GATE Computer ScienceVery hardGATE CS (PYQ pattern)

G1: S → A B; A → a A | c; B → a B | c. G2: S → A B A; A → a A | c; B → b B | c. For each, how many more states does the canonical LR(1) automaton have than the LALR(1) automaton?

  1. A. 0 for G1, 3 for G2
  2. B. 3 for G1, 3 for G2
  3. C. 0 for G1, 6 for G2
  4. D. 3 for G1, 0 for G2

Correct answer: A. 0 for G1, 3 for G2

A core is duplicated only when the same LR(0) core is reached with different lookaheads. In G1 the A-items (lookahead {a, c}) and the B-items (lookahead $) are different cores, so nothing splits: 0. In G2 A occurs twice, once followed by FIRST(B) = {b, c} and once by $, so A's three cores (after a, A → c·, A → a A·) each get two LR(1) copies: 3 extra states.

More Compiler Design questions

Exams that ask this topic