in Compiler Design retagged by
3,374 views
1 vote
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$.
in Compiler Design retagged by
by
3.4k views

1 Answer

3 votes
3 votes

Translation Scheme:

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

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

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

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

Annotated Parse trees:

2.3.1-q1

Related questions