Question
Project 1 JAVA Program Write a basic forth interpreter that does math. You can also view this as writing a simulator of an HP calculator
Project 1 JAVA Program
Write a basic forth interpreter that does math. You can also view this as writing a "simulator"
of an HP calculator (like the 10C). You must use a stack for all the math manipulations. You do
not have an = (equals sign). Along with the basic numeric operations, implement an operator
that will pop the top element of the stack and print it out. implement an operator that will
non-destructively print the stack. When you print the stack with this operator you must mark
the top of the stack.
Implement the 4 math operators:
+ pop the top 2 elements, push the result of adding them.
- pop the top 2 elements of the stack, subtract them, push the result
* pop the top 2 elements, multiply them, push the result
/ pop the top 2 elements, divide them, push the result
. pop the top element and display it
.S print the contents of the stack, mark the top. Don't pop anything!
Anytime you accept input as valid, print ok
Display errors like stack underfow and stack overfow. Tis type of error shouldnt cause your
program to abort. Te stack underfow error should leave an empty stack. You can decide the
consequences of a stack overfow (either push the new number and delete the bottom number
of the stack or simply refuse to modify the stack)
You may use arrays to implement the stack, use 25 as an upper limit for the number of entries.
Tere are a lot of decisions you will need to make. You can decide how to print the stack and
whether to print top to bottom or bottom to top. You can print it out as a single line or one
entry to a line. You must document when you make one of these decision that will afect how
your language works.
Te stack does not contain zeros by default. Do not worry about numeric overfows.
Example:
52
ok
37
ok
5
ok
9
ok
13
ok
.S
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