GATE Computer ScienceHardGATE CS (PYQ pattern)

Augment S → ( L ) | x; L → S | L , S with S′ → S and build the canonical collection of LR(0) item sets. How many states does it have, and is the grammar LR(0)?

  1. A. 9 states; no, there is a shift-reduce clash on ,
  2. B. 8 states; yes, it is LR(0)
  3. C. 9 states; yes, it is LR(0)
  4. D. 10 states; no, there is a reduce-reduce clash

Correct answer: C. 9 states; yes, it is LR(0)

States: I0, S′ → S·, S → x·, S → (·L), L → S·, S → (L·) with L → L·,S, S → (L)·, L → L,·S, L → L,S·: 9. Every complete item sits alone in its state (L → L·, S shares a state with S → (L·), but neither is complete), so there is no conflict: LR(0).

More Compiler Design questions

Exams that ask this topic