GATE Computer ScienceVery hardGATE CS (PYQ pattern)

For S → a S | a S b S | c (augmented), how many states does the canonical LR(1) automaton have, and how many ACTION cells of the canonical LR(1) table are multiply defined?

  1. A. 7 states, 1 cell
  2. B. 12 states, 0 cells
  3. C. 14 states, 2 cells
  4. D. 12 states, 1 cell

Correct answer: D. 12 states, 1 cell

This is the dangling-else shape: a S b S can be read with the b belonging to an inner or outer a. LR(0) has 7 states; five cores split into two lookahead variants (top level with $, and nested before a b), giving 12. In the copy of {S → a S·, S → a S·b S} where this a S is itself nested before a b (lookaheads {b, $}), reducing on b clashes with shifting b: exactly 1 conflicting cell, so the grammar is not LR(1) (it is ambiguous).

More Compiler Design questions

Exams that ask this topic