1 vote

Construct a syntax-directed translation scheme that translates arithmetic expressions from infix notation into prefix notation in which an operator appears before its operands; e.g., $-xy$ is the prefix notation for $x - y$. Give annotated parse trees for the inputs $9-5+2$ and $9-5*2$.

0 votes

__Translation Scheme:__

*expr* -> { print('+') } *expr* + *term* | { print('-') } *expr* - *term* | *term*

*term* -> { print('*') } *term* * *factor* | { print('/') } *term* - *factor* | *factor*

*factor* -> { print('digit') } *digit* | ( *expr *)

*digit* -> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

**Annotated Parse trees:**