CS365 Project Assignment 3

Just as you did in the homework assignment, create an interpreter in which a user can enter a formula. For each cell to which the formula is assigned, your interpreter should immediately evaluate the formula and assign the resulting value to the cell. It should also print the cell name and its assigned value. For this assignment you do not have to worry about re-evaluating any formulas that use the modified variable--you will do that in the next assignment. Here is a sample interaction with the interpreter:
>>> midterm1[1] = 85
midterm1[1] = 85.00
>>> midterm1[2] = 90
midterm1[2] = 90.00
>>> midterm2[1] = 100
midterm2[1] = 100.00
>>> midterm2[2] = 70
midterm2[2] = 70.00
>>> midtermAvg[i=1-2] = (midterm1[i] + midterm2[i]) / 2
midtermAvg[1] = 92.50
midtermAvg[2] = 80.00
>>> midterm1[1] = 95
midterm1[1] = 95.00
Notice that when I modified midterm1[1] at the end of the example the interpreter did not re-evaluated midtermAvg[1] even though midtermAvg[1] depends on midterm1[1]'s value.

Your interpreter should use your JCUP parser to parse each line of input and create an expression tree for the formula. The expression tree should then be assigned to the appropriate cell(s). I would recommend storing the column names (e.g., midterm1, midterm2, midtermAvg) in a hash table and associating an array of cells with each column name. You should not have to duplicate an expression tree for each cell to which it is assigned. Your team should figure out a way to re-use an expression tree for multiple rows in a column.

If your interpreter encounters an undefined cell while evaluating a formula, it should print an error message indicating that the cell is undefined and mark as undefined the cell to which the formula is assigned. For example:

>>> final[1] = final[2]
Error: final[2] is undefined
final[1] = undef
>>> final[1] = foo[1]
Error: foo[1] is undefined
final[1] = undef
Here is another example:
>>> midterm[1] = 50
midterm[1] = 50.00
>>> midterm[2] = 100
midterm[2] = 100.00
>>> comp[1] = min(midterm[1], midterm[2], midterm[3])
Error: midterm[3] is undefined
comp[1] = undef

Output of Your Interpreter

If you have a question about the output your interpreter should generate you can test your input with my test interpreter, which can be invoked by typing:

java -cp .:..:/home/cs365/www-home/project3/:/usr/local/lib/jar formula.interpreter

What to Submit

Place your code in a package named formula. Your main class should be called interpreter. Follow the submission instructions at Michael Beeler's TA website.