GATE Computer ScienceVery hardGATE CS (PYQ pattern)

The grammar A → B a | A a | c; B → B b | A b | d is transformed by the standard algorithm that removes (indirect and immediate) left recursion, processing the non-terminals in the order A, B 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. 12
  2. B. 6
  3. C. 9
  4. D. 11

Correct answer: C. 9

Resulting grammar: A → B a A' | c A'; B → c A' b B' | d B'; A' → a A' | ε; B' → b B' | a A' b B' | ε. That is 9 productions.

More Compiler Design questions

Exams that ask this topic