GATE Computer ScienceVery hardGATE CS (PYQ pattern)

For S → a S b | a b | ε (augmented), how many multiply-defined ACTION cells do the SLR(1), LALR(1) and canonical LR(1) tables have, in that order?

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

Correct answer: B. 1, 1 and 2

The grammar is ambiguous (a b = S → a b, or S → a S b with S → ε), so no LR table is conflict-free. After a, the items S → a·S b, S → a·b and S → · clash on b (shift b vs reduce S → ε, since b ∈ FOLLOW(S)). SLR and LALR have one such state. Canonical LR(1) splits the after-a state into the outermost copy and the nested copy; S → · has lookahead b in both, so the clash appears twice: 2 cells. Merging cores can thus lower the conflict count.

More Compiler Design questions

Exams that ask this topic