>>> midterm1 = 85 midterm1 = 85.00 >>> midterm1 = 90 midterm1 = 90.00 >>> midterm2 = 100 midterm2 = 100.00 >>> midterm2 = 70 midterm2 = 70.00 >>> midtermAvg[i=1-2] = (midterm1[i] + midterm2[i]) / 2 midtermAvg = 92.50 midtermAvg = 80.00 >>> midterm1 = 95 midterm1 = 95.00Notice that when I modified midterm1 at the end of the example the interpreter did not re-evaluated midtermAvg even though midtermAvg depends on midterm1'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 = final Error: final is undefined final = undef >>> final = foo Error: foo is undefined final = undefHere is another example:
>>> midterm = 50 midterm = 50.00 >>> midterm = 100 midterm = 100.00 >>> comp = min(midterm, midterm, midterm) Error: midterm is undefined comp = undef
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
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.