GATE Computer ScienceVery hardGATE CS (PYQ pattern)

Consider G: S → A | x b; A → a A b | B; B → x. Which statements are true? I. G is LL(1). II. G is LR(0). III. G is SLR(1). IV. G is LALR(1).

  1. A. III and IV only
  2. B. IV only
  3. C. None of the four
  4. D. I, III and IV only

Correct answer: B. IV only

I: FIRST(A) = {a, x} meets FIRST(x b) in x. In the state after x from the start, the items are S → x·b and B → x·. FOLLOW(B) = FOLLOW(A) = {b, $}, so SLR (and LR(0)) has a shift-reduce clash on b. The true lookahead of B → x· there is $ only (A = B at the top level), so LALR(1) has no clash; inside a…b the state {B → x·} with lookahead b has a different core.

More Compiler Design questions

Exams that ask this topic