  Second Summer 2002

Homework Assignment Six: A Very Basic Interpreter (Evaluator)

For this assignment you are to write an arithmetic expression evaluator that is able to perform

• multiplications
• subtractions, and
• divisions,
is able to
• store results in named locations (variables) and
• allow them in expressions as well,
as illustrated in the sample session below. The evaluator should also handle parentheses properly.

Here's a sample session with the program:

```frilled.cs.indiana.edu%java Eval
Eval> 1 + 1
1 + 1
2
Result is: 2
Eval> ( 1 + 2 ) * 3
( 1 + 2 ) * 3
( 3 ) * 3
3 * 3
9
Result is: 9
Eval> a = 1 + 1
1 + 1
2
Stored 2 in a
Eval> a
2
Result is: 2
Eval> a = a + 1
2 + 1
3
Stored 3 in a
Eval> a
3
Result is: 3
Eval> b = a - 4
3 - 4
-1
Stored -1 in b
Eval> a
3
Result is: 3
Eval> b
-1
Result is: -1
Eval> a = ( a - b ) * ( a + b )
( 3 - -1 ) * ( 3 + -1 )
( 4 ) * ( 3 + -1 )
( 4 ) * ( 2 )
4 * ( 2 )
4 * 2
8
Stored 8 in a
Eval> a
8
Result is: 8
Eval> b
-1
Result is: -1
Eval> b = a + b * 4
8 + -1 * 4
8 + -4
4
Stored 4 in b
Eval> a / b
8 / 4
2
Result is: 2
Eval> a = a / b
8 / 4
2
Stored 2 in a
Eval> a
2
Result is: 2
Eval> b
4
Result is: 4
Eval> exit
frilled.cs.indiana.edu%```
You may safely assume that
• your only operands are integers and that
• the names of variables are comprised of only alphabetical characters.
Note that in my evaluator the tokens (numbers, parens) are separated by spaces.

Here's a grading scale for this assignment:

Being able to support `+` and `-` 20
Supporting `*` and `/` 20
Properly calculating `(1 + 1) * 2 + 2 * ( 1 + 1 )` 10
Providing error-checking through `try-catch` blocks 5