GATE Computer ScienceModerateGATE CS (PYQ pattern)

The grammar S → i S | i S e S | a is ambiguous. How many distinct parse trees does the string "i i i a e a e a" have?

  1. A. 3
  2. B. 6
  3. C. 5
  4. D. 4

Correct answer: A. 3

Count trees by splitting the string at every possible point and multiplying the counts for each part (a CYK-style count); the total is 3.

More Compiler Design questions

Exams that ask this topic