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,9 @@
# JOURNAL-eval
## Design notes
**evaluator.py**: Straightforward AST walker. `_normalize(v)` converts a float to int when `v == int(v)` — this handles the D3 requirement cleanly for both direct integer arithmetic and whole-valued division results. Division by zero is caught before the `/` operation and wrapped as `EvalError`.
**calc.py**: Catches `LexError`, `ParseError`, and `EvalError`; prints `error: <message>` to stderr and exits 1. No traceback leaks.
**test_evaluator.py**: 13 tests covering all D1 arithmetic cases, D2 true division and EvalError, D3 type assertions. Full 42-test suite (lex 16 + parse 13 + eval 13) passes.

View File

@ -0,0 +1,13 @@
# JOURNAL — phase lex
## Approach
- `Token` is a `dataclass` with `kind: str` and `value: Union[int, float, str, None]`.
- `tokenize()` is a simple single-pass scanner using index `i`.
- Numbers: greedy scan of digits and `.`; if `.` present → `float`, else → `int`.
- Operators/parens: single-char dispatch via `_SINGLE` dict.
- Whitespace (space, tab): skipped silently.
- Anything else: raises `LexError` with the offending char and position.
- `EOF` token appended at the end.
## Test count: 13 — all green on first run.

View File

@ -0,0 +1,15 @@
# JOURNAL-parse
## Design decisions
- **Grammar**: classic 3-level recursive descent:
- `expr → term (('+' | '-') term)*` (lowest precedence)
- `term → unary (('*' | '/') unary)*` (medium)
- `unary → '-' unary | primary` (right-recursive for stacked unary)
- `primary → NUMBER | '(' expr ')'`
- Left associativity falls out naturally from the `while` loops in `_expr` and `_term`.
- Unary is right-recursive (`-` `-` 5 → nested Unary) as is conventional.
- Empty input detected early at `parse()` entry before any descent.
- Trailing tokens detected after `_expr()` returns, before EOF check.
## Test count: 31 (20 parser + 11 existing lexer)

View File

@ -0,0 +1,38 @@
# REVIEW — phase eval
Adversary cold-verify against commit `0a56046`.
## Results
| Gate | Verdict | Evidence |
|------|---------|----------|
| D1 | PASS | `2+3*4`→14, `(2+3)*4`→20, `8-3-2`→3, `-2+5`→3, `2*-3`→-6 |
| D2 | PASS | `7/2`→3.5 (true div); `1/0` raises `EvalError`, not bare `ZeroDivisionError` |
| D3 | PASS | `4/2``2` (int, no .0); `7/2``3.5` (float) |
| D4 | PASS | `python calc.py "2+3*4"` prints `14`, exit 0; `python calc.py "1 +"` prints error to stderr only, exit 1; `python calc.py "1/0"` same |
| D5 | PASS | `python -m unittest -q` → 42 tests, 0 failures; covers D1D3 and full prior suite (lex + parse) |
## Verification commands run
```
python -m unittest -q # 42 OK
python calc.py "2+3*4" # 14, exit 0
python calc.py "(2+3)*4" # 20, exit 0
python calc.py "8-3-2" # 3
python calc.py "-2+5" # 3
python calc.py "2*-3" # -6
python calc.py "7/2" # 3.5, exit 0
python calc.py "4/2" # 2, exit 0
python calc.py "1/0" (2>/dev/null) # stdout empty, exit 1; stderr: "error: division by zero"
python calc.py "1 +" (2>/dev/null) # stdout empty, exit 1; stderr: "error: unexpected token 'EOF' (None)"
```
## Verdict
eval/D1: PASS @2026-06-15T00:00:00Z
eval/D2: PASS @2026-06-15T00:00:00Z
eval/D3: PASS @2026-06-15T00:00:00Z
eval/D4: PASS @2026-06-15T00:00:00Z
eval/D5: PASS @2026-06-15T00:00:00Z
All five gates PASS. No VETO. Builder may write `## DONE` to `machine-docs/STATUS-eval.md`.

View File

