artifacts: add calculators/ — the 30 built calculators (5/variant) + machine-docs + git logs
This commit is contained in:
@ -0,0 +1,113 @@
|
||||
# STATUS-parse
|
||||
|
||||
## DONE
|
||||
|
||||
All gates D1–D6 verified PASS by Adversary at 2026-06-15T01:15Z (commit 79016f1).
|
||||
|
||||
## Gates
|
||||
- D1 — precedence: PASS (Adversary verified)
|
||||
- D2 — left associativity: PASS (Adversary verified)
|
||||
- D3 — parentheses: PASS (Adversary verified)
|
||||
- D4 — unary minus: PASS (Adversary verified)
|
||||
- D5 — errors: PASS (Adversary verified)
|
||||
- D6 — tests green: PASS (Adversary verified)
|
||||
|
||||
## Commit
|
||||
SHA: 88df238
|
||||
Files: calc/parser.py, calc/test_parser.py
|
||||
|
||||
## What is claimed (DoD items)
|
||||
|
||||
### AST node shapes
|
||||
All nodes use operator symbols (not token kind names):
|
||||
- `Num(value)` — numeric literal, value is int or float
|
||||
- `BinOp(op, left, right)` — binary op; op ∈ {'+', '-', '*', '/'}
|
||||
- `Unary(op, operand)` — unary op; op == '-'
|
||||
|
||||
### D1 — precedence
|
||||
`*` and `/` bind tighter than `+` and `-`.
|
||||
|
||||
```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)))
|
||||
|
||||
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))
|
||||
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse; print(parse(tokenize('10-4/2')))"
|
||||
# Expected: BinOp('-', Num(10), BinOp('/', Num(4), Num(2)))
|
||||
```
|
||||
|
||||
### D2 — left associativity
|
||||
Same-precedence operators associate left (left child is the deeper node).
|
||||
|
||||
```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
|
||||
Parens override default precedence.
|
||||
|
||||
```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))
|
||||
# Note: '+' node is DEEPER (left child) of '*' — opposite of D1's case
|
||||
```
|
||||
|
||||
### D4 — unary minus
|
||||
|
||||
```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 (all must raise ParseError, not any other exception)
|
||||
|
||||
```bash
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse, ParseError
|
||||
try: parse(tokenize('1 +'))
|
||||
except ParseError: print('PASS')
|
||||
except Exception as e: print('FAIL:', type(e).__name__, e)"
|
||||
# Expected: PASS
|
||||
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse, ParseError
|
||||
try: parse(tokenize('(1'))
|
||||
except ParseError: print('PASS')
|
||||
except Exception as e: print('FAIL:', type(e).__name__, e)"
|
||||
# Expected: PASS
|
||||
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse, ParseError
|
||||
try: parse(tokenize('1 2'))
|
||||
except ParseError: print('PASS')
|
||||
except Exception as e: print('FAIL:', type(e).__name__, e)"
|
||||
# Expected: PASS
|
||||
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse, ParseError
|
||||
try: parse(tokenize(')('))
|
||||
except ParseError: print('PASS')
|
||||
except Exception as e: print('FAIL:', type(e).__name__, e)"
|
||||
# Expected: PASS
|
||||
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse, ParseError
|
||||
try: parse(tokenize(''))
|
||||
except ParseError: print('PASS')
|
||||
except Exception as e: print('FAIL:', type(e).__name__, e)"
|
||||
# Expected: PASS
|
||||
```
|
||||
|
||||
### D6 — tests green
|
||||
|
||||
```bash
|
||||
python -m unittest -q
|
||||
# Expected: Ran 44 tests in ...s\n\nOK (18 lexer + 26 parser)
|
||||
```
|
||||
Reference in New Issue
Block a user