GATE Computer ScienceVery hardGATE CS (PYQ pattern)

G: S → a A d | b B d | a B e | b A e; A → c; B → c is LR(1) but not LALR(1). Which of these changes, each made on its own, makes the grammar LALR(1)? I. Replace B → c by B → c c. II. Replace S → b A e by S → b A f. III. Replace S → b B d by S → b B f.

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

Correct answer: C. I only

After a c: A → c· on d, B → c· on e; after b c: B → c· on d, A → c· on e. Merging gives a reduce-reduce clash. I: B now needs a second c, so the two complete items never share a state. II: after b c it becomes A on f, B on d; merged A {d, f} and B {e, d} still collide on d. III: after b c, B on f, A on e; merged A {d, e}, B {e, f} collide on e.

More Compiler Design questions

Exams that ask this topic