The GATE Grind

GATE 2015 CS – Question 18

Compiler Design · Parsing and Syntax Analysis · 1 mark · Multiple choice

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

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (C) The stack contains only a set of viable prefixes

Explanation

In a shift-reduce parser the stack at any valid state holds a viable prefix of a right sentential form, built up from smaller viable prefixes, so the stack contains only viable prefixes. The other options place them in a fixed position or deny that the stack holds them.