GATE Computer ScienceVery hardGATE CS (PYQ pattern)

For E → id | E [ E ] | ( E ) (augmented with S′ → E), how many more states does the canonical LR(1) automaton have than the LALR(1) automaton?

  1. A. 7
  2. B. 14
  3. C. 0
  4. D. 12

Correct answer: B. 14

An E occurs in three contexts with different follow sets: at the top ({$, [}), inside [ ] ({], [}) and inside ( ) ({), [}). Apart from I0 and the accept state, each of the 7 LR(0) cores (after id, after [, after (, E[E·], E[E]·, (E·), (E)· and so on) is reachable in all three contexts, so it appears three times: LR(1) has 2 + 7 × 3 = 23 states against 9, a difference of 14.

More Compiler Design questions

Exams that ask this topic