GATE Computer ScienceHardGATE CS (PYQ pattern)

For S′ → S; S → ( L ) | x; L → S | L , S, LALR(1) is formed by merging canonical LR(1) states with equal cores. The LALR state reached from the start state on ( is the merge of how many LR(1) states, and the state reached from it on L and then , is the merge of how many?

  1. A. 1 and 1
  2. B. 2 and 2
  3. C. 2 and 1
  4. D. 3 and 1

Correct answer: C. 2 and 1

( can be read at the top level (the parenthesised S is followed by $) or inside another list (followed by ) or ,): two LR(1) states with the core S → (·L), … but different lookaheads. A comma, however, only occurs inside a list, where L is always followed by {), ,}, so the core L → L,·S has a single LR(1) state.

More Compiler Design questions

Exams that ask this topic