# Ullman (Compiler Design) Edition 2 Exercise 2.3 Question 1 (Page No. 60)

1 vote
103 views
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$.

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:

## Related questions

1
155 views
Construct a syntax-directed translation scheme that translates arithmetic expressions from postfix notation into infix notation. Give annotated parse trees for the inputs $95-2*$ and $952*-$.
1 vote
For the SDD(SYNTAX-DIRECTED DEFINITIONS ) of Fig. $5.4$, give annotated parse trees for the following expressions: $(3+4)\ast(5+6)n.$ $1\ast2\ast3\ast(4+5)n.$ $(9+8\ast(7+6)+5)\ast 4n.$
Extend the SDD of Fig. $5.4$ to handle expressions as in Fig. $5.1$.
For the SDD(SYNTAX-DIRECTED DEFINITIONS ) of Fig. $5.1$, give annotated parse trees for the following expressions: $(3+4)\ast(5+6)n.$ $1\ast2\ast3\ast(4+5)n.$ $(9+8\ast(7+6)+5)\ast 4n.$