GATE Computer ScienceHardGATE CS (PYQ pattern)

For S → A a A b | B b B a; A → ε; B → ε (augmented), how many ACTION cells are multiply defined in the LR(0), SLR(1) and LALR(1) tables, respectively? (An LR(0) reduce is written in every terminal column including $.)

  1. A. 3, 2 and 2
  2. B. 2, 2 and 0
  3. C. 1, 1 and 0
  4. D. 3, 2 and 0

Correct answer: D. 3, 2 and 0

Only I0 holds two complete items, A → · and B → ·. LR(0) writes both reductions in the a, b and $ columns: 3 clashes. SLR uses FOLLOW(A) = FOLLOW(B) = {a, b}: 2 clashes. In I0, A must be followed by a and B by b, so LALR(1) reduces A on a and B on b: no clash (the grammar is even LL(1)).

More Compiler Design questions

Exams that ask this topic