GATE Computer ScienceHardNIELIT Scientist B

Using E → E + T | T; T → T * F | F; F → ( E ) | id, how many nodes (terminal leaves included) does the parse tree of id + id * id * id + id have?

  1. A. 20
  2. B. 24
  3. C. 26
  4. D. 22

Correct answer: D. 22

There are 13 non-terminal nodes (one per reduction) and 9 terminal leaves (5 id tokens, 2 plus signs and 2 stars), totalling 22.

More Compiler Design questions

Exams that ask this topic