artifacts: add calculators/ — the 30 built calculators (5/variant) + machine-docs + git logs
This commit is contained in:
@ -0,0 +1,126 @@
|
||||
# STATUS-parse.md
|
||||
|
||||
## DONE
|
||||
|
||||
All DoD gates Adversary-verified PASS. Phase `parse` complete.
|
||||
|
||||
- D1: PASS @2026-06-15T04:41:47Z
|
||||
- D2: PASS @2026-06-15T04:41:47Z
|
||||
- D3: PASS @2026-06-15T04:41:47Z
|
||||
- D4: PASS @2026-06-15T04:41:47Z
|
||||
- D5: PASS @2026-06-15T04:41:47Z
|
||||
- D6: PASS @2026-06-15T04:41:47Z
|
||||
|
||||
---
|
||||
|
||||
## Gate D1–D6 CLAIMED (archived)
|
||||
|
||||
---
|
||||
|
||||
## AST Shape
|
||||
|
||||
Nodes defined in `calc/parser.py`:
|
||||
|
||||
```python
|
||||
Num(value) # numeric leaf; value is int or float
|
||||
BinOp(op, left, right) # binary: op in {'+','-','*','/'}; left/right are nodes
|
||||
Unary(op, operand) # unary: op == '-'; operand is a node
|
||||
```
|
||||
|
||||
All nodes implement `__repr__` and `__eq__`.
|
||||
|
||||
---
|
||||
|
||||
## D1 — Precedence
|
||||
|
||||
**WHAT:** `*` and `/` bind tighter than `+` and `-`.
|
||||
|
||||
**HOW:**
|
||||
```bash
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse; print(repr(parse(tokenize('1+2*3'))))"
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse; print(repr(parse(tokenize('2*3+4'))))"
|
||||
```
|
||||
|
||||
**EXPECTED:**
|
||||
- `BinOp('+', Num(1), BinOp('*', Num(2), Num(3)))`
|
||||
- `BinOp('+', BinOp('*', Num(2), Num(3)), Num(4))`
|
||||
|
||||
---
|
||||
|
||||
## D2 — Left Associativity
|
||||
|
||||
**WHAT:** Same-precedence operators associate left.
|
||||
|
||||
**HOW:**
|
||||
```bash
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse; print(repr(parse(tokenize('8-3-2'))))"
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse; print(repr(parse(tokenize('8/4/2'))))"
|
||||
```
|
||||
|
||||
**EXPECTED:**
|
||||
- `BinOp('-', BinOp('-', Num(8), Num(3)), Num(2))`
|
||||
- `BinOp('/', BinOp('/', Num(8), Num(4)), Num(2))`
|
||||
|
||||
---
|
||||
|
||||
## D3 — Parentheses
|
||||
|
||||
**WHAT:** Parens override precedence.
|
||||
|
||||
**HOW:**
|
||||
```bash
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse; print(repr(parse(tokenize('(1+2)*3'))))"
|
||||
```
|
||||
|
||||
**EXPECTED:**
|
||||
- `BinOp('*', BinOp('+', Num(1), Num(2)), Num(3))`
|
||||
|
||||
---
|
||||
|
||||
## D4 — Unary Minus
|
||||
|
||||
**WHAT:** Leading and nested unary minus parses correctly.
|
||||
|
||||
**HOW:**
|
||||
```bash
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse; print(repr(parse(tokenize('-5'))))"
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse; print(repr(parse(tokenize('-(1+2)'))))"
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse; print(repr(parse(tokenize('3 * -2'))))"
|
||||
```
|
||||
|
||||
**EXPECTED:**
|
||||
- `Unary('-', Num(5))`
|
||||
- `Unary('-', BinOp('+', Num(1), Num(2)))`
|
||||
- `BinOp('*', Num(3), Unary('-', Num(2)))`
|
||||
|
||||
---
|
||||
|
||||
## D5 — Errors
|
||||
|
||||
**WHAT:** Malformed input raises `ParseError`.
|
||||
|
||||
**HOW:**
|
||||
```bash
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse, ParseError
|
||||
for s in ['1 +','(1','1 2',')(','']:
|
||||
try: parse(tokenize(s)); print('NO ERROR for', repr(s))
|
||||
except ParseError as e: print('OK ParseError:', repr(s), '->', e)
|
||||
"
|
||||
```
|
||||
|
||||
**EXPECTED:** All five raise `ParseError` (not any other exception type).
|
||||
|
||||
---
|
||||
|
||||
## D6 — Tests Green
|
||||
|
||||
**WHAT:** `python -m unittest -q` passes with 0 failures; covers D1–D5.
|
||||
|
||||
**HOW:**
|
||||
```bash
|
||||
python -m unittest -q
|
||||
```
|
||||
|
||||
**EXPECTED:** `Ran 48 tests in ...s\n\nOK` (21 lex + 27 parser)
|
||||
|
||||
**WHERE:** `calc/parser.py`, `calc/test_parser.py`
|
||||
Reference in New Issue
Block a user