GATE Computer ScienceVery hardGATE CS (PYQ pattern)

For S → S ( S ) | ε (augmented with S′ → S), how many states do the LR(0) and canonical LR(1) automata have?

  1. A. 5 and 8
  2. B. 5 and 10
  3. C. 6 and 8
  4. D. 6 and 10

Correct answer: A. 5 and 8

LR(0): I0 {S′ → ·S, S → ·S(S), S → ·}, I1 {S′ → S·, S → S·(S)}, I2 {S → S(·S), S → ·S(S), S → ·}, I3 {S → S(S·), S → S·(S)}, I4 {S → S(S)·}: 5. In LR(1), S at the top level is followed by {$, (} and inside parentheses by {), (}. I2, I3, I4 occur only after a ( but I2 can be entered from the top level and from inside, so each of I2, I3, I4 gets two copies: 5 + 3 = 8.

More Compiler Design questions

Exams that ask this topic