bite-size pieces, twenty minutes a day

Large projects in bite-size pieces.

The kind of software you would normally treat as a black box โ€” databases, compilers, codecs โ€” written in bite-size pieces. Each lesson is one focused twenty-minute session with a concrete spec to hit, and the pieces add up to something that actually runs.

No streaks. No badges. 100% free.

build-an-expression-evaluator / lesson-14.md
Lesson 14 ยท Evaluating the AST

Evaluating the four operators

The spec
Scenario: Arithmetic evaluates through the tree
Given the expression string "2 + 3 * 4"
When it is evaluated with EvalString
Then the result is 14
Your code
// evaluate both sides, then the operator
l, r := Eval(n.Left), Eval(n.Right)
switch n.Op {
case "+": return l + r
case "*": return l * r
}
Further Reading

Crafting Interpreters, by Robert Nystrom.

Checkpoint
The evaluator computes all four operators. Commit and stop here.
// staying grounded in real code in the age of aiDatabasesCompilersRenderersEmulators
Projects

Pick something worth building.

View all projects โ†’