GATE Computer ScienceVery hardGATE CS (PYQ pattern)

After applying left factoring repeatedly (each time extracting the longest common prefix of alternatives that share a first symbol, introducing a new non-terminal each time) to the grammar S → a b c | a b d | a e | f g | f h | k, how many productions (alternatives) does the resulting grammar have? An empty alternative counts as one production.

  1. A. 6
  2. B. 9
  3. C. 10
  4. D. 11

Correct answer: B. 9

Each extraction of a common prefix replaces k alternatives by one and adds a new non-terminal with k alternatives (possibly ε); repeating until no two alternatives share a first symbol leaves 9 productions.

More Compiler Design questions

Exams that ask this topic