artifacts: add calculators/ — the 30 built calculators (5/variant) + machine-docs + git logs
This commit is contained in:
@ -0,0 +1,33 @@
|
||||
# JOURNAL — Phase parse
|
||||
|
||||
## 2026-06-15 — Implementation
|
||||
|
||||
Built `calc/parser.py` using a classic recursive-descent approach with three precedence levels:
|
||||
|
||||
1. `_expr` handles `+`/`-` (lowest precedence, left-assoc via loop)
|
||||
2. `_term` handles `*`/`/` (medium precedence, left-assoc via loop)
|
||||
3. `_unary` handles leading `-` (right-assoc via recursion)
|
||||
4. `_primary` handles numbers and parenthesized expressions
|
||||
|
||||
Left-associativity falls out naturally from the `while` loops in `_expr` and `_term` — each iteration wraps the accumulated `node` as the left child of a new `BinOp`, building a left-leaning tree.
|
||||
|
||||
Test verification output:
|
||||
```
|
||||
D1: BinOp(op='+', left=Num(value=1), right=BinOp(op='*', left=Num(value=2), right=Num(value=3)))
|
||||
D2: BinOp(op='-', left=BinOp(op='-', left=Num(value=8), right=Num(value=3)), right=Num(value=2))
|
||||
D3: BinOp(op='*', left=BinOp(op='+', left=Num(value=1), right=Num(value=2)), right=Num(value=3))
|
||||
D4a: Unary(op='-', operand=Num(value=5))
|
||||
D4b: Unary(op='-', operand=BinOp(op='+', left=Num(value=1), right=Num(value=2)))
|
||||
D4c: BinOp(op='*', left=Num(value=3), right=Unary(op='-', operand=Num(value=2)))
|
||||
|
||||
D5 errors:
|
||||
OK ParseError for '1 +': unexpected token 'EOF' (None)
|
||||
OK ParseError for '(1': unclosed parenthesis, got 'EOF'
|
||||
OK ParseError for '1 2': unexpected token 'NUMBER' (2)
|
||||
OK ParseError for ')(': unexpected token 'RPAREN' (')')
|
||||
OK ParseError for '': empty input
|
||||
|
||||
D6: Ran 37 tests in 0.001s OK
|
||||
```
|
||||
|
||||
All 6 gates claimed and pushed. Awaiting Adversary verification.
|
||||
Reference in New Issue
Block a user