Question: Using ANTLR to implement a reverse Polish calculator We will leverage ANTLR to implement a reverse polish calculator. Write code in Java. 1 . Write

Using ANTLR to implement a reverse Polish calculator
We will leverage ANTLR to implement a reverse polish calculator. Write code in Java.
1. Write the grammar for the following mathematical operations in ANTLR:
Arithmetic operations: **(power)
Logarithmic functions: log (base 10), ln (base e)
Trigonometric functions: sin, cos, tan, asin, acos, and atan
Hyperbolic trigonometric functions: sinh, cosh, tanh
Factorial function:
Special number: e (Euler number), pi (\pi )
() to override operator precedence.
Numbers: integer, float, and scientific
2. Generate lexer and parser code from ANTLR grammar.
3. Implement code to generate reverse Polish expression from input and the computation result, up to the 5th decimal place.
Do NOT print trailing 0s after the decimal point.
If there is no trailing 0s after the decimal point, do not print the decimal point. Only print the integer part.
4. Write unit tests.
Here are some input and output examples:
Input expression
Reverse Polish expression
Computation result
e.g. input: sin(pi/6) reverse: pi 6/ sin result: 0.5
Code input and output:
Your code should read from standard input, not from file.
Input will include one infix expression on each line.
Your output should include 3 lines per each input:
1st line: the infix expression
2nd line: the reverse polish expression, one space character between operators and operands
3rd line: the value of the expression per specification above

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!