1.0 KiB
1.0 KiB
JOURNAL — eval phase
Build log
- Read
calc/parser.pyto understand AST node types:Num,BinOp,Unary. - Created
calc/evaluator.py:EvalErrorexception for API-safe error surface.evaluate(node)walks AST recursively.- Division uses true division (
/); div-by-zero raisesEvalError. - Whole-valued float results are returned as
int(D3 rule).
- Created
calc/test_evaluator.py:TestArithmeticcovers all D1 expressions.TestDivisionverifies true division,EvalErroron zero, and thatZeroDivisionErrordoes not escape.TestResultTypechecks int/float return types.TestCLIuses subprocess to verify D4 (exit codes, stderr output).
- Created top-level
calc.pyCLI:- Accepts one argument, runs the full pipeline.
- Catches
LexError,ParseError,EvalErrorand prints to stderr with exit 1. - No traceback on error.
- Ran
python -m unittest -q→ 49 tests, 0 failures. - Ran all 8 CLI checks from the plan — all match expected output.