The Gateway to Computer Science Excellence
+36 votes
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
in Compiler Design by Boss (30.8k points)
retagged by | 6.2k views
+2
0

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

6 Answers

+54 votes
Best answer

Answer - C

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
can some one please explain with diagram what is answer
+1
+10 votes
C) should be the answer
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.
–2 votes
whats the correct answer??
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
–2 votes
C should be the answer
by (245 points)
–4 votes
b is answer
by (139 points) 1 flag:
✌ Low quality (Sahin)
0
Answer is C :)
–6 votes
option b is right answer.

viable prefixes helps in determining the handle of a grammar and handle can occurs only at top of stack.
by (-1 points)
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,321 answers
198,387 comments
105,140 users