GATE Computer ScienceVery hardGATE CS (PYQ pattern)

For the augmented grammar S′ → S; S → ( L ) | x; L → S | L , S, how many states does the canonical LR(1) automaton have, and in how many of them is S → x · the complete item?

  1. A. 9 states, 1 with S → x ·
  2. B. 13 states, 3 with S → x ·
  3. C. 15 states, 2 with S → x ·
  4. D. 13 states, 2 with S → x ·

Correct answer: D. 13 states, 2 with S → x ·

Outside any parentheses an S is followed by $; inside, by ) or , (one lookahead set {), ,}, both at the first level and deeper). So the cores reachable from inside a ( (S → (·L), S → x·, S → (L·), S → (L)·) appear twice, once with $ and once with {), ,}, while the L-cores occur only inside: 9 LR(0) states + 4 extra = 13, and S → x· appears with $ and with {), ,}: 2 states.

More Compiler Design questions

Exams that ask this topic