GATE Computer ScienceHardGATE CS (PYQ pattern)

For S → A B; A → a A | ε; B → b B | ε (augmented), in how many states of the LR(0) automaton is there a conflict, and is the grammar SLR(1)?

  1. A. 2 states; yes, SLR(1)
  2. B. 4 states; no, not SLR(1)
  3. C. 0 states; it is LR(0)
  4. D. 4 states; yes, SLR(1)

Correct answer: D. 4 states; yes, SLR(1)

The ε-items create complete items beside shifts: I0 (A → · with shift a), the state after a (A → a·A, A → · with shift a), the state after A (S → A·B, B → · with shift b) and the state after b (B → b·B, B → · with shift b): 4 states. FOLLOW(A) = {b, $} and FOLLOW(B) = {$} avoid the shifted terminals, so SLR(1) has no conflict.

More Compiler Design questions

Exams that ask this topic