GATE Computer ScienceHardGATE CS (PYQ pattern)

An LR parser for E → id | E [ E ] | ( E ) parses "id [ ( id [ id ] ) ]". What is the largest number of grammar symbols on its stack at any moment (states not counted)?

  1. A. 7
  2. B. 9
  3. C. 6
  4. D. 8

Correct answer: A. 7

Each id is reduced to E as soon as it is shifted. The deepest stack occurs at the inner index: E [ ( E [ E ] just before E [ E ] is reduced — 7 symbols. The input has 9 tokens, but they are never all on the stack together.

More Compiler Design questions

Exams that ask this topic