Now, viable prefix is defined in Ullman Compilers text as :
- Possible strings which appear on the stack during shift reduce parsing
- Or formally, viable prefix is a prefix of the right sentential form which does not move past the right end of the right most handle.
Well, with this being said lets us check the options:
(A) Viable prefixes appear only at the bottom of the stack and not inside
(B) Viable prefixes appear only at the top of the stack and not inside.
Viable prefix as stated in point (1) as per Ullman, is present along the entire length of the stack. Neither at the bottom nor on the top.
So options (A) and (B) are clearly wrong.
Now,
(D) The stack never contains viable prefixes
is wrong as well as viable prefix is present along the entire length of the stack.
So option (C) remains, which is supposed to be correct. But why?
Suppose if :
$$X_0X_1X_2...X_{n-1}$$
is the contents of the stack at any point in time, [$X_i$ can be a variable or terminal],
Then,
$$X_0$$
$$X_0X_1$$
$$X_0X_1X_2$$
…
$$X_0X_1X_2...X_{n-1}$$
Are all viable prefix on the stack. Why? Because at sometime in the past,
each of $X_0..X_i$, $i=0,1,2..,n-1$ were the only contents on the stack.
Please correct me if I am wrong.