GATE Computer ScienceVery hardGATE CS (PYQ pattern)

The grammar S → S a b | S c | A S | x; A → A d | S y | z is transformed by the standard algorithm that removes (indirect and immediate) left recursion, processing the non-terminals in the order S, A and substituting earlier non-terminals into later ones. How many productions does the resulting grammar have? (Count each alternative, including A′ → ε, as one production.)

  1. A. 13
  2. B. 7
  3. C. 11
  4. D. 10

Correct answer: D. 10

Resulting grammar: S → A S S' | x S'; A → x S' y A' | z A'; S' → a b S' | c S' | ε; A' → d A' | S S' y A' | ε. That is 10 productions.

More Compiler Design questions

Exams that ask this topic