909 B
909 B
JOURNAL — phase eval
2026-06-15 — Initial implementation
What I built
calc/evaluator.py:evaluate(node)walks Num/BinOp/Unary AST nodes recursively. SLASH branch guardsright == 0and raisesEvalError("division by zero").calc.py: CLI entry point.fmt(value)converts whole-valued floats to int string. CatchesLexError|ParseError|EvalError, prints to stderr, exits 1.calc/test_evaluator.py: 11 tests across 3 classes covering D1–D3.
Local verification
$ python -m unittest -q
----------------------------------------------------------------------
Ran 50 tests in 0.003s
OK
$ python calc.py "2+3*4"
14
$ python calc.py "(2+3)*4"
20
$ python calc.py "7/2"
3.5
$ python calc.py "4/2"
2
$ python calc.py "1/0"
error: division by zero (stderr, exit 1)
$ python calc.py "1 +"
error: unexpected token 'EOF' (stderr, exit 1)
All D1–D5 verified locally.