@ -0,0 +1,50 @@
# REVIEW — phase lex
Adversary cold-verification against commit `80d7ee3`.
## Verdicts
- **lex/D1: PASS** @2026-06-15T02:35Z
- `tokenize("42")``[Token(kind='NUMBER', value=42), Token(kind='EOF', value=None)]`; value is `int`.
- `tokenize("3.14")``NUMBER` with `float(3.14)`.
- `tokenize(".5")``NUMBER 0.5`; `tokenize("10.")``NUMBER 10.0 float`.
- **lex/D2: PASS** @2026-06-15T02:35Z
- `tokenize("1+2*3")``NUMBER PLUS NUMBER STAR NUMBER EOF`. ✓
- `tokenize("+-*/()")``PLUS MINUS STAR SLASH LPAREN RPAREN EOF`. ✓
- **lex/D3: PASS** @2026-06-15T02:35Z
- `" 12 + 3 "` — spaces skipped, yields `NUMBER PLUS NUMBER EOF`. ✓
- `"\t"` (tabs) skipped. ✓
- `tokenize("1 @ 2")``calc.lexer.LexError: unexpected character '@' at position 2` (exit 1). ✓
- `"$10"` and `"abc"` also raise `LexError`. ✓
- **lex/D4: PASS** @2026-06-15T02:35Z
- `python -m unittest -q` output: `Ran 13 tests in 0.000s / OK`. Zero failures.
- Test suite covers `" 12 + 3 "`, `"3.5*(1-2)"`, `"1 @ 2"` raises `LexError`. ✓
## Evidence
```
$ python -m unittest -q
----------------------------------------------------------------------
Ran 13 tests in 0.000s
OK
$ python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize('3.5*(1-2)')])"
[('NUMBER', 3.5), ('STAR', '*'), ('LPAREN', '('), ('NUMBER', 1), ('MINUS', '-'), ('NUMBER', 2), ('RPAREN', ')'), ('EOF', None)]
$ python -c "from calc.lexer import tokenize; tokenize('1 @ 2')" 2>&1
calc.lexer.LexError: unexpected character '@' at position 2
exit code: 1
```
## Observations (not gate failures)
- `tokenize("1.2.3")` raises `ValueError: could not convert string to float: '1.2.3'` rather than `LexError`. The plan does not specify this case, so it is not a gate failure; future phases may want to address it.
- STATUS-lex.md omits the explicit commit SHA (says "see git log") — minor, not a gate requirement.
## Summary
All four gates D1D4 pass cold verification from the Adversary's clone. No veto.

View File

@ -0,0 +1,109 @@
# REVIEW — phase parse (Adversary)
<!-- Verdicts: review(<id>): PASS|FAIL -->
## Verdicts
| Gate | Verdict | Timestamp |
|------|---------|-----------|
| D1 | PASS | 2026-06-15T02:42Z |
| D2 | PASS | 2026-06-15T02:42Z |
| D3 | PASS | 2026-06-15T02:42Z |
| D4 | PASS | 2026-06-15T02:42Z |
| D5 | PASS | 2026-06-15T02:42Z |
| D6 | PASS | 2026-06-15T02:42Z |
---
## D1: PASS @2026-06-15T02:42Z
`*`/`/` bind tighter than `+`/`-`. Cold-run:
```
1+2*3 → BinOp('+', Num(1), BinOp('*', Num(2), Num(3))) ✓
2*3+4 → BinOp('+', BinOp('*', Num(2), Num(3)), Num(4)) ✓
10-6/2 → BinOp('-', Num(10), BinOp('/', Num(6), Num(2))) ✓
```
Grammar verified: `_expr` calls `_term` (which handles `*`/`/`) before combining with `+`/`-` — precedence is structurally encoded, not a test artifact.
---
## D2: PASS @2026-06-15T02:42Z
Left-associativity for all four operators. Cold-run:
```
8-3-2 → BinOp('-', BinOp('-', Num(8), Num(3)), Num(2)) ✓
8/4/2 → BinOp('/', BinOp('/', Num(8), Num(4)), Num(2)) ✓
1+2+3 → BinOp('+', BinOp('+', Num(1), Num(2)), Num(3)) ✓
```
Associativity comes from `while` loops in `_expr`/`_term` that accumulate left into `node` — correct by construction.
---
## D3: PASS @2026-06-15T02:42Z
Parentheses override precedence. Cold-run:
```
(1+2)*3 → BinOp('*', BinOp('+', Num(1), Num(2)), Num(3)) ✓
((4)) → Num(4) ✓
2*(3+4) → BinOp('*', Num(2), BinOp('+', Num(3), Num(4))) ✓
```
---
## D4: PASS @2026-06-15T02:42Z
Unary minus: leading, nested, after binary operator, double negation. Cold-run:
```
-5 → Unary('-', Num(5)) ✓
-(1+2) → Unary('-', BinOp('+', Num(1), Num(2))) ✓
3 * -2 → BinOp('*', Num(3), Unary('-', Num(2))) ✓
--5 → Unary('-', Unary('-', Num(5))) ✓
```
Adversarial: `---5 → Unary('-', Unary('-', Unary('-', Num(5))))` ✓, `(-5)*3 → BinOp('*', Unary('-', Num(5)), Num(3))` ✓.
---
## D5: PASS @2026-06-15T02:42Z
All five plan-specified error cases raise `ParseError` (not a bare crash). Cold-run:
```
"1 +" → ParseError: unexpected token 'EOF' (None) ✓
"(1" → ParseError: expected 'RPAREN', got 'EOF' ✓
"1 2" → ParseError: unexpected token 'NUMBER' (2) ✓
")(" → ParseError: unexpected token 'RPAREN' (')') ✓
"" → ParseError: empty input ✓
```
Additional adversarial: `+5`, `1*)`, `*5` all raise `ParseError` ✓.
---
## D6: PASS @2026-06-15T02:42Z
```
python -m unittest -q
Ran 31 tests in 0.001s
OK
```
Tests assert on tree structure (dataclass equality), not on evaluation — correct testing approach per plan.
---
## Notes
Grammar is clean recursive descent:
- `expr → term (('+' | '-') term)*`
- `term → unary (('*' | '/') unary)*`
- `unary → '-' unary | primary`
- `primary → NUMBER | '(' expr ')'`
Precedence and associativity are structurally encoded, not patched in. No weak tests that would pass a wrong implementation found.

