GATE Computer ScienceVery hardNIELIT Scientist B

Indirect left recursion is removed from S → A a | b; A → A c | S d | ε by ordering the non-terminals S, A, substituting S into A's rules, and then removing immediate left recursion (the new non-terminal is A′). How many productions does the resulting grammar have?

  1. A. 6
  2. B. 8
  3. C. 9
  4. D. 7

Correct answer: D. 7

S → A a | b stays (2). Substituting gives A → A c | A a d | b d | ε; removing the recursion yields A → b d A′ | A′ (2) and A′ → c A′ | a d A′ | ε (3): 2 + 2 + 3 = 7.

More Compiler Design questions

Exams that ask this topic