Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Rules In Database Systems Third International Workshop Rids 97 Sk Vde Sweden June 26 28 1997 Proceedings Lncs 1312

Authors: Andreas Geppert ,Mikael Berndtsson

1997th Edition

3540635165, 978-3540635161

More Books

Students also viewed these Databases questions

Question

4. Explain the strengths and weaknesses of each approach.

Answered: 1 week ago