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 A → x y z | x y | x w | x y v u; B → p B | p | q, how many productions (alternatives) does the resulting grammar have? An empty alternative counts as one production.

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

Correct answer: C. 10

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 10 productions.

More Compiler Design questions

Exams that ask this topic