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 @@
# BACKLOG — eval phase
## Build backlog
_(Builder's items — read-only for Adversary)_
## Adversary findings
_(To be populated after comprehensive cold-verification of eval phase build.)_

View File

@ -0,0 +1,14 @@
# BACKLOG — lex phase
## Build backlog
- [x] D1 — NUMBER token for integers and floats (int/float value)
- [x] D2 — PLUS, MINUS, STAR, SLASH, LPAREN, RPAREN, EOF tokens
- [x] D3 — skip whitespace (space/tab); raise LexError on invalid char
- [x] D4 — calc/test_lexer.py passing 20 unittest cases
All items complete.
## Adversary findings
_(No findings yet.)_

View File

@ -0,0 +1,9 @@
# BACKLOG — parse phase
## Build backlog
_(Builder manages this section.)_
## Adversary findings
_(No findings yet — comprehensive verification deferred to review phase.)_

View File

@ -0,0 +1,10 @@
# BACKLOG — review phase
## Build backlog
- [ ] Address any findings filed by Adversary in REVIEW-review.md
- [ ] Write "## DONE" to STATUS-review.md after Adversary's comprehensive PASS
## Adversary findings
(Adversary writes here)

View File

@ -0,0 +1,7 @@
# DECISIONS — shared (append-only)
## 2026-06-16T01:44Z
Adversary adopting DEFERRED review cadence per standing role instructions.
Per-gate verdicts will NOT be written during build phases (lex/parse/eval).
Comprehensive cold-verification deferred to the `review` phase.

View File

@ -0,0 +1,10 @@
# JOURNAL — eval phase (Adversary)
## 2026-06-16 — Initialization
- Pulled repo: 44 tests passing (lex + parse baseline clean).
- Eval phase not yet built: no evaluator.py, no calc.py, no STATUS-eval.md.
- Initialized REVIEW-eval.md, BACKLOG-eval.md, JOURNAL-eval.md.
- Early probes on existing AST shapes confirm correct parse output for all D1 eval test cases.
- Key risks identified: EvalError vs ZeroDivisionError boundary (D2), whole-value formatting (D3), traceback suppression in CLI (D4).
- Waiting for Builder to implement eval phase.

View File

@ -0,0 +1,43 @@
# JOURNAL — lex phase
## 2026-06-16T01:44Z — Adversary initialized
Adversary loop started. Phase plan read. DEFERRED review protocol noted.
Working directory is clean (only seed commit). Waiting for Builder to push code.
Coordination files created:
- machine-docs/STATUS-lex.md
- machine-docs/REVIEW-lex.md
- machine-docs/BACKLOG-lex.md
- machine-docs/JOURNAL-lex.md (this file)
## 2026-06-16T01:46Z — Builder: implementation complete
**Plan read:** lex.md — tokenizer for arithmetic calculator.
**Design decisions:**
- `Token` uses `__slots__` for efficiency; has `__eq__` for test assertions.
- `LexError(Exception)` with message including char and position.
- Number parsing: scan while digit or (`.` and not yet seen dot) → convert to `int` or `float` based on `has_dot`.
- Handles `.5`, `10.`, `3.14` per spec.
- Single-char dispatch table for operators/parens.
**Test run output:**
```
Ran 20 tests in 0.001s
OK
```
**Plan verify commands output:**
```
python -m unittest -q
→ Ran 20 tests in 0.001s / 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')"
→ LexError: Unexpected character '@' at position 2
```
All DoD items D1D4 satisfied. Self-certifying as BUILD phase.

View File

@ -0,0 +1,23 @@
# JOURNAL — review phase
## 2026-06-16 — review phase start
Read phase plan. Prior phases (lex, parse, eval) all self-certified DONE under DEFERRED protocol.
Full test suite pre-run:
```
python -m unittest -q
Ran 68 tests in 0.077s
OK
```
Cross-feature D3 cases manually verified:
- `-(-(1+2))` → 3 (exit 0) ✓
- `2+3*4-5/5` → 13 (exit 0) ✓
- `1 @ 2` → Error: Unexpected character '@' at position 2 (stderr, exit 1) ✓
- `1/0` → Error: Division by zero (stderr, exit 1) ✓
- `(1+` → Error: Unexpected end of input (stderr, exit 1) ✓
- ` 3.14 * (2 + 1) ` → 9.42 (exit 0) ✓
- `1.5 + (2.5 * 2)` → 6.5 (exit 0) ✓
STATUS-review.md filed with complete verification instructions. Claiming D1/D2/D3 ready for Adversary comprehensive cold-verification.

View File

@ -0,0 +1,27 @@
# REVIEW — eval phase
**Protocol:** DEFERRED. Comprehensive verification runs once the eval phase build is complete, covering ALL prior DoD items (lex + parse + eval) in one cold pass.
## Verdicts
_No verdicts written yet — awaiting eval phase build completion._
## Early Probes
**Baseline (pre-eval):** 44 tests pass (20 lex + 24 parser). No regression risk from prior phases.
**AST shapes verified for D1 eval cases:**
- `2+3*4``BinOp('+', Num(2), BinOp('*', Num(3), Num(4)))` ✓ (evaluates to 14)
- `(2+3)*4``BinOp('*', BinOp('+', Num(2), Num(3)), Num(4))` ✓ (evaluates to 20)
- `8-3-2``BinOp('-', BinOp('-', Num(8), Num(3)), Num(2))` ✓ (evaluates to 3)
- `-2+5``BinOp('+', Unary('-', Num(2)), Num(5))` ✓ (evaluates to 3)
- `2*-3``BinOp('*', Num(2), Unary('-', Num(3)))` ✓ (evaluates to -6)
**Probe targets to hit once eval is built:**
- `1/0` → EvalError (not bare ZeroDivisionError), stderr, non-zero exit
- `4/2` → prints `2` (not `2.0`) — D3 whole-value rule
- `7/2` → prints `3.5` — D3 non-whole rule
- `1 +` → error to stderr, exit non-zero, no Python traceback
- `--5` → what does the evaluator do with double unary? (parser accepts it: Unary('-', Unary('-', Num(5))))
- Float literals: `2.5*2` → 5.0 or 5?
- Whitespace-only: `" "` → ParseError from parser (Empty input after lex strips spaces)

View File

@ -0,0 +1,11 @@
# REVIEW — lex phase
**Protocol:** DEFERRED. Comprehensive verification runs in the `review` phase, not per-gate.
## Verdicts
_No verdicts written yet — awaiting comprehensive review phase._
## Early Probes
_(Findings from early break-it probes logged here as they occur.)_

View File

@ -0,0 +1,11 @@
# REVIEW — parse phase
**Protocol:** DEFERRED. Comprehensive verification runs in the `review` phase, not per-gate.
## Verdicts
_No verdicts written yet — awaiting comprehensive review phase._
## Early Probes
_(Findings from early break-it probes logged here as they occur.)_

View File

@ -0,0 +1,83 @@
# REVIEW — review phase
## review(all): PASS @2026-06-16T00:00Z
Adversary cold-verification of the entire accumulated build (lex + parse + eval).
---
## D1 — Full cold re-verify (all prior phase DoD)
Re-ran from scratch in the work-adv clone (fresh pull, no cached state).
**Test suite:** `python -m unittest -v` → Ran 68 tests in 0.087s — **OK, 0 failures**
Subsystems verified:
- Lexer (20 tests): tokens, numbers (int/float), operators, parens, whitespace, LexError ✓
- Parser (24 tests): AST node shape, precedence, left-assoc, unary, parens, ParseError ✓
- Evaluator (24 tests): arithmetic, true division, result types (int/float coercion), CLI, EvalError ✓
**D1: PASS**
---
## D2 — Full suite green
`python -m unittest -q``Ran 68 tests in 0.087s / OK`
**D2: PASS**
---
## D3 — Cross-feature break-it
All of Builder's pre-verified table confirmed independently:
| Expression | Expected | Actual | Exit |
|----------------------|----------------------|-----------------------------------|------|
| `-(-(1+2))` | 3 (int) | 3 (int) | 0 |
| `2+3*4-5/5` | 13 (int) | 13 (int) | 0 |
| `1 @ 2` | LexError on stderr | Error: Unexpected character '@' at position 2 | 1 |
| `1/0` | EvalError on stderr | Error: Division by zero | 1 |
| `(1+` | ParseError on stderr | Error: Unexpected end of input | 1 |
| ` 3.14 * (2 + 1) ` | 9.42 (float) | 9.42 (float) | 0 |
| `1.5 + (2.5 * 2)` | 6.5 (float) | 6.5 (float) | 0 |
Additional adversary probes (break-it attempts):
| Expression | Expected | Actual | Status |
|------------------------|-------------------|------------------------|--------|
| `6.0/2` | 3 (int) | 3 (int) | PASS |
| `(.5+.5)*4` | 4 (int) | 4 (int) | PASS |
| `-0` | 0 (int) | 0 (int) | PASS |
| `---5` | -5 (int) | -5 (int) | PASS |
| `1.5+1.5` | 3 (int) | 3 (int) | PASS |
| `-2*3` | -6 (int) | -6 (int) | PASS |
| `2-1-1` | 0 (int, L-assoc) | 0 (int) | PASS |
| `8/4/2` | 1 (int, L-assoc) | 1 (int) | PASS |
| `((3+1)*2-(4/2))/3` | 2 (int) | 2 (int) | PASS |
| `1+2 3` | ParseError | ParseError: Unexpected token after expression | PASS |
| `1++2` | ParseError | ParseError: Unexpected token 'PLUS' | PASS |
| `(1+2` | ParseError | ParseError: Expected RPAREN, got 'EOF' | PASS |
| `1+2)` | ParseError | ParseError: Unexpected token after expression | PASS |
| `)(` (mismatched) | ParseError | ParseError: Unexpected token 'RPAREN' | PASS |
| ` ` (whitespace only)| ParseError | ParseError: Empty input | PASS |
| `""` (empty string) | ParseError | ParseError: Empty input | PASS |
No error leaked a bare traceback on any path. ZeroDivisionError does not escape `evaluate()`.
**D3: PASS**
---
## D4 — Findings cleared
No defects found. No VETOs.
**D4: PASS**
---
## Verdict
**review(all): PASS** — every DoD item from every phase (lex, parse, eval, review) verified by Adversary from cold state. No findings. No VETOs.

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`

View File

@ -0,0 +1,73 @@
# STATUS — lex phase
## DONE
All DoD gates D1D4 implemented and self-certified (BUILD phase — DEFERRED review protocol).
---
## What was built
- `calc/__init__.py` — makes `calc` a package
- `calc/lexer.py``Token`, `LexError`, `tokenize(src) -> list[Token]`
- `calc/test_lexer.py` — 20 unittest cases covering D1D4
---
## D1 — Numbers ✓
Integers and floats tokenize to NUMBER with correct Python type (int / float).
Verify:
```bash
python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize('42')])"
# Expected: [('NUMBER', 42), ('EOF', None)]
python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize('.5')])"
# Expected: [('NUMBER', 0.5), ('EOF', None)]
python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize('10.')])"
# Expected: [('NUMBER', 10.0), ('EOF', None)]
```
## D2 — Operators & Parens ✓
All six single-char operators tokenize to the right kind.
Verify:
```bash
python -c "from calc.lexer import tokenize; print([t.kind for t in tokenize('1+2*3')])"
# Expected: ['NUMBER', 'PLUS', 'NUMBER', 'STAR', 'NUMBER', 'EOF']
```
## D3 — Whitespace & Errors ✓
Spaces/tabs skipped; invalid chars raise `LexError` with char + position.
Verify:
```bash
python -c "from calc.lexer import tokenize; tokenize('1 @ 2')"
# Expected: raises calc.lexer.LexError: Unexpected character '@' at position 2
```
## D4 — Tests green ✓
20 tests, 0 failures.
Verify:
```bash
python -m unittest -q
# Expected: Ran 20 tests in 0.00xs / OK
```
---
## Plan verify commands (from lex.md)
```bash
python -m unittest -q
# → Ran 20 tests in 0.001s / 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')"
# → LexError: Unexpected character '@' at position 2
```
Commit sha: 0092890 (chore: add .gitignore, remove tracked pycache)
009755c (feat(lex): implement lexer, Token, LexError, and test suite)

View File

@ -0,0 +1,138 @@
# STATUS — parse phase
## DONE
All DoD gates D1D6 implemented and self-certified (BUILD phase — DEFERRED review protocol).
---
## What was built
- `calc/parser.py``ParseError`, `Num`, `BinOp`, `Unary`, `parse(tokens) -> Node`
- `calc/test_parser.py` — 24 unittest cases covering D1D5 (D6 = all pass)
---
## AST shape (stable contract for the evaluator)
```
Num(value) .value — int or float
BinOp(op, left, right) .op — one of '+', '-', '*', '/'
.left — any Node
.right — any Node
Unary(op, operand) .op — '-'
.operand — any Node
```
All nodes implement `__repr__` and `__eq__`.
---
## D1 — Precedence ✓
`1+2*3` parses as `BinOp('+', Num(1), BinOp('*', Num(2), Num(3)))``*` tighter than `+`.
Verify:
```bash
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 ✓
`8-3-2``BinOp('-', BinOp('-', Num(8), Num(3)), Num(2))`
`8/4/2``BinOp('/', BinOp('/', Num(8), Num(4)), Num(2))`
Verify:
```bash
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))
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 — Parentheses ✓
`(1+2)*3``BinOp('*', BinOp('+', Num(1), Num(2)), Num(3))``+` is child of `*`.
Verify:
```bash
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 ✓
```
-5 → Unary('-', Num(5))
-(1+2) → Unary('-', BinOp('+', Num(1), Num(2)))
3 * -2 → BinOp('*', Num(3), Unary('-', Num(2)))
```
Verify:
```bash
python -c "from calc.lexer import tokenize; from calc.parser import parse; print(parse(tokenize('-5')))"
# Expected: Unary('-', Num(5))
python -c "from calc.lexer import tokenize; from calc.parser import parse; print(parse(tokenize('-(1+2)')))"
# Expected: Unary('-', BinOp('+', Num(1), Num(2)))
python -c "from calc.lexer import tokenize; from calc.parser import parse; print(parse(tokenize('3 * -2')))"
# Expected: BinOp('*', Num(3), Unary('-', Num(2)))
```
## D5 — Errors ✓
Each of the following raises `ParseError` (not any other exception):
| Input | ParseError message |
|----------|--------------------|
| `'1 +'` | `Unexpected end of input` |
| `'(1'` | `Expected RPAREN, got 'EOF' (None)` |
| `'1 2'` | `Unexpected token after expression: 'NUMBER' (2)` |
| `')('` | `Unexpected token 'RPAREN' (')')` |
| `''` | `Empty input` |
Verify:
```bash
python -c "from calc.lexer import tokenize; from calc.parser import parse; parse(tokenize('1 +'))"
# Expected: raises ParseError: Unexpected end of input
python -c "from calc.lexer import tokenize; from calc.parser import parse; parse(tokenize('(1'))"
# Expected: raises ParseError: Expected RPAREN...
python -c "from calc.lexer import tokenize; from calc.parser import parse; parse(tokenize('1 2'))"
# Expected: raises ParseError: Unexpected token after expression...
python -c "from calc.lexer import tokenize; from calc.parser import parse; parse(tokenize(')('))"
# Expected: raises ParseError: Unexpected token 'RPAREN'...
python -c "from calc.lexer import tokenize; from calc.parser import parse; parse(tokenize(''))"
# Expected: raises ParseError: Empty input
```
## D6 — Tests green ✓
44 total tests (20 lex + 24 parser), 0 failures.
Verify:
```bash
python -m unittest -q
# Expected: Ran 44 tests in 0.00xs / OK
```
---
## Plan verify commands (from parse.md)
```bash
python -m unittest -q
# → Ran 44 tests in 0.001s / OK
python -c "from calc.lexer import tokenize; from calc.parser import parse; print(parse(tokenize('1+2*3')))"
# → BinOp('+', Num(1), BinOp('*', Num(2), Num(3)))
python -c "from calc.lexer import tokenize; from calc.parser import parse; parse(tokenize('1 +'))"
# → ParseError: Unexpected end of input
```

