6.2k views

Which one of the following is TRUE at any valid state in shift-reduce parsing?

1. Viable prefixes appear only at the bottom of the stack and not inside
2. Viable prefixes appear only at the top of the stack and not inside
3. The stack contains only a set of viable prefixes
4. The stack never contains viable prefixes

retagged | 6.2k views
+2
0

It was helpful @Kushagra गुप्ता Thanks!😊

Explanation:

A handle is actually the one which is always on the top of the stack. A viable prefix(prefix of the Right-hand side of a production or productions), is actually a prefix of the handle and so can never extend past the right end of the handle(i.e. the top of the stack).

The structure of the stack can be considered as a set of viable prefixes -

$Stack = \{Prefix_1 Prefix_2 Prefix_3 \ldots Prefix_{n-1} Prefix_{n} \}$  and so it is not wrong to say that the stack contains a set of viable prefixes.

by Active (3.5k points)
edited by
0
@arjun sir, Handle is on the top of the stack or rightmost end of handle is on the top of the stack?
+3
Handle is on the top of the stack (i.e. terminals which is going to be reduced in next step. this is correct.
+2

For more details and clear conception http://cse.iitkgp.ac.in/~bivasm/notes/scribe/11CS30001.pdf

0
+1
by Active (1.5k points)
0
Can u please explain...If it's a viable prefix..After one or two steps it will definitely get reduced na..how can it be inside the stack
+2
Can you explain what is viable prefix ?
+2
Remember LR(0) implementation using the stack, all the shift operations are the push and when you push the input you also push the state numbers as well hence you will only push when ever there is shift operation and hence viable prefix in stack.
by (243 points)
+3

ans C

Remember LR(0) implementation using the stack, all the shift operations are the push and when you push the input you also push the state numbers as well hence you will only push when ever there is shift operation and hence viable prefix in stack.

+4
Handles appear at top of the stack. Viable prefixes may appear any where in the stack
by (245 points)
by (139 points) 1 flag:
✌ Low quality (Sahin)
0

viable prefixes helps in determining the handle of a grammar and handle can occurs only at top of stack.
by (-1 points)