GATE Computer ScienceHardGATE CS (PYQ pattern)

For the declaration grammar D → T L; T → int | float; L → L , id | id (augmented with D′ → D), how many states does the LR(0) automaton have, and is the grammar LR(0)?

  1. A. 9 states; yes, no state mixes items
  2. B. 8 states; no — T → int· clashes with id
  3. C. 9 states; no — D → T L· clashes with shifting ,
  4. D. 10 states; yes, no state mixes items

Correct answer: C. 9 states; no — D → T L· clashes with shifting ,

States: I0, D′ → D·, T → int·, T → float·, D → T·L (with L-items), D → T L· together with L → L·, id, L → id·, L → L ,·id, L → L , id·: 9. The state after T L holds the complete item D → T L· and the item L → L·, id, which shifts ',': an LR(0) shift-reduce conflict. SLR resolves it since FOLLOW(D) = {$}.

More Compiler Design questions

Exams that ask this topic