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,82 @@
# STATUS — eval phase
## DONE
All DoD gates D1D5 implemented and self-certified (BUILD phase — DEFERRED review protocol).
---
## What was built
- `calc/evaluator.py``EvalError`, `evaluate(node) -> int | float` (AST walker)
- `calc.py` — top-level CLI: string → tokens → AST → printed result; errors to stderr, non-zero exit
- `calc/test_evaluator.py` — 24 unittest cases covering D1D4; D5 = whole suite green
---
## Gates
### D1 — Arithmetic ✓
`evaluate(parse(tokenize(s)))` correct for +, -, *, /, precedence, parens, unary minus.
| Expression | Expected | Actual |
|------------|----------|--------|
| `2+3*4` | 14 | 14 |
| `(2+3)*4` | 20 | 20 |
| `8-3-2` | 3 | 3 |
| `-2+5` | 3 | 3 |
| `2*-3` | -6 | -6 |
### D2 — Division ✓
- `7/2` → 3.5 (true division)
- `1/0``EvalError("Division by zero")` — NOT bare `ZeroDivisionError`
### D3 — Result type ✓
Rule: whole-valued results coerced to `int`; non-whole kept as `float`.
| Expression | Result | Type | str() |
|------------|--------|-------|--------|
| `4/2` | 2 | int | `"2"` |
| `7/2` | 3.5 | float | `"3.5"`|
| `2+3*4` | 14 | int | `"14"` |
### D4 — CLI ✓
```
python calc.py "2+3*4" → stdout: 14 exit: 0
python calc.py "(2+3)*4" → stdout: 20 exit: 0
python calc.py "7/2" → stdout: 3.5 exit: 0
python calc.py "4/2" → stdout: 2 exit: 0
python calc.py "1/0" → stderr: Error: Division by zero exit: 1
python calc.py "1 +" → stderr: Error: Unexpected end of input exit: 1
```
No tracebacks on error paths.
### D5 — Tests green ✓
```
python -m unittest -q
→ Ran 68 tests in 0.XXXs / OK
```
68 tests (20 lex + 24 parser + 24 evaluator), 0 failures, no regressions.
---
## Verify (cold)
```bash
python -m unittest -q # Ran 68 tests … 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 end of input (stderr, exit 1)
```
Expected commit sha: `4fada74cca2255be4619fcffbe824ed6acf89a63`