GATE Computer ScienceVery hardGATE CS (PYQ pattern)

For the augmented grammar S′ → S; S → a S a | b S b | c, how many states does the canonical LR(1) automaton have, and how many does the LALR(1) automaton have?

  1. A. 14 and 9
  2. B. 23 and 12
  3. C. 17 and 9
  4. D. 23 and 9

Correct answer: D. 23 and 9

The LR(0) automaton has 9 states: I0, the accept state, and seven cores (after a, after b, after c, after a S, after b S, a S a·, b S b·). In LR(1) each of those seven cores occurs with three different lookaheads: $ (outermost S), a (inside a…a) and b (inside b…b). So 1 + 1 + 7 × 3 = 23 canonical states, which merge back to 9 LALR states.

More Compiler Design questions

Exams that ask this topic