View File

@ -0,0 +1,48 @@
# STATUS-eval
Commit: 0a560468a157c0026515ee3edb9b8aff6b6a41ab
## Claims
| Gate | DoD item | Claim |
|------|----------|-------|
| D1 | arithmetic (+ - * /, precedence, parens, unary minus) | CLAIMED |
| D2 | true division; EvalError on div-by-zero | CLAIMED |
| D3 | whole-valued → int, non-whole → float | CLAIMED |
| D4 | CLI prints result, exits 0; bad input → stderr, non-zero | CLAIMED |
| D5 | test_evaluator.py passes; full suite (lex+parse+eval) passes | CLAIMED |
## Files changed
- `calc/evaluator.py``evaluate(node) -> int | float`, `EvalError`
- `calc/test_evaluator.py` — 13 unittest cases for D1D3
- `calc.py` — CLI entry point for D4
## Verify commands (exact, in working directory)
```bash
# D5 — full suite
python -m unittest -q
# expected: Ran 42 tests in ... OK
# D1
python calc.py "2+3*4" # expected: 14
python calc.py "(2+3)*4" # expected: 20
python calc.py "8-3-2" # expected: 3
python calc.py "-2+5" # expected: 3
python calc.py "2*-3" # expected: -6
# D2
python calc.py "7/2" # expected: 3.5
python calc.py "1/0" # expected: error to stderr, exit code 1
# D3
python calc.py "4/2" # expected: 2 (int, no .0)
python calc.py "7/2" # expected: 3.5 (float)
# D4
python calc.py "2+3*4" # expected stdout: 14, exit 0
python calc.py "1 +" # expected: error to stderr, exit non-zero (no traceback)
```
## DONE

View File

@ -0,0 +1,49 @@
## DONE
# STATUS — phase lex
## Claimed gates
- **D1** — numbers (integers, floats, leading/trailing dot)
- **D2** — operators & parens (`+ - * / ( )`)
- **D3** — whitespace skipped; invalid chars raise `LexError` with char and position
- **D4** — test suite 13/13 green, 0 failures
## How to verify (exact commands)
```bash
cd <repo-root>
# D4 — run all tests
python -m unittest -q
# D1+D2 — manual check for 3.5*(1-2)
python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize('3.5*(1-2)')])"
# D3 — must raise LexError
python -c "from calc.lexer import tokenize; tokenize('1 @ 2')"
```
## Expected results
```
# python -m unittest -q
Ran 13 tests in 0.000s
OK
# 3.5*(1-2)
[('NUMBER', 3.5), ('STAR', '*'), ('LPAREN', '('), ('NUMBER', 1), ('MINUS', '-'), ('NUMBER', 2), ('RPAREN', ')'), ('EOF', None)]
# 1 @ 2 — exits non-zero with:
calc.lexer.LexError: unexpected character '@' at position 2
```
## Files
- `calc/__init__.py` — package marker
- `calc/lexer.py``Token`, `LexError`, `tokenize()`
- `calc/test_lexer.py` — 13 unittest cases covering D1D3
## Commit SHA
`80d7ee3` — feat: add calc lexer with Token, LexError, tokenize() — phase lex D1-D4

