Question: program in java Project 1 Write a basic forth interpreter that does math. You can also view this as writing a simulator of an HP
program in java
Project 1 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 off 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 underflow and stack overflow. This type of error shouldnt cause your program to abort. The stack underflow error should leave an empty stack. You can decide the consequences of a stack overflow (either push the new number and delete the bottom number off 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. There 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 affect how your language works.
The stack does not contain zeros by default. Do not worry about numeric overflows.
Example:
52
ok
37
ok5ok
9ok13ok.S
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
