GATE Computer ScienceVery hardGATE CS (PYQ pattern)

For G: S → a A b | A a; A → a | ε (which generates a, aa, ab and aab), which statements are true? I. G is LL(2). II. G is LL(3). III. G is LR(1). IV. G is unambiguous.

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

Correct answer: B. II and IV only

Each of the four strings has exactly one tree (IV). With lookahead a at the start, S → a A b (aab, ab) and S → A a (a, aa) share the 2-prefix a a (aab versus aa), so not LL(2); three symbols (a a b versus a a $) decide: LL(3). An LR parser seeing a first must already decide whether to reduce A → ε (the string a) or shift a (A = a, or S → a A b), and one symbol of lookahead cannot tell a$ from aa$: LR(1) conflicts, so G is not LR(1) though it is LL(3) (and hence LR(3)).

More Compiler Design questions

Exams that ask this topic