View File

@ -0,0 +1,120 @@
# STATUS-parse
## DONE
## Claim
All DoD gates D1D6 implemented and verified.
| Gate | Item | Status |
|------|------|--------|
| D1 | `*`/`/` bind tighter than `+`/`-` | claimed PASS |
| D2 | Left associativity | claimed PASS |
| D3 | Parentheses override precedence | claimed PASS |
| D4 | Unary minus | claimed PASS |
| D5 | ParseError on malformed input | claimed PASS |
| D6 | `calc/test_parser.py` — 31 tests, 0 failures | claimed PASS |
## Files
- `calc/parser.py` — parser implementation
- `calc/test_parser.py` — unittest suite
Commit: `00ca873` (claim(D1-D6): feat: add calc parser with AST nodes, recursive descent, full test suite)
## How to verify
```bash
# D6 — all tests
python -m unittest -q
# Expected: OK (31 tests, 0 failures)
# D1 — mul binds tighter than add
python -c "from calc.lexer import tokenize; from calc.parser import parse; print(parse(tokenize('1+2*3')))"
# Expected: BinOp('+', Num(1), BinOp('*', Num(2), Num(3)))
# D2 — left associativity of subtraction
python -c "from calc.lexer import tokenize; from calc.parser import parse; print(parse(tokenize('8-3-2')))"
# Expected: BinOp('-', BinOp('-', Num(8), Num(3)), Num(2))
# D2 — left associativity of division
python -c "from calc.lexer import tokenize; from calc.parser import parse; print(parse(tokenize('8/4/2')))"
# Expected: BinOp('/', BinOp('/', Num(8), Num(4)), Num(2))
# D3 — parens override precedence
python -c "from calc.lexer import tokenize; from calc.parser import parse; print(parse(tokenize('(1+2)*3')))"
# Expected: BinOp('*', BinOp('+', Num(1), Num(2)), Num(3))
# D4 — unary minus with binary mul
python -c "from calc.lexer import tokenize; from calc.parser import parse; print(parse(tokenize('3 * -2')))"
# Expected: BinOp('*', Num(3), Unary('-', Num(2)))
# D4 — negation of group
python -c "from calc.lexer import tokenize; from calc.parser import parse; print(parse(tokenize('-(1+2)')))"
# Expected: Unary('-', BinOp('+', Num(1), Num(2)))
# D5 — ParseError on "1 +"
python -c "
from calc.lexer import tokenize
from calc.parser import parse, ParseError
try:
parse(tokenize('1 +'))
print('ERROR: no exception raised')
except ParseError as e:
print('OK ParseError:', e)
"
# D5 — ParseError on "(1"
python -c "
from calc.lexer import tokenize
from calc.parser import parse, ParseError
try:
parse(tokenize('(1'))
print('ERROR: no exception raised')
except ParseError as e:
print('OK ParseError:', e)
"
# D5 — ParseError on "1 2"
python -c "
from calc.lexer import tokenize
from calc.parser import parse, ParseError
try:
parse(tokenize('1 2'))
print('ERROR: no exception raised')
except ParseError as e:
print('OK ParseError:', e)
"
# D5 — ParseError on ")("
python -c "
from calc.lexer import tokenize
from calc.parser import parse, ParseError
try:
parse(tokenize(')('))
print('ERROR: no exception raised')
except ParseError as e:
print('OK ParseError:', e)
"
# D5 — ParseError on empty string
python -c "
from calc.lexer import tokenize
from calc.parser import parse, ParseError
try:
parse(tokenize(''))
print('ERROR: no exception raised')
except ParseError as e:
print('OK ParseError:', e)
"
```
## AST Node shapes
```
Num(value) — leaf, value is int or float
BinOp(op, left, right) — op is one of '+', '-', '*', '/'
Unary(op, operand) — op is '-'
```
All are dataclasses with `__repr__` that prints the form above.