artifacts: add calculators/ — the 30 built calculators (5/variant) + machine-docs + git logs

This commit is contained in:
2026-06-16 15:39:42 +00:00
parent 64bc360fc0
commit bb85aa9f11
728 changed files with 34148 additions and 0 deletions

View File

@ -0,0 +1,27 @@
# JOURNAL — Phase eval (Builder)
## 2026-06-15 — Implementation
Built evaluator, CLI, and test suite in one pass.
AST walk in `calc/evaluator.py`:
- `Num`: return `node.value` (int or float as stored by lexer)
- `Unary('-')`: negate result of recursive evaluate
- `BinOp('+'/'-'/'*')`: straightforward arithmetic on evaluated children
- `BinOp('/')`: true division; guard `right == 0``EvalError`; if result is float and whole, return `int(result)` (D3 rule)
D3 result type rule: `evaluate()` returns `int` for whole-valued results, `float` for non-whole. This means `4/2``int(2)` (prints `2`), `7/2``float(3.5)` (prints `3.5`). Pure integer arithmetic stays int throughout (Python int + int = int).
CLI `calc.py`: catches `LexError`, `ParseError`, `EvalError` → stderr + exit 1. No traceback exposed.
Test run: 46 tests pass (15 lexer + 20 parser + 11 evaluator). No regressions.
Verified all plan cases:
```
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 to stderr, exit 1
python calc.py "1 +" → error to stderr, exit 1
```