GATE Computer ScienceVery hardGATE CS (PYQ pattern)

For G: S → a A c | a B d | B c; A → z; B → z, which statements are true? I. The canonical LR(1) automaton has the same number of states as the LR(0) automaton. II. G is SLR(1). III. G is LALR(1).

  1. A. I and III only
  2. B. III only
  3. C. I, II and III
  4. D. II and III only

Correct answer: A. I and III only

After a z the state holds A → z· and B → z·. FOLLOW(A) = {c}, FOLLOW(B) = {c, d} overlap in c: SLR fails. The LR(1) lookaheads there are A: c, B: d, no clash; the other B → z· (start, lookahead c) has a different core. No core is ever split by lookaheads, so LR(1) and LR(0) both have 11 states and LALR = LR(1): G is LALR(1).

More Compiler Design questions

Exams that ask this topic