GATE Computer ScienceHardGATE CS (PYQ pattern)

G: S → id | id [ E ] | id ( E ); E → id. G′ is obtained from G by left factoring S. Which statements are true? I. G is LL(1). II. G′ is LL(1). III. G is LR(0). IV. G is SLR(1).

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

Correct answer: D. II and IV only

I: all three S-alternatives start with id. II: G′ is S → id R; R → [ E ] | ( E ) | ε, and FOLLOW(R) = {$} is disjoint from [ and (. III: after id the LR(0) state holds S → id· beside shifts on [ and (. IV: FOLLOW(S) = {$}, so SLR reduces only on $ and the clash disappears.

More Compiler Design questions

Exams that ask this topic