Formula interpretation
The core of a spreadsheet program is its ability to interpret formulas. When the user inputs a formula in a cell, it is interpreted and its value is evaluated. The process of formula interpretation is divided into three separate steps. First, given the input string, the Scanner generates a Token List, then the Parser generates a Syntax Tree, and the Evaluator determines the value.
![](https://static.packt-cdn.com/products/9781786464224/graphics/B05475_09_02.jpg)
A token is the least significant part of the formula. For instance, a1 is interpreted as a reference and 1.2 is interpreted as a value. Assuming that the cells have values according to the following sheet, the formula interpretation process will be as follows. Remember that a formula is text beginning with an equal sign (=).
![](https://static.packt-cdn.com/products/9781786464224/graphics/B05475_09_03.jpg)
![](https://static.packt-cdn.com/products/9781786464224/graphics/B05475_09_04.jpg)
![](https://static.packt-cdn.com/products/9781786464224/graphics/B05475_09_05.jpg)
The tokens
The scanner takes a string as input and finds its least significant parts-its tokens. Spaces between the tokens are ignored, and the scanner makes out no difference between capital and small letters. The Value
token needs an extra piece of information...