Question

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

Choose one option
Official answer and solution
Official answer
C
From
Official GATE 2015 answer key

Solution

Recall the fundamental invariant of shift-reduce LR parsers regarding parser stack contents.

By definition in compiler theory:

  • A viable prefix of a right-sentential form is a prefix that does not extend beyond the right end of the handle.
  • As long as no error has occurred, the string of grammar symbols on the parser stack of a shift-reduce parser is always a viable prefix of some right-sentential form.
  • When the parser shifts a terminal or reduces by a production, the new stack contents continue to form a viable prefix.

Therefore, at any valid parsing state, the stack contains only a set of viable prefixes (option C).

Final answer

C

Common trap

Believing viable prefixes reside only at the top or bottom of the stack, rather than the entire stack prefix.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2015 Computer Science and Information Technology (CS) Session 1
Question
23 of 65, printed as CS Q.13
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.