GATE Computer ScienceHardGATE CS (PYQ pattern)

For E → id | E [ E ] | ( E ) (augmented), how many states does the LR(0) automaton have, and which is the strongest of LR(0) / SLR(1) / LALR(1) that the grammar satisfies?

  1. A. 9 states; SLR(1) but not LR(0)
  2. B. 11 states; LALR(1) but not SLR(1)
  3. C. 9 states; it is LR(0)
  4. D. 8 states; SLR(1) but not LR(0)

Correct answer: C. 9 states; it is LR(0)

States: I0, E′ → E· (with E → E·[E]), E → id·, E → (·E), E → E[·E], E → (E·) with E → E·[E], E → E[E·] with E → E·[E], E → (E)·, E → E[E]·: 9. The only complete items (id·, (E)·, E[E]·) are alone in their states and the accept item sits only with a shift on [, so there is no conflict even without lookahead: the grammar is LR(0).

More Compiler Design questions

Exams that ask this topic