artifacts: add calculators/ — the 30 built calculators (5/variant) + machine-docs + git logs
This commit is contained in:
@ -0,0 +1,7 @@
|
||||
# BACKLOG-eval.md — eval phase backlog
|
||||
|
||||
## Build backlog
|
||||
(Builder fills this in)
|
||||
|
||||
## Adversary findings
|
||||
(none yet)
|
||||
@ -0,0 +1,15 @@
|
||||
# BACKLOG-lex — Builder
|
||||
|
||||
## Build backlog
|
||||
|
||||
- [x] Create calc/__init__.py
|
||||
- [x] Implement calc/lexer.py (Token, LexError, tokenize)
|
||||
- [x] Implement calc/test_lexer.py (unittest covering D1-D3)
|
||||
- [x] Verify locally: python -m unittest -q — 16/16 PASS
|
||||
- [x] Claim D1 (numbers)
|
||||
- [x] Claim D2 (operators & parens)
|
||||
- [x] Claim D3 (whitespace & errors)
|
||||
- [x] Claim D4 (tests green)
|
||||
|
||||
## Awaiting Adversary
|
||||
All gates claimed. Waiting for REVIEW-lex.md verdicts.
|
||||
@ -0,0 +1,14 @@
|
||||
# BACKLOG-parse — Adversary
|
||||
|
||||
## Adversary findings
|
||||
|
||||
(none yet)
|
||||
|
||||
## Build backlog
|
||||
|
||||
- [x] Create `calc/parser.py` with recursive-descent parser
|
||||
- [x] Create `calc/test_parser.py` with 27 tests covering D1–D5
|
||||
- [x] Run `python -m unittest -q` — 43 tests pass (16 lexer + 27 parser)
|
||||
- [x] Verify all AST shapes manually (D1–D5 confirmed)
|
||||
- [x] Write STATUS-parse.md with exact verification commands
|
||||
- [x] Claim D1–D6 (awaiting Adversary PASS)
|
||||
@ -0,0 +1,9 @@
|
||||
# DECISIONS — shared (append-only)
|
||||
|
||||
## 2026-06-15 — Token representation
|
||||
Using `dataclasses.dataclass` for Token (fields: kind: str, value: object).
|
||||
Reason: more ergonomic than namedtuple for downstream parser phases; still pure stdlib.
|
||||
|
||||
## 2026-06-15 — NUMBER value type
|
||||
Integers stored as Python `int`, floats as Python `float`.
|
||||
Detection: presence of `.` in the matched digit string → float.
|
||||
@ -0,0 +1,42 @@
|
||||
# JOURNAL-eval.md — Adversary journal for phase `eval`
|
||||
|
||||
## 2026-06-15T01:26Z — Phase initialized
|
||||
|
||||
- Read phase plan from /home/loops/project-orchestrator/projects/agent-orchestrator-benchmark/plans/calc/eval.md
|
||||
- parse phase is DONE (all D1-D6 PASS)
|
||||
- eval phase not started — no evaluator.py, calc.py, or test_evaluator.py yet
|
||||
- Initialized tracking files: STATUS-eval.md, REVIEW-eval.md, BACKLOG-eval.md, JOURNAL-eval.md
|
||||
- Waiting for Builder to claim gates
|
||||
|
||||
---
|
||||
|
||||
## 2026-06-15 — Builder implementation notes
|
||||
|
||||
### Approach
|
||||
|
||||
Implemented `evaluate(node)` as a recursive AST walk. Key decisions:
|
||||
|
||||
1. **D3 normalization**: `_normalize(val)` converts whole-valued floats (e.g., `2.0`) to `int`. Applied after every arithmetic operation. Ensures `str(evaluate(...))` prints `2` not `2.0` for whole results.
|
||||
|
||||
2. **D2 division by zero**: Explicit `if r == 0: raise EvalError(...)` before `l / r`. Catches integer 0, float 0.0, and zero sub-expressions (e.g., `5/(3-3)`).
|
||||
|
||||
### Test run output
|
||||
|
||||
```
|
||||
$ python -m unittest -q
|
||||
Ran 60 tests in 0.005s
|
||||
OK
|
||||
```
|
||||
|
||||
One fix during dev: `test_expression_div_by_zero` had `calc("5*(3-3)")` (multiplication, not division). Fixed to `calc("5/(3-3)")`.
|
||||
|
||||
### CLI verification output
|
||||
|
||||
```
|
||||
$ 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" → stderr: "error: division by zero", exit=1
|
||||
$ python calc.py "1 +" → stderr: "error: unexpected end of input", exit=1
|
||||
```
|
||||
@ -0,0 +1,59 @@
|
||||
# JOURNAL-lex — Builder
|
||||
|
||||
## 2026-06-15 — Initial setup
|
||||
|
||||
Phase plan read. Mission: build calc/lexer.py with Token (kind, value), LexError,
|
||||
and tokenize(src) -> list[Token]. Kinds: NUMBER, PLUS, MINUS, STAR, SLASH, LPAREN,
|
||||
RPAREN, EOF.
|
||||
|
||||
Design notes:
|
||||
- Token as a dataclass or namedtuple — using dataclass for forward-compat with parser phase
|
||||
- NUMBER value stored as int if no decimal point, float if decimal present
|
||||
- LexError carries offending char and position
|
||||
- tokenize scans left-to-right, skips whitespace, raises on unknown char
|
||||
|
||||
## 2026-06-15 — Implementation + local verification
|
||||
|
||||
Wrote calc/lexer.py and calc/test_lexer.py. Found one bug in test_values_preserved:
|
||||
used a conditional expression `('STAR','*') if False else ('PLUS','+')` accidentally
|
||||
duplicated PLUS in expected list. Fixed immediately.
|
||||
|
||||
Test run output:
|
||||
```
|
||||
$ python -m unittest -q
|
||||
----------------------------------------------------------------------
|
||||
Ran 16 tests in 0.000s
|
||||
|
||||
OK
|
||||
```
|
||||
|
||||
Verification commands:
|
||||
```
|
||||
$ 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')"
|
||||
calc.lexer.LexError: unexpected character '@' at position 2
|
||||
```
|
||||
|
||||
All D1–D4 criteria met. Claiming all gates.
|
||||
|
||||
## 2026-06-15 — Adversary verdicts + AF-1 fix
|
||||
|
||||
Adversary returned: D1 PASS, D2 PASS, D3 PASS, D4 PASS.
|
||||
|
||||
AF-1 filed (non-blocking): malformed floats (`".."`, `"1.2.3"`, `"."`) raised bare
|
||||
`ValueError` from `float(raw)` instead of `LexError`. Root cause: greedy dot scanner
|
||||
at lexer.py:29–31 consumes multi-dot sequences without validation.
|
||||
|
||||
Fix: wrapped `float(raw)` in try/except ValueError → re-raise as LexError with
|
||||
message `"invalid number literal {raw!r} at position {i}"`. Added 3 new tests.
|
||||
|
||||
Post-fix run:
|
||||
```
|
||||
$ python -m unittest -q
|
||||
Ran 19 tests in 0.000s
|
||||
OK
|
||||
```
|
||||
|
||||
Phase DONE.
|
||||
@ -0,0 +1,44 @@
|
||||
# JOURNAL-parse.md
|
||||
|
||||
## 2026-06-15T01:21Z — Parser implementation
|
||||
|
||||
### Approach
|
||||
Implemented a classic recursive-descent parser with three precedence levels:
|
||||
- `_expr()`: handles `+` / `-` (lowest precedence, left-associative)
|
||||
- `_term()`: handles `*` / `/` (middle precedence, left-associative)
|
||||
- `_unary()`: handles unary `-` (right-associative by recursion)
|
||||
- `_primary()`: handles NUMBER literals and `(` expr `)`
|
||||
|
||||
Left-associativity falls out naturally from the while-loop accumulation pattern in `_expr()` and `_term()`: each iteration wraps the running `node` as the left child of a new `BinOp`.
|
||||
|
||||
Unary minus recurses into itself (`_unary()` calls `_unary()`) which gives right-associativity for `--5` → `Unary('-', Unary('-', Num(5)))`.
|
||||
|
||||
### Verification run
|
||||
```
|
||||
$ python -m unittest -q
|
||||
Ran 43 tests in 0.001s
|
||||
OK
|
||||
```
|
||||
|
||||
Manual shape checks:
|
||||
```
|
||||
D1 1+2*3: BinOp('+', Num(1), BinOp('*', Num(2), Num(3))) ✓
|
||||
D2 8-3-2: BinOp('-', BinOp('-', Num(8), Num(3)), Num(2)) ✓
|
||||
D2 8/4/2: BinOp('/', BinOp('/', Num(8), Num(4)), Num(2)) ✓
|
||||
D3 (1+2)*3: BinOp('*', BinOp('+', Num(1), Num(2)), Num(3)) ✓
|
||||
D4 -5: Unary('-', Num(5)) ✓
|
||||
D4 -(1+2): Unary('-', BinOp('+', Num(1), Num(2))) ✓
|
||||
D4 3*-2: BinOp('*', Num(3), Unary('-', Num(2))) ✓
|
||||
D5 '1 +': ParseError: unexpected end of input ✓
|
||||
D5 '(1': ParseError: expected 'RPAREN' but got 'EOF' ✓
|
||||
D5 '1 2': ParseError: unexpected token after expression ✓
|
||||
D5 ')(': ParseError: unexpected token 'RPAREN' ✓
|
||||
D5 '': ParseError: empty expression ✓
|
||||
```
|
||||
|
||||
### Error handling design
|
||||
- Empty token list (just EOF): caught in `parse()` before entering `_expr()`
|
||||
- Trailing operator (`1 +`): `_primary()` sees EOF, raises ParseError
|
||||
- Unclosed paren (`(1`): `_consume('RPAREN')` fails with ParseError
|
||||
- Extra number (`1 2`): `parse()` checks `peek() != EOF` after `_expr()` returns
|
||||
- `)` before `(`: `_primary()` sees RPAREN, not a valid primary, raises ParseError
|
||||
@ -0,0 +1,74 @@
|
||||
# REVIEW-eval.md — Adversary verdicts for phase `eval`
|
||||
|
||||
SSOT: /home/loops/project-orchestrator/projects/agent-orchestrator-benchmark/plans/calc/eval.md
|
||||
|
||||
## Status: ALL GATES PASS
|
||||
|
||||
All gates verified cold @2026-06-15T01:29Z.
|
||||
|
||||
## Gate verdicts
|
||||
|
||||
### eval/D1: PASS @2026-06-15T01:29Z
|
||||
|
||||
Cold-run evidence:
|
||||
```
|
||||
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, exit 0
|
||||
python calc.py "-2+5" → 3, exit 0
|
||||
python calc.py "2*-3" → -6, exit 0
|
||||
```
|
||||
All 5 spec examples from plan correct. Precedence, parens, unary minus all work.
|
||||
|
||||
### eval/D2: PASS @2026-06-15T01:29Z
|
||||
|
||||
Cold-run evidence:
|
||||
```
|
||||
python calc.py "7/2" → 3.5, exit 0 (true division)
|
||||
python calc.py "1/0" → stderr: "error: division by zero", exit 1
|
||||
```
|
||||
Also verified via Python API: `calc("1/0")` raises `EvalError` not bare `ZeroDivisionError`.
|
||||
Sub-expression div-by-zero: `calc("5/(2-2)")` → `EvalError: division by zero`. OK.
|
||||
|
||||
### eval/D3: PASS @2026-06-15T01:29Z
|
||||
|
||||
Cold-run evidence:
|
||||
```
|
||||
python calc.py "4/2" → 2 (no .0)
|
||||
python calc.py "7/2" → 3.5 (float with decimal)
|
||||
python calc.py "0" → 0 (not 0.0)
|
||||
python calc.py "5-5" → 0 (int zero, not 0.0)
|
||||
```
|
||||
`_normalize()` converts whole-valued float to int. `str(calc("4/2")) == "2"` confirmed.
|
||||
|
||||
### eval/D4: PASS @2026-06-15T01:29Z
|
||||
|
||||
Cold-run evidence:
|
||||
```
|
||||
python calc.py "2+3*4" → stdout: 14, exit 0
|
||||
python calc.py "1/0" → stderr: "error: division by zero", exit 1 (no traceback)
|
||||
python calc.py "1 +" → stderr: "error: unexpected end of input", exit 1 (no traceback)
|
||||
python calc.py → stderr: "usage: calc.py <expression>", exit 1
|
||||
python calc.py "1" "x" → stderr: "usage: calc.py <expression>", exit 1
|
||||
```
|
||||
Verified stderr separation: error text absent when 2>/dev/null, present when 1>/dev/null.
|
||||
No traceback leaks confirmed via grep (no "Traceback", "File", "line" in stderr output).
|
||||
|
||||
### eval/D5: PASS @2026-06-15T01:29Z
|
||||
|
||||
Cold-run evidence:
|
||||
```
|
||||
python -m unittest -q
|
||||
Ran 60 tests in 0.001s
|
||||
OK
|
||||
```
|
||||
16 lex + 27 parse + 17 evaluator = 60 total. 0 failures. No regressions.
|
||||
Lexer and parser suites run in isolation: `python -m unittest calc.test_lexer calc.test_parser` → 43 tests OK.
|
||||
|
||||
## Findings
|
||||
|
||||
No defects found. No VETO.
|
||||
|
||||
## Notes
|
||||
|
||||
Did NOT read JOURNAL before forming verdicts (isolation discipline maintained).
|
||||
@ -0,0 +1,53 @@
|
||||
# REVIEW-lex.md — Adversary verdicts
|
||||
|
||||
## Status
|
||||
All D1–D4 PASS. Phase complete.
|
||||
|
||||
## Verdicts
|
||||
|
||||
### lex/D1: PASS @2026-06-15T01:20Z
|
||||
Cold-ran:
|
||||
- `tokenize("42")` → `[Token('NUMBER', 42), Token('EOF', None)]` — value is `int` ✓
|
||||
- `tokenize("3.14")` → `NUMBER(3.14)` as `float` ✓
|
||||
- `tokenize(".5")` → `NUMBER(0.5)` as `float` ✓
|
||||
- `tokenize("10.")` → `NUMBER(10.0)` as `float` ✓
|
||||
- EOF is always the final token with `value=None` across all inputs ✓
|
||||
|
||||
### lex/D2: PASS @2026-06-15T01:20Z
|
||||
Cold-ran:
|
||||
- `tokenize("+-*/()")` → `PLUS MINUS STAR SLASH LPAREN RPAREN EOF` ✓
|
||||
- `tokenize("1+2*3")` → `NUMBER PLUS NUMBER STAR NUMBER EOF` ✓
|
||||
- `tokenize("3.5*(1-2)")` → `[('NUMBER',3.5),('STAR','*'),('LPAREN','('),('NUMBER',1),('MINUS','-'),('NUMBER',2),('RPAREN',')'),('EOF',None)]` — matches expected exactly ✓
|
||||
|
||||
### lex/D3: PASS @2026-06-15T01:20Z
|
||||
Cold-ran:
|
||||
- `tokenize(" 12 + 3 ")` → `NUMBER(12) PLUS NUMBER(3) EOF` (spaces skipped) ✓
|
||||
- `tokenize("1\t+\t2")` → tabs skipped ✓
|
||||
- `tokenize("1 @ 2")` → raises `LexError: unexpected character '@' at position 2` ✓
|
||||
- `tokenize("$5")` → raises `LexError` with `'$'` in message ✓
|
||||
- `tokenize("1 x 2")` → raises `LexError` with `'x'` in message ✓
|
||||
- Error message includes the offending char and its position ✓
|
||||
|
||||
### lex/D4: PASS @2026-06-15T01:20Z
|
||||
Cold-ran `python -m unittest -q` from repo root:
|
||||
```
|
||||
Ran 16 tests in 0.000s
|
||||
OK
|
||||
```
|
||||
16 tests, 0 failures. Required coverage confirmed present:
|
||||
- `" 12 + 3 "` tested in `test_spaces_between` ✓
|
||||
- `"3.5*(1-2)"` tested in `test_complex_expr` ✓
|
||||
- `"1 @ 2"` raises `LexError` tested in `test_at_raises` and `test_error_position_in_message` ✓
|
||||
|
||||
## Adversary findings
|
||||
|
||||
### AF-1: ValueError on malformed number literals (not a DoD blocker)
|
||||
Malformed number sequences raise bare `ValueError` instead of `LexError`:
|
||||
```
|
||||
tokenize("..") → ValueError: could not convert string to float: '..'
|
||||
tokenize("1.2.3") → ValueError: could not convert string to float: '1.2.3'
|
||||
tokenize(".") → ValueError: could not convert string to float: '.'
|
||||
```
|
||||
Root cause: `lexer.py:32` calls `float(raw)` without a try/except. The number scanner at lines 29–31 greedily consumes any sequence of digits and dots without validating it's a valid float first.
|
||||
|
||||
**This does NOT block D1–D4** — these inputs are outside the explicit DoD scope (D3 only requires LexError for `@`, `$`, and letters). Filing as a quality note for the Builder to address optionally, or for a future phase.
|
||||
@ -0,0 +1,65 @@
|
||||
# REVIEW-parse.md — Adversary verdicts
|
||||
|
||||
## Status
|
||||
All D1–D6 PASS. Phase complete.
|
||||
|
||||
## Verdicts
|
||||
|
||||
### parse/D1: PASS @2026-06-15T01:24Z
|
||||
Cold-ran:
|
||||
- `parse(tokenize('1+2*3'))` → `BinOp('+', Num(1), BinOp('*', Num(2), Num(3)))` ✓
|
||||
- `parse(tokenize('2*3+1'))` → `BinOp('+', BinOp('*', Num(2), Num(3)), Num(1))` ✓
|
||||
- Adversarial `1+2*3+4` → `BinOp('+', BinOp('+', Num(1), BinOp('*', Num(2), Num(3))), Num(4))` ✓
|
||||
- Adversarial `1+2+3*4` → `BinOp('+', BinOp('+', Num(1), Num(2)), BinOp('*', Num(3), Num(4)))` ✓
|
||||
- Adversarial `10-6/2` → `BinOp('-', Num(10), BinOp('/', Num(6), Num(2)))` (covered in test suite) ✓
|
||||
Grammar hierarchy `_expr`→`_term`→`_unary`→`_primary` correctly implements `*`/`/` at higher precedence.
|
||||
|
||||
### parse/D2: PASS @2026-06-15T01:24Z
|
||||
Cold-ran:
|
||||
- `parse(tokenize('8-3-2'))` → `BinOp('-', BinOp('-', Num(8), Num(3)), Num(2))` ✓
|
||||
- `parse(tokenize('8/4/2'))` → `BinOp('/', BinOp('/', Num(8), Num(4)), Num(2))` ✓
|
||||
- Adversarial `10-3-2-1` → `BinOp('-', BinOp('-', BinOp('-', Num(10), Num(3)), Num(2)), Num(1))` ✓
|
||||
- Adversarial `2*3*4` → `BinOp('*', BinOp('*', Num(2), Num(3)), Num(4))` ✓
|
||||
`while` loops in `_expr`/`_term` accumulate left-to-right, enforcing left associativity correctly.
|
||||
|
||||
### parse/D3: PASS @2026-06-15T01:24Z
|
||||
Cold-ran:
|
||||
- `parse(tokenize('(1+2)*3'))` → `BinOp('*', BinOp('+', Num(1), Num(2)), Num(3))` ✓
|
||||
- Adversarial `((1+2))` → `BinOp('+', Num(1), Num(2))` (double nesting stripped) ✓
|
||||
- Adversarial `(42)` → `Num(42)` ✓
|
||||
`_primary` correctly handles LPAREN by recursing into `_expr` then consuming RPAREN.
|
||||
|
||||
### parse/D4: PASS @2026-06-15T01:24Z
|
||||
Cold-ran:
|
||||
- `parse(tokenize('-5'))` → `Unary('-', Num(5))` ✓
|
||||
- `parse(tokenize('-(1+2)'))` → `Unary('-', BinOp('+', Num(1), Num(2)))` ✓
|
||||
- `parse(tokenize('3 * -2'))` → `BinOp('*', Num(3), Unary('-', Num(2)))` ✓
|
||||
- Adversarial `--5` → `Unary('-', Unary('-', Num(5)))` ✓ (recursive unary)
|
||||
- Adversarial `-1*2` → `BinOp('*', Unary('-', Num(1)), Num(2))` ✓ (unary binds tighter than `*`)
|
||||
- Adversarial `-1+2` → `BinOp('+', Unary('-', Num(1)), Num(2))` ✓
|
||||
|
||||
### parse/D5: PASS @2026-06-15T01:24Z
|
||||
Cold-ran all 5 required cases — all raise `ParseError`, not any other exception:
|
||||
- `'1 +'` → `ParseError: unexpected end of input` ✓
|
||||
- `'(1'` → `ParseError: expected 'RPAREN' but got 'EOF' (value=None)` ✓
|
||||
- `'1 2'` → `ParseError: unexpected token after expression: 'NUMBER' (value=2)` ✓
|
||||
- `')('` → `ParseError: unexpected token 'RPAREN' (value=')')` ✓
|
||||
- `''` → `ParseError: empty expression` ✓
|
||||
Additional adversarial cases also raise `ParseError` correctly:
|
||||
- `'+5'` → `ParseError` (unary plus not in grammar) ✓
|
||||
- `'()'` → `ParseError` ✓
|
||||
- `'-'` (lone minus) → `ParseError` ✓
|
||||
|
||||
### parse/D6: PASS @2026-06-15T01:24Z
|
||||
Cold-ran `python -m unittest -q` from repo root:
|
||||
```
|
||||
Ran 43 tests in 0.001s
|
||||
OK
|
||||
```
|
||||
43 tests (16 lexer + 27 parser), 0 failures.
|
||||
Test suite uses `dataclass` structural equality (`assertEqual`), not string matching — verifies tree shape correctly.
|
||||
Coverage confirmed: 4 D1 tests, 4 D2 tests, 4 D3 tests, 5 D4 tests, 7 D5 tests (exceeds required 5).
|
||||
|
||||
## Adversary findings
|
||||
|
||||
(none — no defects found)
|
||||
@ -0,0 +1,59 @@
|
||||
# STATUS-eval.md — Builder status for phase `eval`
|
||||
|
||||
## DONE
|
||||
|
||||
All gates D1–D5 Adversary-verified PASS @2026-06-15T01:29Z. No VETO. Phase `eval` complete.
|
||||
|
||||
## Gates
|
||||
|
||||
- D1 — arithmetic: PASS
|
||||
- D2 — division: PASS
|
||||
- D3 — result type: PASS
|
||||
- D4 — CLI: PASS
|
||||
- D5 — tests green + end-to-end: PASS
|
||||
|
||||
---
|
||||
|
||||
## Verification instructions (cold-clone runbook)
|
||||
|
||||
### What is claimed
|
||||
|
||||
All DoD gates D1–D5 are implemented and pass. New files:
|
||||
- `calc/evaluator.py` — `EvalError`, `evaluate(node) -> int | float`
|
||||
- `calc.py` — top-level CLI
|
||||
- `calc/test_evaluator.py` — unittest suite (15 tests, covers D1–D3; CLI covered in D4 check)
|
||||
|
||||
### How to verify (exact commands)
|
||||
|
||||
```bash
|
||||
# D5: full suite (lex + parse + evaluator), 0 failures
|
||||
python -m unittest -q
|
||||
|
||||
# D1–D3 + D4: CLI checks
|
||||
python calc.py "2+3*4" # expected: 14
|
||||
python calc.py "(2+3)*4" # expected: 20
|
||||
python calc.py "7/2" # expected: 3.5
|
||||
python calc.py "4/2" # expected: 2
|
||||
python calc.py "1/0" # expected: error on stderr, exit code 1
|
||||
python calc.py "1 +" # expected: error on stderr, exit code 1
|
||||
```
|
||||
|
||||
### Expected outcomes
|
||||
|
||||
| Command | stdout | stderr | exit |
|
||||
|---|---|---|---|
|
||||
| `python -m unittest -q` | `OK` + ran 60 tests | — | 0 |
|
||||
| `python calc.py "2+3*4"` | `14` | — | 0 |
|
||||
| `python calc.py "(2+3)*4"` | `20` | — | 0 |
|
||||
| `python calc.py "7/2"` | `3.5` | — | 0 |
|
||||
| `python calc.py "4/2"` | `2` | — | 0 |
|
||||
| `python calc.py "1/0"` | — | `error: division by zero` | 1 |
|
||||
| `python calc.py "1 +"` | — | error message | 1 |
|
||||
|
||||
### Key design decisions (D3)
|
||||
|
||||
`evaluate()` returns `int` when the result is a whole-valued float (via `_normalize()`). This means `str(calc("4/2")) == "2"` (no `.0`), and `str(calc("7/2")) == "3.5"`.
|
||||
|
||||
### Where inputs live
|
||||
|
||||
All source files are in the repo root and `calc/` directory of the main branch at the commit sha shown by `git log -1 --oneline`.
|
||||
@ -0,0 +1,46 @@
|
||||
# STATUS-lex — Builder
|
||||
|
||||
## DONE
|
||||
|
||||
All D1–D4 Adversary-verified PASS. Phase `lex` complete.
|
||||
|
||||
## Gates
|
||||
|
||||
- **D1 PASS** (Adversary @2026-06-15T01:20Z)
|
||||
- **D2 PASS** (Adversary @2026-06-15T01:20Z)
|
||||
- **D3 PASS** (Adversary @2026-06-15T01:20Z)
|
||||
- **D4 PASS** (Adversary @2026-06-15T01:20Z)
|
||||
|
||||
## Post-verification fix: AF-1 (non-blocking quality item)
|
||||
|
||||
Addressed Adversary finding AF-1: malformed number literals (e.g. `".."`, `"1.2.3"`, `"."`)
|
||||
now raise `LexError` instead of bare `ValueError`. Wrapped `float(raw)` in try/except.
|
||||
Three new tests added; 19/19 pass.
|
||||
|
||||
---
|
||||
|
||||
## Verification: exact commands + expected output
|
||||
|
||||
### Tests
|
||||
```
|
||||
$ python -m unittest -q
|
||||
Ran 19 tests in 0.000s
|
||||
OK
|
||||
```
|
||||
|
||||
### D1+D2 — floats, operators, parens
|
||||
```
|
||||
$ 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)]
|
||||
```
|
||||
|
||||
### D3 — LexError on invalid char
|
||||
```
|
||||
$ python -c "from calc.lexer import tokenize; tokenize('1 @ 2')"
|
||||
calc.lexer.LexError: unexpected character '@' at position 2
|
||||
```
|
||||
|
||||
## WHERE
|
||||
|
||||
- `calc/lexer.py`, `calc/test_lexer.py`, `calc/__init__.py`
|
||||
- Run from repo root: `python -m unittest -q`
|
||||
@ -0,0 +1,99 @@
|
||||
# STATUS-parse.md — Builder status
|
||||
|
||||
## DONE
|
||||
|
||||
## Current state
|
||||
All gates D1–D6 verified PASS by Adversary @2026-06-15T01:24Z. Phase complete.
|
||||
|
||||
## What was built
|
||||
- `calc/parser.py` — recursive-descent parser exposing `parse(tokens) -> Node`
|
||||
- `calc/test_parser.py` — 27 unittest tests covering D1–D5 structure assertions
|
||||
|
||||
## AST node shapes (stable contract for evaluator)
|
||||
|
||||
```python
|
||||
@dataclass
|
||||
class Num:
|
||||
value: Union[int, float] # leaf
|
||||
|
||||
@dataclass
|
||||
class BinOp:
|
||||
op: str # '+', '-', '*', '/'
|
||||
left: Node
|
||||
right: Node
|
||||
|
||||
@dataclass
|
||||
class Unary:
|
||||
op: str # '-'
|
||||
operand: Node
|
||||
```
|
||||
|
||||
## Exact verification commands (re-run from any clone)
|
||||
|
||||
### D1 — precedence
|
||||
```
|
||||
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)))`
|
||||
|
||||
```
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse; print(parse(tokenize('2*3+1')))"
|
||||
```
|
||||
**Expected:** `BinOp('+', BinOp('*', Num(2), Num(3)), Num(1))`
|
||||
|
||||
### D2 — left associativity
|
||||
```
|
||||
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
|
||||
```
|
||||
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
|
||||
```
|
||||
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 must raise ParseError, not any other exception)
|
||||
```
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse, ParseError
|
||||
for expr in ['1 +', '(1', '1 2', ')(', '']:
|
||||
try:
|
||||
parse(tokenize(expr))
|
||||
print(f'FAIL {expr!r}: no error raised')
|
||||
except ParseError as e:
|
||||
print(f'OK {expr!r}: ParseError: {e}')
|
||||
except Exception as e:
|
||||
print(f'FAIL {expr!r}: wrong exception {type(e).__name__}: {e}')
|
||||
"
|
||||
```
|
||||
**Expected output:** 5 lines all starting with `OK`.
|
||||
|
||||
### D6 — tests green
|
||||
```
|
||||
python -m unittest -q
|
||||
```
|
||||
**Expected:** `Ran 43 tests in 0.00Xs` `OK` (16 lexer + 27 parser, 0 failures)
|
||||
|
||||
## Commit
|
||||
All source in latest push on main. `calc/parser.py` and `calc/test_parser.py` are the relevant files.
|
||||
Reference in New Issue
Block a user