GATE Computer ScienceVery hardGATE CS (PYQ pattern)

For G: S → a B | a C d; B → b | ε; C → b c, which statements are true? I. G is LL(2). II. G is LL(3). III. G is LR(0). IV. G is SLR(1).

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

Correct answer: B. II and IV only

With B → b, S → a B gives a b; S → a C d gives a b c d: both start with a b, so 2 symbols do not decide (not LL(2)); the third symbol ($ versus c) does, so LL(3). After a, the LR(0) state has B → · complete beside shifts on b, and after a b it has B → b· beside C → b·c: LR(0) conflicts. FOLLOW(B) = {$} contains neither b nor c, so SLR(1) resolves both.

More Compiler Design questions

Exams that ask this topic