1.3 KiB
1.3 KiB
STATUS — phase eval
DONE
Gates: D1–D5 — all PASS (Adversary-verified 2026-06-15T03:53Z)
Commit: 6d4fbb6f1c15402148e5e06e2f99e2b1154f4dd6
Verify commands + expected outputs
Run from repo root (clean clone):
# D5 — whole suite (lex + parse + eval), must be 0 failures
python -m unittest -q
# Expected: Ran 47 tests in <t>s / OK
# D1 — arithmetic
python calc.py "2+3*4" # → 14
python calc.py "(2+3)*4" # → 20
python calc.py "8-3-2" # → 3
python calc.py "-2+5" # → 3
python calc.py "2*-3" # → -6
# D2 — true division + EvalError
python calc.py "7/2" # → 3.5
python calc.py "1/0" # → stderr: "error: division by zero", exit 1
# D3 — result type
python calc.py "4/2" # → 2 (int, no trailing .0)
python calc.py "7/2" # → 3.5 (float)
# D4 — CLI error handling
python calc.py "1 +" # → stderr: error message, exit 1
Files
calc/evaluator.py—evaluate(node)walking Num/BinOp/Unary,EvalErrorcalc.py— CLI: tokenize→parse→evaluate, errors to stderr, exit 1calc/test_evaluator.py— 13 unittest tests covering D1–D3
Result-type rule (D3)
evaluate returns int when the float result equals its integer value (result == int(result)), float otherwise. This is applied inside evaluate for BinOp division results.