GATE Computer ScienceModerateGATE CS (PYQ pattern)

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

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

Correct answer: D. 5

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

More Compiler Design questions

Exams that ask this topic