GATE Computer ScienceVery hardGATE CS (PYQ pattern)

For G: S → x S y | x y | S S, which statements are true? I. G is ambiguous. II. The canonical LR(1) table has more multiply-defined cells than the LALR(1) table. III. The LALR(1) automaton has fewer states than the canonical LR(1) automaton. IV. G is LR(0).

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

Correct answer: C. I, II and III only

x y x y x y has two trees ((S S) S and S (S S)), so I holds and no LR table is conflict-free (IV false). The clash is in the state reached after S S, between reducing S → S S and shifting x. In canonical LR(1) that core appears twice (lookahead set with $ at top level and with y inside x…y), giving 2 conflicting cells; LALR merges them into 1. LR(1) has 12 states against 7.

More Compiler Design questions

Exams that ask this topic