The following notes briefly describe how you can use my interpreter classes to implement your spreadsheet interface. You should copy the /home/cs365/www-home/project5/formula directory to your formula directory and then add your interface classes.
You can parse a new formula and get it assigned to the appropriate cells using the following call:
parser expParser = new parser(new Yylex(new StringReader(formula))); expParser.parse();formula should be a String variable that points to the formula you want parsed.
If the formula contains either a syntactic or semantic error, the parser will throw a ParserError exception. ParserError extends the RuntimeException class. It contains an explanation of the error in the public variable errorMsg. You can display this string in an error dialog box so that the user knows that an error has occurred. Your spreadsheet interface will need to catch this exception and display an error dialog box.
My parser will simply assign the new formula to the appropriate set of cells and it will create a list of cells that need to be re-evaluated but it will not actually bring the cells up-to-date. In order to bring the cells up-to-date you will need to make the following call:
LinkedList<Cell> updatedCells = Cell.updateCells();updateCells is a static method in my Cell class which re-evaluates all out-of-date cells and returns a linked list of cells that have changed. Your interface code can iterate through this list of cells and update the appropriate cell fields in your interface. Before printing the value of a cell your code should check to see whether the cell's value is undefined. If so you should print "Undef" in the cell's field rather than a floating point number. The following instance variables and methods in a Cell object may prove helpful to you:
These instance variables and methods should allow you to locate the appropriate field in your spreadsheet that should be updated and to display the appropriate value in that field.
Here is the example code that I used to test my parser code to make sure it works. Basically I updated my formula interpreter to use the new methods that I defined for the Cell class and the new ParserError class to handle invalid formulas.