artifacts: add calculators/ — the 30 built calculators (5/variant) + machine-docs + git logs
This commit is contained in:
@ -0,0 +1,127 @@
|
||||
# STATUS — phase parse
|
||||
|
||||
## Role
|
||||
Builder
|
||||
|
||||
## DONE
|
||||
|
||||
All DoD gates verified PASS by Adversary at 2026-06-15T05:59:19Z.
|
||||
|
||||
## Gates
|
||||
- D1: PASS (Adversary verified 2026-06-15T05:59:19Z)
|
||||
- D2: PASS (Adversary verified 2026-06-15T05:59:19Z)
|
||||
- D3: PASS (Adversary verified 2026-06-15T05:59:19Z)
|
||||
- D4: PASS (Adversary verified 2026-06-15T05:59:19Z)
|
||||
- D5: PASS (Adversary verified 2026-06-15T05:59:19Z)
|
||||
- D6: PASS (Adversary verified 2026-06-15T05:59:19Z)
|
||||
|
||||
## AST Shape (for Adversary reference)
|
||||
|
||||
Nodes (from `calc/parser.py`):
|
||||
- `Num(value)` — a number literal
|
||||
- `BinOp(op, left, right)` — binary operation; op in {'+', '-', '*', '/'}
|
||||
- `Unary(op, operand)` — unary minus; op == '-'
|
||||
- `ParseError` — raised on malformed input
|
||||
|
||||
## Gates
|
||||
|
||||
### D1 — Precedence CLAIMED, awaiting Adversary
|
||||
|
||||
**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'))))"
|
||||
```
|
||||
|
||||
**EXPECTED:**
|
||||
```
|
||||
BinOp('+', Num(1), BinOp('*', Num(2), Num(3)))
|
||||
```
|
||||
|
||||
### D2 — Left Associativity CLAIMED, awaiting Adversary
|
||||
|
||||
**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 CLAIMED, awaiting Adversary
|
||||
|
||||
**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 CLAIMED, awaiting Adversary
|
||||
|
||||
**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 CLAIMED, awaiting Adversary
|
||||
|
||||
**WHAT:** Malformed input raises `ParseError`, not any other exception.
|
||||
|
||||
**HOW:**
|
||||
```bash
|
||||
python -c "
|
||||
from calc.lexer import tokenize
|
||||
from calc.parser import parse, ParseError
|
||||
cases = ['1 +', '(1', '1 2', ')(' , '']
|
||||
for src in cases:
|
||||
try:
|
||||
parse(tokenize(src))
|
||||
print(f'NO ERROR for {src!r} — BUG')
|
||||
except ParseError as e:
|
||||
print(f'OK ParseError for {src!r}')
|
||||
except Exception as e:
|
||||
print(f'WRONG exception {type(e).__name__} for {src!r}')
|
||||
"
|
||||
```
|
||||
|
||||
**EXPECTED:** Each case prints `OK ParseError for ...`
|
||||
|
||||
### D6 — Tests Green CLAIMED, awaiting Adversary
|
||||
|
||||
**WHAT:** `calc/test_parser.py` passes under `python -m unittest`, 0 failures.
|
||||
|
||||
**HOW:**
|
||||
```bash
|
||||
python -m unittest -q
|
||||
```
|
||||
|
||||
**EXPECTED:**
|
||||
```
|
||||
Ran 31 tests in <time>
|
||||
|
||||
OK
|
||||
```
|
||||
Reference in New Issue
Block a user