GATE Computer ScienceVery hardGATE CS (PYQ pattern)

For each choice of terminals x, y ∈ {a, b, c} consider G(x, y): S → A x B; A → a A | ε; B → b B | y. Of the nine grammars, how many are LL(1), and how many are SLR(1)?

  1. A. 4 LL(1), 4 SLR(1)
  2. B. 6 LL(1), 6 SLR(1)
  3. C. 4 LL(1), 6 SLR(1)
  4. D. 5 LL(1), 9 SLR(1)

Correct answer: C. 4 LL(1), 6 SLR(1)

FOLLOW(A) = {x}, so x = a clashes with A → a A in M[A, a], and for LR the parser must decide to reduce A → ε before shifting a that may belong to A or be x: all three x = a grammars fail both tests. For x ∈ {b, c}: y = b makes B → b B | b clash in M[B, b] (not LL(1)) but an LR parser simply shifts b and decides at the next symbol, so it stays SLR(1). LL(1): x ∈ {b, c}, y ∈ {a, c} = 4; SLR(1): x ∈ {b, c}, any y = 6.

More Compiler Design questions

Exams that ask this topic