Answered step by step
Verified Expert Solution
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.
Write the grammar for the following mathematical operations in ANTLR:
Arithmetic operations: power
Logarithmic functions: log base 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
Generate lexer and parser code from ANTLR grammar.
Implement code to generate reverse Polish expression from input and the computation result, up to the th decimal place.
Do NOT print trailing s after the decimal point.
If there is no trailing s after the decimal point, do not print the decimal point. Only print the integer part.
Write unit tests.
Here are some input and output examples:
Input expression
Reverse Polish expression
Computation result
eg input: sinpi reverse: pi sin result:
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 lines per each input:
st line: the infix expression
nd line: the reverse polish expression, one space character between operators and operands
rd line: the value of the expression per specification above
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started