GATE Computer ScienceHardGATE CS (PYQ pattern)

For S′ → S; S → S ( S ) | ε, LALR(1) merges canonical LR(1) states with equal cores. The LALR state whose only item is S → S ( S ) · is the merge of how many LR(1) states, and what is its lookahead set?

  1. A. 2 states; {$, (, )}
  2. B. 1 state; {$, (, )}
  3. C. 2 states; {(, )}
  4. D. 3 states; {$, (, )}

Correct answer: A. 2 states; {$, (, )}

An S at the top level is followed by $ or (; an S inside parentheses by ) or (. S ( S ) · is reached in both contexts, giving one LR(1) state with lookaheads {$, (} and one with {), (}. Merging them gives {$, (, )}.

More Compiler Design questions

Exams that ask this topic