Similar questions 1 more →
Semantic Analysis & Type Checking

Answer & solution
Answer: D (no official key was published)
1. S→ER and R→*E{print(*)}R|ε put multiplication below the expression E; E→F+E{print(+)}|F groups the addition on the right. For 2*3+4, first print 2, then parse E for 3+4, printing 3,4,+, then print * when that E finishes.
2. The output is 234+*, option D. Applying ordinary arithmetic precedence would incorrectly give 23*4+.
3. Teaching check: Semantic print actions fire at their positions in the grammar, not according to the usual arithmetic-precedence rules. The E nonterminal consumes the whole 3+4 before R’s multiplication-print action runs. The result is therefore postfix for 2*(3+4).