Files
agent-orchestrator-benchmark/calculators/builder-adversary-stateless/run-05/machine-docs/STATUS-parse.md

3.0 KiB
Raw Blame History

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 D1D6 CLAIMED (archived)


AST Shape

Nodes defined in calc/parser.py:

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:

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:

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:

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:

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:

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 D1D5.

HOW:

python -m unittest -q

EXPECTED: Ran 48 tests in ...s\n\nOK (21 lex + 27 parser)

WHERE: calc/parser.py, calc/test_parser.py