GATE Computer ScienceVery hardGATE CS (PYQ pattern)

For S → X Y Z; X → a X | ε; Y → b Y | X; Z → c | ε (augmented), in how many states is there a conflict in the SLR(1) table, and in how many in the canonical LR(1) table?

  1. A. 4 in SLR(1), 0 in LR(1)
  2. B. 4 in SLR(1), 2 in LR(1)
  3. C. 4 in SLR(1), 4 in LR(1)
  4. D. 2 in SLR(1), 2 in LR(1)

Correct answer: B. 4 in SLR(1), 2 in LR(1)

The grammar is ambiguous (an a can come from X or, via Y → X, from the second X), so even canonical LR(1) keeps the clash between X → · and shifting a in I0 and in the state after a (a top-level X may stop early). SLR also reduces X → · on all of FOLLOW(X) = {a, b, c, $} in the state after X (S → X·Y Z, Y → ·X …) and in the state after b (Y → b·Y …), where the true lookahead of that X is only {c, $}: those two extra states clash on a and b. Total 4 versus 2

More Compiler Design questions

Exams that ask this topic