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

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!