View File

@ -0,0 +1,68 @@
# STATUS — review phase
## DONE
Adversary cold-verification: PASS (commit `6d89215`). All D1D4 items verified, 0 findings, no VETOs.
---
## What the Adversary needs to verify
The entire accumulated build (lex + parse + eval phases) is complete and self-certified.
The Adversary must cold-verify all three prior phases in one pass per the DEFERRED protocol.
### Commit
Expected commit sha: `0d4ee30`
Branch: `main` (origin/main)
### D1 — Full cold re-verify (all prior phase DoD)
**HOW:** From a fresh clone, run:
```bash
cd /tmp/<fresh-clone>
python -m unittest -q
```
**EXPECTED:** `Ran 68 tests in 0.XXXs / OK` — 0 failures
Subsystems verified:
- Lexer (`calc/lexer.py`): 20 tests covering tokens, numbers, operators, whitespace, LexError
- Parser (`calc/parser.py`): 24 tests covering AST shape, precedence, unary, parens, ParseError
- Evaluator (`calc/evaluator.py`): 24 tests covering arithmetic, division, result types, CLI, EvalError
### D2 — Full suite green
**HOW:** `python -m unittest -q`
**EXPECTED:** `Ran 68 tests in 0.XXXs / OK`
### D3 — Cross-feature break-it
Builder pre-verified all D3 cases (results below):
| Expression | Expected | Actual | Exit |
|--------------------|----------|--------|------|
| `-(-(1+2))` | 3 | 3 | 0 |
| `2+3*4-5/5` | 13 | 13 | 0 |
| `1 @ 2` | Error: Unexpected character '@' at position 2 (stderr) | ✓ | 1 |
| `1/0` | Error: Division by zero (stderr) | ✓ | 1 |
| `(1+` | Error: Unexpected end of input (stderr) | ✓ | 1 |
| ` 3.14 * (2 + 1) `| 9.42 | 9.42 | 0 |
| `1.5 + (2.5 * 2)` | 6.5 | 6.5 | 0 |
Adversary must re-run these and any additional break-it cases it chooses.
### D4 — Findings cleared
No findings yet. Adversary to file defects in REVIEW-review.md. Builder will address all findings.
---
## File locations
- `calc/lexer.py` — tokenizer
- `calc/parser.py` — recursive-descent parser + AST nodes
- `calc/evaluator.py` — AST evaluator + EvalError
- `calc.py` — CLI entry point
- `calc/test_lexer.py`, `calc/test_parser.py`, `calc/test_evaluator.py` — test suites