retagged by
19,361 views
53 votes
53 votes

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 by

2 Answers

Best answer
72 votes
72 votes

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.

edited by
1 votes
1 votes
Ans C.

The following statement is true at any valid state in shift-reduce parsing:

The stack contains only a set of viable prefixes

In shift-reduce parsing, the stack is used to store a set of viable prefixes of the input string, which are sequences of terminals and non-terminals that can potentially form a valid sentence in the grammar. At any valid state in the parsing process, the stack contains a set of viable prefixes that have been generated so far, and the top of the stack represents the currently active prefix. The parser uses a set of shift and reduce actions to transform the input and stack, until the entire input string has been processed and a complete sentence is formed on the stack.

The other statements are not necessarily true, as viable prefixes can appear inside the stack as well, not only at the top or bottom. The stack may contain not only a set of viable prefixes but also non-viable prefixes.
Answer:

Related questions

1.5k
views
3 answers
2 votes
Ankit Chourasiya asked Sep 9, 2015
1,472 views
SET OF VIABLE PREFIXES FOR A GIVEN SLR(1) GRAMMAR IS REGULAR LANGUAGE ?
1.6k
views
1 answers
4 votes
Ruturaj Mohanty asked Dec 27, 2018
1,640 views
Which of the following statements on Viable Prefixes is incorrect?A viable prefix does not extend past the right end of the handleFor any context-free grammar, the set of...
8.7k
views
2 answers
29 votes
go_editor asked Feb 14, 2015
8,704 views
Among simple LR (SLR), canonical LR, and look-ahead LR (LALR), which of the following pairs identify the method that is very easy to implement and the method that is the ...
29.7k
views
7 answers
80 votes
makhdoom ghaya asked Feb 13, 2015
29,675 views
The least number of temporary variables required to create a three-address code in static single assignment form for the expression $q + r / 3 + s - t * 5 + u * v/w$ is_...