GATE Computer ScienceVery hardGATE CS (PYQ pattern)

For G: S → a A | b B; A → c A d | ε; B → c B d d | ε, which statements are true? I. G is LL(1). II. G is LR(0). III. The canonical LR(1) automaton has exactly 7 more states than the LALR(1) automaton.

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

Correct answer: A. I and III only

I: FIRST(c A d) = {c} and FOLLOW(A) = {d, $} are disjoint (same for B), so LL(1). II: the state after a holds A → ·c A d and the complete item A → ·, a shift-reduce clash for LR(0). III: LR(0)/LALR have 13 states. In LR(1) seven cores split into a copy for the outermost A/B (lookahead $) and one for nested ones (lookahead d): after c for A and for B, c A·d, c A d·, c B·d d, c B d·d, c B d d·. That gives 20 states: 20 − 13 = 7.

More Compiler Design questions

Exams that ask this topic