The power operator was the trickiest to parse, and now it is the payoff to evaluate. Today you compute exponentiation and watch the right-associative grouping you built produce the right number.
Evaluate the ^ operator as exponentiation.
Exponentiation is one more case in the operator switch, computed with the host
language’s power function. The single-line change is small, but the value it produces
is the proof that the right-associative parsing from the earlier chapter was correct.
2 ^ 3 ^ 2 evaluates to 512, because the tree grouped it as 2 ^ (3 ^ 2), which is
2 ^ 9. Had it grouped the other way, you would get (2 ^ 3) ^ 2 = 64 instead.
This is the satisfying part of separating parsing from evaluation: the evaluator does nothing clever about associativity or precedence at all. It blindly walks whatever tree it is handed. All the difficult decisions were made once, in the binding powers, and every operator you evaluate simply inherits them.
// in the Bin operator switch, add a power case using the host math librarycase "^": return math.Pow(l, r), nil