retagged by
3,377 views
1 votes
1 votes
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$.
retagged by

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

1 votes
1 votes
0 answers
1
admin asked Jul 26, 2019
1,260 views
Construct a syntax-directed translation scheme that translates arithmetic expressions from postfix notation into infix notation. Give annotated parse trees for the inputs...
2 votes
2 votes
0 answers
2
admin asked Sep 6, 2019
1,979 views
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)...
0 votes
0 votes
1 answer
3
5 votes
5 votes
1 answer
4
admin asked Sep 6, 2019
40,370 views
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)...