GATE Computer ScienceHardGATE CS (PYQ pattern)

For S → id | id [ E ] | id ( E ); E → id (augmented with S′ → S), how many states do the LR(0) and the canonical LR(1) automata have?

  1. A. 10 and 10
  2. B. 9 and 11
  3. C. 10 and 11
  4. D. 11 and 13

Correct answer: C. 10 and 11

LR(0): I0, S′ → S·, the state after id (S → id·, S → id·[E], S → id·(E)), after [, after (, E → id· (one state, reached from both), S → id[E·], S → id(E·), S → id[E]·, S → id(E)·: 10. In LR(1) the item E → id· has lookahead ] after [ and ) after (, so that state splits in two: 11. Every other core occurs in a single context.

More Compiler Design questions

Exams that ask this topic