search
Log In
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$.
in Compiler Design 103 views

1 Answer

0 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

0 votes
0 answers
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*-$.
asked Jul 26, 2019 in Compiler Design Lakshman Patel RJIT 155 views
1 vote
0 answers
2
151 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)+5)\ast 4n.$
asked Sep 6, 2019 in Compiler Design Lakshman Patel RJIT 151 views
1 vote
1 answer
4
...