GATE Computer ScienceVery hardGATE CS

A syntax-directed translation scheme prints as it reduces: E → T + E { print('+') } | T; T → F * T { print('*') } | F; F → id { print(id.name) }. The parser is bottom-up and executes each action when its production is reduced. What is printed for the input a+b*c+d*e*f?

  1. A. abc*def++**
  2. B. abc*def*+*+
  3. C. abc*+def**+
  4. D. abc*def**++

Correct answer: D. abc*def**++

Both operators are right associative: a + (b*c + (d*(e*f))). Printing the operands as F is reduced and each operator after both its operands gives a b c * d e f * * + +, i.e. abc*def**++.

More Compiler Design questions

Exams that ask this topic