Question: You need to implement a predictive parser to translate the expression to postfix notation. The grammar (translation scheme) is described as following. Please reference slides
You need to implement a predictive parser to translate the expression to postfix notation. The grammar (translation scheme) is described as following. Please reference slides 47-72 ( slideshow linked below)
( Link to explain missing characters https://ibb.co/hOUuGG )
(view picture link posted above for better detail.)
expr term rest
rest + term {print (+)} rest|- term {print (-)} rest |
term term / factor { print('/') }
term term * factor { print(*') }
term factor
factor digit | (expr)
digit 0 {print(0)}
1. Input from keyboard a single digit expression without semicolon. E.g. 2+3*(4-2)
2. The starting symbol is expr
3. Print out the postfix notation if the parsing is successful
4. Give syntax error information if parsing is failed
5. Your parser should be able to translate the expression of any length
also try to modify the grammar to include % (modulate) operator in the expression, which has higher precedence than multiplication and division. Implement the parser
(contains a link to the slideshow https://docs.google.com/presentation/d/1uwWhTlzzAi6Fm5UgcKQbL-tO4DtzKbUkH3LHBCGx2CA/edit?usp=sharing )
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
