A formula's whole point is referring to other cells. Today you make a cell reference a leaf of the AST, so "=A1+B1" parses into a tree with two cell nodes the evaluator can later resolve.
Parse a Cell token into a CellNode leaf holding its coordinate.
Until now the only leaves in the tree were numbers. A cell reference is the
other kind of leaf, and it is what turns a calculator into a spreadsheet. When the
primary parser meets a Cell token, it parses the reference text into a coordinate
(reusing parseRef from Chapter 1) and wraps it in a CellNode. A CellNode
renders as its A1 address, so it reads naturally in the parenthesized output.
Because references are just another primary, they compose with all the precedence
you already built: A1+B1*2 parses with B1*2 as a subtree and prints
(A1 + (B1 * 2)), exactly as the numeric version did. The CellNode only records
which cell the formula points at - it does not know that cell’s value yet. Turning
a CellNode into the value stored at that address is the evaluator’s job in the
next chapter; for now the tree simply remembers the dependency.
type CellNode struct{ Ref Ref }func (n CellNode) String() string { return formatRef(n.Ref) }// in primary(): a Cell token becomes a CellNodecase TCell:return CellNode{Ref: parseRef(t.Text)}