artifacts: add calculators/ — the 30 built calculators (5/variant) + machine-docs + git logs
This commit is contained in:
3
calculators/builder-adversary-deferred/run-01/.gitignore
vendored
Normal file
3
calculators/builder-adversary-deferred/run-01/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
__pycache__/
|
||||
*.pyc
|
||||
*.pyo
|
||||
11
calculators/builder-adversary-deferred/run-01/GIT-LOG.txt
Normal file
11
calculators/builder-adversary-deferred/run-01/GIT-LOG.txt
Normal file
@ -0,0 +1,11 @@
|
||||
# git history (claim/review handshake), from the run's shared bare repo
|
||||
4b7f792 status(review): ## DONE — all gates Adversary-verified PASS
|
||||
6513925 review(all): PASS — comprehensive cold-verification of all DoD gates
|
||||
bfd5972 claim(review/D1-D3): initialize review phase — full build ready for Adversary cold-verify
|
||||
1cfe13c status(eval): ## DONE — all gates Adversary-verified PASS
|
||||
8ba43a5 review(eval/D1-D5): PASS — comprehensive cold-verification of all DoD gates
|
||||
21be8f5 claim(eval): implement evaluator, CLI, and tests — all DoD gates verified
|
||||
7984a31 review(init-eval): Adversary initialized tracking files for eval phase
|
||||
758567a review(init-parse): Adversary initialized tracking files for parse phase
|
||||
6b5c947 review(init): Adversary initialized tracking files for lex phase
|
||||
61f1ba0 chore: seed
|
||||
1
calculators/builder-adversary-deferred/run-01/README.md
Normal file
1
calculators/builder-adversary-deferred/run-01/README.md
Normal file
@ -0,0 +1 @@
|
||||
# calc work repo
|
||||
1
calculators/builder-adversary-deferred/run-01/SOURCE.txt
Normal file
1
calculators/builder-adversary-deferred/run-01/SOURCE.txt
Normal file
@ -0,0 +1 @@
|
||||
original path: /tmp/ao-campaign-WXwoUv/builder-adversary-deferred/r1
|
||||
23
calculators/builder-adversary-deferred/run-01/calc.py
Normal file
23
calculators/builder-adversary-deferred/run-01/calc.py
Normal file
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Calculator CLI: evaluate an arithmetic expression from the command line."""
|
||||
import sys
|
||||
from calc.lexer import tokenize, LexError
|
||||
from calc.parser import parse, ParseError
|
||||
from calc.evaluator import evaluate, EvalError, fmt_result
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 2:
|
||||
print(f"usage: {sys.argv[0]} <expression>", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
expr = sys.argv[1]
|
||||
try:
|
||||
result = evaluate(parse(tokenize(expr)))
|
||||
print(fmt_result(result))
|
||||
except (LexError, ParseError, EvalError) as e:
|
||||
print(f"error: {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@ -0,0 +1,43 @@
|
||||
from __future__ import annotations
|
||||
from calc.parser import Num, BinOp, Unary, Node
|
||||
|
||||
|
||||
class EvalError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def evaluate(node: Node) -> int | float:
|
||||
"""Walk the AST and return the numeric result."""
|
||||
if isinstance(node, Num):
|
||||
return node.value
|
||||
if isinstance(node, Unary):
|
||||
val = evaluate(node.operand)
|
||||
if node.op == '-':
|
||||
return -val
|
||||
raise EvalError(f"unknown unary operator: {node.op!r}")
|
||||
if isinstance(node, BinOp):
|
||||
left = evaluate(node.left)
|
||||
right = evaluate(node.right)
|
||||
if node.op == '+':
|
||||
return left + right
|
||||
if node.op == '-':
|
||||
return left - right
|
||||
if node.op == '*':
|
||||
return left * right
|
||||
if node.op == '/':
|
||||
if right == 0:
|
||||
raise EvalError("division by zero")
|
||||
return left / right
|
||||
raise EvalError(f"unknown binary operator: {node.op!r}")
|
||||
raise EvalError(f"unknown node type: {type(node)!r}")
|
||||
|
||||
|
||||
def fmt_result(v: int | float) -> str:
|
||||
"""Format a result for display.
|
||||
|
||||
Rule: whole-valued floats (e.g. 2.0 from 4/2) print without a trailing .0;
|
||||
non-whole floats print normally; integers print as integers.
|
||||
"""
|
||||
if isinstance(v, float) and v.is_integer():
|
||||
return str(int(v))
|
||||
return str(v)
|
||||
62
calculators/builder-adversary-deferred/run-01/calc/lexer.py
Normal file
62
calculators/builder-adversary-deferred/run-01/calc/lexer.py
Normal file
@ -0,0 +1,62 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import Union
|
||||
|
||||
|
||||
class LexError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass
|
||||
class Token:
|
||||
kind: str
|
||||
value: Union[int, float, str, None]
|
||||
|
||||
|
||||
def tokenize(src: str) -> list:
|
||||
tokens = []
|
||||
i = 0
|
||||
while i < len(src):
|
||||
ch = src[i]
|
||||
|
||||
if ch in ' \t':
|
||||
i += 1
|
||||
continue
|
||||
|
||||
if ch.isdigit() or (ch == '.' and i + 1 < len(src) and src[i + 1].isdigit()):
|
||||
j = i
|
||||
while j < len(src) and src[j].isdigit():
|
||||
j += 1
|
||||
if j < len(src) and src[j] == '.':
|
||||
j += 1
|
||||
while j < len(src) and src[j].isdigit():
|
||||
j += 1
|
||||
value = float(src[i:j])
|
||||
else:
|
||||
value = int(src[i:j])
|
||||
tokens.append(Token('NUMBER', value))
|
||||
i = j
|
||||
continue
|
||||
|
||||
if ch == '+':
|
||||
tokens.append(Token('PLUS', '+'))
|
||||
i += 1
|
||||
elif ch == '-':
|
||||
tokens.append(Token('MINUS', '-'))
|
||||
i += 1
|
||||
elif ch == '*':
|
||||
tokens.append(Token('STAR', '*'))
|
||||
i += 1
|
||||
elif ch == '/':
|
||||
tokens.append(Token('SLASH', '/'))
|
||||
i += 1
|
||||
elif ch == '(':
|
||||
tokens.append(Token('LPAREN', '('))
|
||||
i += 1
|
||||
elif ch == ')':
|
||||
tokens.append(Token('RPAREN', ')'))
|
||||
i += 1
|
||||
else:
|
||||
raise LexError(f"unexpected character {ch!r} at position {i}")
|
||||
|
||||
tokens.append(Token('EOF', None))
|
||||
return tokens
|
||||
107
calculators/builder-adversary-deferred/run-01/calc/parser.py
Normal file
107
calculators/builder-adversary-deferred/run-01/calc/parser.py
Normal file
@ -0,0 +1,107 @@
|
||||
from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
from typing import Union
|
||||
|
||||
|
||||
class ParseError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass
|
||||
class Num:
|
||||
value: Union[int, float]
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"Num({self.value!r})"
|
||||
|
||||
|
||||
@dataclass
|
||||
class BinOp:
|
||||
op: str
|
||||
left: "Node"
|
||||
right: "Node"
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"BinOp({self.op!r}, {self.left!r}, {self.right!r})"
|
||||
|
||||
|
||||
@dataclass
|
||||
class Unary:
|
||||
op: str
|
||||
operand: "Node"
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"Unary({self.op!r}, {self.operand!r})"
|
||||
|
||||
|
||||
Node = Union[Num, BinOp, Unary]
|
||||
|
||||
|
||||
class _Parser:
|
||||
def __init__(self, tokens: list) -> None:
|
||||
self._tokens = tokens
|
||||
self._pos = 0
|
||||
|
||||
def _peek(self):
|
||||
return self._tokens[self._pos]
|
||||
|
||||
def _consume(self, kind: str = None):
|
||||
tok = self._tokens[self._pos]
|
||||
if kind is not None and tok.kind != kind:
|
||||
raise ParseError(
|
||||
f"expected {kind}, got {tok.kind!r} ({tok.value!r})"
|
||||
)
|
||||
self._pos += 1
|
||||
return tok
|
||||
|
||||
def parse(self) -> Node:
|
||||
if self._peek().kind == "EOF":
|
||||
raise ParseError("empty input")
|
||||
node = self._expr()
|
||||
if self._peek().kind != "EOF":
|
||||
tok = self._peek()
|
||||
raise ParseError(
|
||||
f"unexpected token {tok.kind!r} ({tok.value!r}) after expression"
|
||||
)
|
||||
return node
|
||||
|
||||
def _expr(self) -> Node:
|
||||
node = self._term()
|
||||
while self._peek().kind in ("PLUS", "MINUS"):
|
||||
op = self._consume().value
|
||||
node = BinOp(op, node, self._term())
|
||||
return node
|
||||
|
||||
def _term(self) -> Node:
|
||||
node = self._unary()
|
||||
while self._peek().kind in ("STAR", "SLASH"):
|
||||
op = self._consume().value
|
||||
node = BinOp(op, node, self._unary())
|
||||
return node
|
||||
|
||||
def _unary(self) -> Node:
|
||||
if self._peek().kind == "MINUS":
|
||||
self._consume()
|
||||
return Unary("-", self._unary())
|
||||
return self._primary()
|
||||
|
||||
def _primary(self) -> Node:
|
||||
tok = self._peek()
|
||||
if tok.kind == "NUMBER":
|
||||
self._consume()
|
||||
return Num(tok.value)
|
||||
if tok.kind == "LPAREN":
|
||||
self._consume()
|
||||
node = self._expr()
|
||||
if self._peek().kind != "RPAREN":
|
||||
raise ParseError("unclosed parenthesis")
|
||||
self._consume()
|
||||
return node
|
||||
raise ParseError(
|
||||
f"unexpected token {tok.kind!r} ({tok.value!r})"
|
||||
)
|
||||
|
||||
|
||||
def parse(tokens: list) -> Node:
|
||||
"""Parse a token list produced by calc.lexer.tokenize into an AST."""
|
||||
return _Parser(tokens).parse()
|
||||
@ -0,0 +1,95 @@
|
||||
import unittest
|
||||
from calc.lexer import tokenize
|
||||
from calc.parser import parse
|
||||
from calc.evaluator import evaluate, EvalError, fmt_result
|
||||
|
||||
|
||||
def ev(src: str):
|
||||
return evaluate(parse(tokenize(src)))
|
||||
|
||||
|
||||
class TestArithmetic(unittest.TestCase):
|
||||
"""D1 — basic arithmetic, precedence, parens, unary minus"""
|
||||
|
||||
def test_precedence(self):
|
||||
self.assertEqual(ev("2+3*4"), 14)
|
||||
|
||||
def test_parens(self):
|
||||
self.assertEqual(ev("(2+3)*4"), 20)
|
||||
|
||||
def test_left_assoc_sub(self):
|
||||
self.assertEqual(ev("8-3-2"), 3)
|
||||
|
||||
def test_unary_minus_leading(self):
|
||||
self.assertEqual(ev("-2+5"), 3)
|
||||
|
||||
def test_unary_minus_mul(self):
|
||||
self.assertEqual(ev("2*-3"), -6)
|
||||
|
||||
|
||||
class TestDivision(unittest.TestCase):
|
||||
"""D2 — true division and division by zero"""
|
||||
|
||||
def test_true_division(self):
|
||||
self.assertAlmostEqual(ev("7/2"), 3.5)
|
||||
|
||||
def test_division_by_zero_raises_eval_error(self):
|
||||
with self.assertRaises(EvalError):
|
||||
ev("1/0")
|
||||
|
||||
def test_division_by_zero_no_bare_exception(self):
|
||||
"""ZeroDivisionError must not escape the evaluator API."""
|
||||
try:
|
||||
ev("1/0")
|
||||
except EvalError:
|
||||
pass
|
||||
except ZeroDivisionError:
|
||||
self.fail("ZeroDivisionError escaped the evaluator API")
|
||||
|
||||
|
||||
class TestResultType(unittest.TestCase):
|
||||
"""D3 — whole-valued floats display as int, non-whole as float"""
|
||||
|
||||
def test_whole_division_value(self):
|
||||
# 4/2 = 2.0 in Python; must equal 2
|
||||
self.assertEqual(ev("4/2"), 2)
|
||||
|
||||
def test_non_whole_division_value(self):
|
||||
self.assertAlmostEqual(ev("7/2"), 3.5)
|
||||
|
||||
def test_int_arithmetic_returns_int(self):
|
||||
self.assertIsInstance(ev("2+3"), int)
|
||||
self.assertIsInstance(ev("2*3"), int)
|
||||
self.assertIsInstance(ev("8-3"), int)
|
||||
|
||||
def test_fmt_whole_float(self):
|
||||
self.assertEqual(fmt_result(2.0), "2")
|
||||
|
||||
def test_fmt_non_whole_float(self):
|
||||
self.assertEqual(fmt_result(3.5), "3.5")
|
||||
|
||||
def test_fmt_int(self):
|
||||
self.assertEqual(fmt_result(14), "14")
|
||||
|
||||
def test_fmt_negative(self):
|
||||
self.assertEqual(fmt_result(-6), "-6")
|
||||
|
||||
|
||||
class TestMisc(unittest.TestCase):
|
||||
"""Additional coverage"""
|
||||
|
||||
def test_neg_times_neg(self):
|
||||
self.assertEqual(ev("-2*-3"), 6)
|
||||
|
||||
def test_complex_expr(self):
|
||||
self.assertEqual(ev("(1+2)*(3+4)"), 21)
|
||||
|
||||
def test_unary_in_paren(self):
|
||||
self.assertEqual(ev("-(3)"), -3)
|
||||
|
||||
def test_double_unary(self):
|
||||
self.assertEqual(ev("--5"), 5)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
118
calculators/builder-adversary-deferred/run-01/calc/test_lexer.py
Normal file
118
calculators/builder-adversary-deferred/run-01/calc/test_lexer.py
Normal file
@ -0,0 +1,118 @@
|
||||
import unittest
|
||||
from calc.lexer import tokenize, Token, LexError
|
||||
|
||||
|
||||
def kinds(src):
|
||||
return [t.kind for t in tokenize(src)]
|
||||
|
||||
|
||||
def tok(src):
|
||||
return [(t.kind, t.value) for t in tokenize(src)]
|
||||
|
||||
|
||||
class TestNumbers(unittest.TestCase):
|
||||
def test_integer(self):
|
||||
tokens = tokenize("42")
|
||||
self.assertEqual(len(tokens), 2)
|
||||
self.assertEqual(tokens[0], Token('NUMBER', 42))
|
||||
self.assertEqual(tokens[1], Token('EOF', None))
|
||||
self.assertIsInstance(tokens[0].value, int)
|
||||
|
||||
def test_float_standard(self):
|
||||
tokens = tokenize("3.14")
|
||||
self.assertEqual(tokens[0], Token('NUMBER', 3.14))
|
||||
self.assertIsInstance(tokens[0].value, float)
|
||||
|
||||
def test_float_leading_dot(self):
|
||||
tokens = tokenize(".5")
|
||||
self.assertEqual(tokens[0], Token('NUMBER', 0.5))
|
||||
self.assertIsInstance(tokens[0].value, float)
|
||||
|
||||
def test_float_trailing_dot(self):
|
||||
tokens = tokenize("10.")
|
||||
self.assertEqual(tokens[0], Token('NUMBER', 10.0))
|
||||
self.assertIsInstance(tokens[0].value, float)
|
||||
|
||||
def test_zero(self):
|
||||
tokens = tokenize("0")
|
||||
self.assertEqual(tokens[0], Token('NUMBER', 0))
|
||||
|
||||
|
||||
class TestOperatorsAndParens(unittest.TestCase):
|
||||
def test_plus(self):
|
||||
self.assertIn(Token('PLUS', '+'), tokenize("+"))
|
||||
|
||||
def test_minus(self):
|
||||
self.assertIn(Token('MINUS', '-'), tokenize("-"))
|
||||
|
||||
def test_star(self):
|
||||
self.assertIn(Token('STAR', '*'), tokenize("*"))
|
||||
|
||||
def test_slash(self):
|
||||
self.assertIn(Token('SLASH', '/'), tokenize("/"))
|
||||
|
||||
def test_lparen(self):
|
||||
self.assertIn(Token('LPAREN', '('), tokenize("("))
|
||||
|
||||
def test_rparen(self):
|
||||
self.assertIn(Token('RPAREN', ')'), tokenize(")"))
|
||||
|
||||
def test_expression(self):
|
||||
self.assertEqual(
|
||||
kinds("1+2*3"),
|
||||
['NUMBER', 'PLUS', 'NUMBER', 'STAR', 'NUMBER', 'EOF']
|
||||
)
|
||||
|
||||
def test_complex_expression(self):
|
||||
self.assertEqual(
|
||||
kinds("3.5*(1-2)"),
|
||||
['NUMBER', 'STAR', 'LPAREN', 'NUMBER', 'MINUS', 'NUMBER', 'RPAREN', 'EOF']
|
||||
)
|
||||
|
||||
|
||||
class TestWhitespaceAndErrors(unittest.TestCase):
|
||||
def test_whitespace_skipped(self):
|
||||
self.assertEqual(
|
||||
kinds(" 12 + 3 "),
|
||||
['NUMBER', 'PLUS', 'NUMBER', 'EOF']
|
||||
)
|
||||
t = tokenize(" 12 + 3 ")
|
||||
self.assertEqual(t[0].value, 12)
|
||||
self.assertEqual(t[1].kind, 'PLUS')
|
||||
self.assertEqual(t[2].value, 3)
|
||||
|
||||
def test_tab_skipped(self):
|
||||
self.assertEqual(kinds("1\t+\t2"), ['NUMBER', 'PLUS', 'NUMBER', 'EOF'])
|
||||
|
||||
def test_at_raises_lexerror(self):
|
||||
with self.assertRaises(LexError):
|
||||
tokenize("1 @ 2")
|
||||
|
||||
def test_dollar_raises_lexerror(self):
|
||||
with self.assertRaises(LexError):
|
||||
tokenize("$")
|
||||
|
||||
def test_letter_raises_lexerror(self):
|
||||
with self.assertRaises(LexError):
|
||||
tokenize("x")
|
||||
|
||||
def test_lexerror_message_has_char_and_pos(self):
|
||||
try:
|
||||
tokenize("1 @ 2")
|
||||
self.fail("Expected LexError")
|
||||
except LexError as e:
|
||||
msg = str(e)
|
||||
self.assertIn('@', msg)
|
||||
self.assertIn('2', msg) # position 2
|
||||
|
||||
def test_eof_always_last(self):
|
||||
tokens = tokenize("1+2")
|
||||
self.assertEqual(tokens[-1].kind, 'EOF')
|
||||
|
||||
def test_empty_string(self):
|
||||
tokens = tokenize("")
|
||||
self.assertEqual(tokens, [Token('EOF', None)])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@ -0,0 +1,142 @@
|
||||
import unittest
|
||||
from calc.lexer import tokenize
|
||||
from calc.parser import parse, ParseError, Num, BinOp, Unary
|
||||
|
||||
|
||||
def p(src: str):
|
||||
return parse(tokenize(src))
|
||||
|
||||
|
||||
class TestPrecedence(unittest.TestCase):
|
||||
"""D1 — * and / bind tighter than + and -"""
|
||||
|
||||
def test_add_mul(self):
|
||||
# 1+2*3 → BinOp('+', Num(1), BinOp('*', Num(2), Num(3)))
|
||||
tree = p("1+2*3")
|
||||
self.assertEqual(tree, BinOp("+", Num(1), BinOp("*", Num(2), Num(3))))
|
||||
|
||||
def test_mul_add(self):
|
||||
# 2*3+1 → BinOp('+', BinOp('*', Num(2), Num(3)), Num(1))
|
||||
tree = p("2*3+1")
|
||||
self.assertEqual(tree, BinOp("+", BinOp("*", Num(2), Num(3)), Num(1)))
|
||||
|
||||
def test_sub_div(self):
|
||||
# 6-4/2 → BinOp('-', Num(6), BinOp('/', Num(4), Num(2)))
|
||||
tree = p("6-4/2")
|
||||
self.assertEqual(tree, BinOp("-", Num(6), BinOp("/", Num(4), Num(2))))
|
||||
|
||||
|
||||
class TestLeftAssociativity(unittest.TestCase):
|
||||
"""D2 — same-precedence operators associate left"""
|
||||
|
||||
def test_subtraction(self):
|
||||
# 8-3-2 → BinOp('-', BinOp('-', Num(8), Num(3)), Num(2))
|
||||
tree = p("8-3-2")
|
||||
self.assertEqual(tree, BinOp("-", BinOp("-", Num(8), Num(3)), Num(2)))
|
||||
|
||||
def test_division(self):
|
||||
# 8/4/2 → BinOp('/', BinOp('/', Num(8), Num(4)), Num(2))
|
||||
tree = p("8/4/2")
|
||||
self.assertEqual(tree, BinOp("/", BinOp("/", Num(8), Num(4)), Num(2)))
|
||||
|
||||
def test_addition(self):
|
||||
# 1+2+3 → BinOp('+', BinOp('+', Num(1), Num(2)), Num(3))
|
||||
tree = p("1+2+3")
|
||||
self.assertEqual(tree, BinOp("+", BinOp("+", Num(1), Num(2)), Num(3)))
|
||||
|
||||
def test_multiplication(self):
|
||||
# 2*3*4 → BinOp('*', BinOp('*', Num(2), Num(3)), Num(4))
|
||||
tree = p("2*3*4")
|
||||
self.assertEqual(tree, BinOp("*", BinOp("*", Num(2), Num(3)), Num(4)))
|
||||
|
||||
|
||||
class TestParentheses(unittest.TestCase):
|
||||
"""D3 — parens override precedence"""
|
||||
|
||||
def test_paren_add_then_mul(self):
|
||||
# (1+2)*3 → BinOp('*', BinOp('+', Num(1), Num(2)), Num(3))
|
||||
tree = p("(1+2)*3")
|
||||
self.assertEqual(tree, BinOp("*", BinOp("+", Num(1), Num(2)), Num(3)))
|
||||
|
||||
def test_nested_parens(self):
|
||||
# ((4)) → Num(4)
|
||||
tree = p("((4))")
|
||||
self.assertEqual(tree, Num(4))
|
||||
|
||||
def test_paren_complex(self):
|
||||
# 2*(3+4) → BinOp('*', Num(2), BinOp('+', Num(3), Num(4)))
|
||||
tree = p("2*(3+4)")
|
||||
self.assertEqual(tree, BinOp("*", Num(2), BinOp("+", Num(3), Num(4))))
|
||||
|
||||
|
||||
class TestUnaryMinus(unittest.TestCase):
|
||||
"""D4 — unary minus"""
|
||||
|
||||
def test_simple_unary(self):
|
||||
# -5 → Unary('-', Num(5))
|
||||
tree = p("-5")
|
||||
self.assertEqual(tree, Unary("-", Num(5)))
|
||||
|
||||
def test_unary_paren(self):
|
||||
# -(1+2) → Unary('-', BinOp('+', Num(1), Num(2)))
|
||||
tree = p("-(1+2)")
|
||||
self.assertEqual(tree, Unary("-", BinOp("+", Num(1), Num(2))))
|
||||
|
||||
def test_unary_in_binop(self):
|
||||
# 3 * -2 → BinOp('*', Num(3), Unary('-', Num(2)))
|
||||
tree = p("3 * -2")
|
||||
self.assertEqual(tree, BinOp("*", Num(3), Unary("-", Num(2))))
|
||||
|
||||
def test_double_unary(self):
|
||||
# --5 → Unary('-', Unary('-', Num(5)))
|
||||
tree = p("--5")
|
||||
self.assertEqual(tree, Unary("-", Unary("-", Num(5))))
|
||||
|
||||
|
||||
class TestErrors(unittest.TestCase):
|
||||
"""D5 — malformed input raises ParseError"""
|
||||
|
||||
def test_trailing_operator(self):
|
||||
with self.assertRaises(ParseError):
|
||||
p("1 +")
|
||||
|
||||
def test_unclosed_paren(self):
|
||||
with self.assertRaises(ParseError):
|
||||
p("(1")
|
||||
|
||||
def test_two_numbers(self):
|
||||
with self.assertRaises(ParseError):
|
||||
p("1 2")
|
||||
|
||||
def test_close_before_open(self):
|
||||
with self.assertRaises(ParseError):
|
||||
p(")(")
|
||||
|
||||
def test_empty_string(self):
|
||||
with self.assertRaises(ParseError):
|
||||
p("")
|
||||
|
||||
def test_only_operator(self):
|
||||
with self.assertRaises(ParseError):
|
||||
p("+")
|
||||
|
||||
def test_mismatched_parens(self):
|
||||
with self.assertRaises(ParseError):
|
||||
p("(1+2")
|
||||
|
||||
|
||||
class TestAtoms(unittest.TestCase):
|
||||
"""Basic atoms parse cleanly"""
|
||||
|
||||
def test_single_int(self):
|
||||
self.assertEqual(p("42"), Num(42))
|
||||
|
||||
def test_single_float(self):
|
||||
self.assertEqual(p("3.14"), Num(3.14))
|
||||
|
||||
def test_single_in_parens(self):
|
||||
self.assertEqual(p("(7)"), Num(7))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@ -0,0 +1,7 @@
|
||||
# BACKLOG — Phase `eval`
|
||||
|
||||
## Build backlog
|
||||
_(Builder manages this section)_
|
||||
|
||||
## Adversary findings
|
||||
_None yet — awaiting implementation._
|
||||
@ -0,0 +1,10 @@
|
||||
# BACKLOG — phase `lex`
|
||||
|
||||
## Build backlog
|
||||
|
||||
All items completed.
|
||||
|
||||
- [x] D1: Implement `NUMBER` token (int + float, including `.5` and `10.`)
|
||||
- [x] D2: Implement operator and paren tokens (`PLUS`, `MINUS`, `STAR`, `SLASH`, `LPAREN`, `RPAREN`)
|
||||
- [x] D3: Skip whitespace; raise `LexError` for invalid characters
|
||||
- [x] D4: Write `calc/test_lexer.py` with unittest coverage for D1–D3
|
||||
@ -0,0 +1,21 @@
|
||||
# BACKLOG — Phase `parse`
|
||||
|
||||
## Build backlog
|
||||
_Read-only to Adversary — Builder maintains this section._
|
||||
|
||||
## Adversary findings
|
||||
_No findings yet — comprehensive verification deferred until review phase._
|
||||
|
||||
### Probe ideas (to run when implementation lands)
|
||||
- D1: `1+2*3` — must produce `BinOp('+', Num(1), BinOp('*', Num(2), Num(3)))` or equivalent, NOT `BinOp('*', BinOp('+', ...), ...)`.
|
||||
- D2: `8-3-2` — must be left-associative: `BinOp('-', BinOp('-', Num(8), Num(3)), Num(2))`.
|
||||
- D2: `8/4/2` — must be left-associative: `BinOp('/', BinOp('/', Num(8), Num(4)), Num(2))`.
|
||||
- D3: `(1+2)*3` — `+` must appear as LEFT child of `*`.
|
||||
- D4: `-5` — must parse as `Unary('-', Num(5))` or equivalent.
|
||||
- D4: `3 * -2` — unary on right side of binary op.
|
||||
- D4: `-(1+2)` — unary applied to parenthesized subexpr.
|
||||
- D5: `"1 +"` → ParseError (not generic exception).
|
||||
- D5: `"(1"` → ParseError.
|
||||
- D5: `"1 2"` → ParseError.
|
||||
- D5: `")("` → ParseError.
|
||||
- D5: `""` → ParseError.
|
||||
@ -0,0 +1,16 @@
|
||||
# BACKLOG — Phase `review`
|
||||
|
||||
## Build backlog
|
||||
|
||||
- [x] Initialize review-phase tracking files
|
||||
- [x] Run full test suite — 64 tests OK
|
||||
- [x] Run D3 cross-feature tests locally — all pass
|
||||
- [x] Populate STATUS-review.md with WHAT/HOW/EXPECTED/WHERE for Adversary
|
||||
- [x] Claim D1-D3 (commit + push)
|
||||
- [ ] Await Adversary comprehensive cold-verification in REVIEW-review.md
|
||||
- [ ] Fix any findings from Adversary (D4)
|
||||
- [ ] Write ## DONE to STATUS-review.md after Adversary PASS
|
||||
|
||||
## Adversary findings
|
||||
|
||||
(None yet — awaiting REVIEW-review.md)
|
||||
@ -0,0 +1,17 @@
|
||||
# DECISIONS (append-only)
|
||||
|
||||
## lex phase
|
||||
|
||||
**Token as dataclass**: Used `@dataclass` for `Token` to get `__eq__` for free, enabling `assertIn` and `assertEqual` in tests.
|
||||
|
||||
**int vs float**: `tokenize` returns Python `int` for whole-number literals (no decimal point), `float` when a `.` is present. This matches the plan's wording "numeric value (int or float)".
|
||||
|
||||
**EOF value**: Set `EOF` token `value` to `None` (no meaningful payload).
|
||||
|
||||
## eval phase
|
||||
|
||||
**EvalError wraps ZeroDivisionError**: `evaluate` catches division by zero itself (checks `right == 0`) and raises `EvalError` rather than letting Python's `ZeroDivisionError` propagate. This is the public API contract: callers catch `EvalError`.
|
||||
|
||||
**D3 formatting rule in `fmt_result`**: Placed in `calc/evaluator.py` so it's importable and testable from `calc/test_evaluator.py`. Rule: `isinstance(v, float) and v.is_integer()` → `str(int(v))`, else `str(v)`. Python's `/` always returns float, so `4/2 = 2.0`; `fmt_result` converts to `"2"`.
|
||||
|
||||
**CLI at repo root as `calc.py`**: Top-level script; Python finds the `calc/` package for imports because the working directory is on `sys.path` when running `python calc.py`.
|
||||
@ -0,0 +1,24 @@
|
||||
# JOURNAL — Phase `eval` (Adversary)
|
||||
|
||||
## 2026-06-16T00:20Z — Initialized
|
||||
|
||||
- Read eval.md: final phase, makes calculator end-to-end.
|
||||
- Builder's repo at seed (61f1ba0): has lexer.py, parser.py, test_lexer.py, test_parser.py (all seeded).
|
||||
- No evaluator.py, calc.py, or test_evaluator.py present yet.
|
||||
- Initialized STATUS-eval.md, REVIEW-eval.md, BACKLOG-eval.md, JOURNAL-eval.md.
|
||||
- Per REVIEW CADENCE: will do ONE comprehensive cold-verification after full build.
|
||||
- Waiting for Builder to implement eval phase.
|
||||
|
||||
## 2026-06-16 — Builder implementation
|
||||
|
||||
- Built calc/evaluator.py: EvalError, evaluate(node), fmt_result(v).
|
||||
- Built calc.py: CLI reading sys.argv[1], printing fmt_result(evaluate(parse(tokenize(expr)))).
|
||||
- Built calc/test_evaluator.py: 19 tests covering D1 (arithmetic), D2 (division/EvalError), D3 (fmt_result).
|
||||
- Full suite: 64 tests, 0 failures (python -m unittest -q).
|
||||
- CLI checks:
|
||||
- python calc.py "2+3*4" → 14
|
||||
- python calc.py "(2+3)*4" → 20
|
||||
- python calc.py "7/2" → 3.5
|
||||
- python calc.py "4/2" → 2
|
||||
- python calc.py "1/0" → stderr error, exit 1
|
||||
- python calc.py "1 +" → stderr error, exit 1
|
||||
@ -0,0 +1,42 @@
|
||||
# JOURNAL — phase `lex`
|
||||
|
||||
## Implementation
|
||||
|
||||
Built `calc/lexer.py` with:
|
||||
- `Token` dataclass with `kind: str` and `value: Union[int, float, str, None]`
|
||||
- `LexError(Exception)` for invalid characters
|
||||
- `tokenize(src: str) -> list[Token]` scanning left-to-right
|
||||
|
||||
Number handling: checks `ch.isdigit()` OR `ch == '.' followed by digit` (for `.5` case).
|
||||
Collects integer digits, then optionally a `.` and fractional digits.
|
||||
Result is `int` if no `.` seen, `float` otherwise — handles `10.` (trailing dot) correctly.
|
||||
|
||||
Operators: simple char-dispatch to the 6 operator/paren token kinds.
|
||||
|
||||
Whitespace: space and tab explicitly skipped via `continue`.
|
||||
|
||||
Errors: any unrecognised character raises `LexError` with `f"unexpected character {ch!r} at position {i}"`.
|
||||
|
||||
EOF appended unconditionally as the final token.
|
||||
|
||||
## Test run
|
||||
|
||||
```
|
||||
$ python -m unittest -q
|
||||
......................
|
||||
Ran 21 tests in 0.000s
|
||||
|
||||
OK
|
||||
```
|
||||
|
||||
## Verification
|
||||
|
||||
```
|
||||
$ python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize('3.5*(1-2)')])"
|
||||
[('NUMBER', 3.5), ('STAR', '*'), ('LPAREN', '('), ('NUMBER', 1), ('MINUS', '-'), ('NUMBER', 2), ('RPAREN', ')'), ('EOF', None)]
|
||||
|
||||
$ python -c "from calc.lexer import tokenize; tokenize('1 @ 2')"
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
calc.lexer.LexError: unexpected character '@' at position 2
|
||||
```
|
||||
@ -0,0 +1,6 @@
|
||||
# JOURNAL — Phase `parse` (Adversary)
|
||||
|
||||
## 2026-06-16T00:12Z — Init
|
||||
- Initialized parse phase tracking files.
|
||||
- No implementation present yet — only seed + adversary-init commits.
|
||||
- Entering idle loop; will poll for Builder progress.
|
||||
@ -0,0 +1,59 @@
|
||||
# JOURNAL — Phase `review`
|
||||
|
||||
## 2026-06-16 — Builder initialization
|
||||
|
||||
Entered review phase. Read phase plan at /home/loops/project-orchestrator/projects/agent-orchestrator-benchmark/plans/calc/review.md.
|
||||
|
||||
Prior state: all lex/parse/eval phases self-certified. eval DONE with Adversary comprehensive PASS at commit 21be8f5. Full 64 tests green.
|
||||
|
||||
### Self-verification runs
|
||||
|
||||
```
|
||||
$ python -m unittest -q
|
||||
----------------------------------------------------------------------
|
||||
Ran 64 tests in 0.001s
|
||||
|
||||
OK
|
||||
```
|
||||
|
||||
### D3 Cross-feature tests (local run)
|
||||
|
||||
```
|
||||
$ python calc.py "-(-(1+2))"
|
||||
3
|
||||
exit:0
|
||||
|
||||
$ python calc.py "2+3*4-5/5"
|
||||
13
|
||||
exit:0
|
||||
|
||||
$ python calc.py "1 @ 2"; echo "exit:$?"
|
||||
error: unexpected character '@' at position 2
|
||||
exit:1
|
||||
|
||||
$ python calc.py "1/0"; echo "exit:$?"
|
||||
error: division by zero
|
||||
exit:1
|
||||
|
||||
$ python calc.py "(1+"; echo "exit:$?"
|
||||
error: unexpected token 'EOF' (None)
|
||||
exit:1
|
||||
|
||||
$ python calc.py " 2.5 + ( 3.5 * 2 ) "
|
||||
9.5
|
||||
exit:0
|
||||
|
||||
$ python calc.py "( 1 + 2 ) * ( 3 + 4 )"
|
||||
21
|
||||
exit:0
|
||||
|
||||
$ python calc.py "2+3*4"; echo "exit:$?"
|
||||
14
|
||||
exit:0
|
||||
|
||||
$ python calc.py "bad input @#"; echo "exit:$?"
|
||||
error: unexpected character 'b' at position 0
|
||||
exit:1
|
||||
```
|
||||
|
||||
All cross-feature tests produce expected output. Builder claims D1-D3; awaiting Adversary cold-verification.
|
||||
@ -0,0 +1,63 @@
|
||||
# REVIEW — Phase `eval`
|
||||
|
||||
**Adversary cold-verification record.**
|
||||
|
||||
## Status
|
||||
COMPREHENSIVE PASS — all DoD gates verified @2026-06-16T00:18Z from cold start in work-adv clone.
|
||||
No VETO.
|
||||
|
||||
## Verdicts
|
||||
|
||||
### D1 — arithmetic: PASS @2026-06-16T00:18Z
|
||||
Verified all 5 plan-specified cases independently:
|
||||
- `2+3*4` → 14 ✓ (precedence: * before +)
|
||||
- `(2+3)*4` → 20 ✓ (parens override precedence)
|
||||
- `8-3-2` → 3 ✓ (left-associativity; NOT 7)
|
||||
- `-2+5` → 3 ✓ (leading unary minus)
|
||||
- `2*-3` → -6 ✓ (unary minus after binary op)
|
||||
|
||||
Command: `python -c "... evaluate(parse(tokenize(expr))) ..."` for each case.
|
||||
|
||||
### D2 — division: PASS @2026-06-16T00:18Z
|
||||
- `7/2` → 3.5 ✓ (true division, not floor)
|
||||
- `1/0` raises `EvalError("division by zero")` ✓
|
||||
- `ZeroDivisionError` does NOT escape the API ✓ (independently verified: caught EvalError, no ZeroDivisionError propagated)
|
||||
|
||||
### D3 — result type: PASS @2026-06-16T00:18Z
|
||||
- `fmt_result(eval("4/2"))` → `"2"` ✓ (whole float → no trailing .0)
|
||||
- `fmt_result(eval("7/2"))` → `"3.5"` ✓ (non-whole float)
|
||||
- `fmt_result(eval("2+3"))` → `"5"` ✓ (int stays int)
|
||||
- `fmt_result(-6)` → `"-6"` ✓ (negative int)
|
||||
- `fmt_result(eval("-7/2"))` → `"-3.5"` ✓ (negative non-whole float via CLI)
|
||||
- `fmt_result(eval("-6/2"))` → `"-3"` ✓ (negative whole float → no .0)
|
||||
|
||||
### D4 — CLI: PASS @2026-06-16T00:18Z
|
||||
- `python calc.py "2+3*4"` → stdout `14`, exit 0 ✓
|
||||
- `python calc.py "(2+3)*4"` → stdout `20`, exit 0 ✓
|
||||
- `python calc.py "7/2"` → stdout `3.5`, exit 0 ✓
|
||||
- `python calc.py "4/2"` → stdout `2`, exit 0 ✓
|
||||
- `python calc.py "1/0"` → stderr `error: division by zero`, exit 1 ✓
|
||||
- `python calc.py "1 +"` → stderr `error: unexpected token 'EOF' (None)`, exit 1 ✓
|
||||
- Error output goes to STDERR (stdout suppression confirmed) ✓
|
||||
- No raw traceback on any error path ✓ (checked with grep)
|
||||
- Wrong arg count → usage message to stderr, exit 1 ✓
|
||||
|
||||
### D5 — tests green + end-to-end: PASS @2026-06-16T00:18Z
|
||||
- `python -m unittest -q` → `Ran 64 tests in 0.001s\nOK` ✓
|
||||
- Lex suite (calc.test_lexer): 45 of 64 total — passes ✓ (no regression)
|
||||
- Parse suite (calc.test_parser): included in 45 — passes ✓ (no regression)
|
||||
- Eval suite (calc.test_evaluator): 19 tests covering D1–D3 ✓
|
||||
|
||||
## Cross-feature integration probes (adversarial)
|
||||
All passed:
|
||||
- `python calc.py "-6/2"` → `-3` ✓ (unary minus + whole-float formatting)
|
||||
- `python calc.py "(-6)/2"` → `-3` ✓
|
||||
- `python calc.py "(2*(3+4))"` → `14` ✓ (nested parens + multiplication)
|
||||
- `python calc.py "-7/2"` → `-3.5` ✓ (unary minus + true division)
|
||||
- `python calc.py "@"` → stderr error, exit 1, no traceback ✓ (LexError path)
|
||||
|
||||
## Notes
|
||||
- Verified from work-adv clone (cold start — no cached pyc state from builder's env).
|
||||
- JOURNAL not consulted before verdict (isolation maintained).
|
||||
- `evaluate()` returns Python `int` for integer arithmetic (e.g., `2+3 → int(5)`) — `fmt_result` handles both `int` and `float` correctly.
|
||||
- Division always returns Python `float` (Python `/` operator), caught by `is_integer()` check.
|
||||
@ -0,0 +1,13 @@
|
||||
# REVIEW — Phase `lex`
|
||||
|
||||
**Adversary cold-verification record.**
|
||||
|
||||
## Status
|
||||
Awaiting Builder to complete implementation. Per REVIEW CADENCE — DEFERRED rules, comprehensive verification will occur after full build completes.
|
||||
|
||||
## Verdicts
|
||||
_None yet — Builder has not claimed completion._
|
||||
|
||||
## Notes
|
||||
- Seed commit only (61f1ba0) — no implementation present
|
||||
- Monitoring for Builder commits
|
||||
@ -0,0 +1,15 @@
|
||||
# REVIEW — Phase `parse`
|
||||
|
||||
**Adversary cold-verification record.**
|
||||
|
||||
## Status
|
||||
DEFERRED — per REVIEW CADENCE rules, comprehensive verification occurs after full build, not per gate.
|
||||
Builder has not yet implemented the parse phase.
|
||||
|
||||
## Verdicts
|
||||
_None yet — implementation not present._
|
||||
|
||||
## Notes
|
||||
- Monitoring for Builder commits to `calc/parser.py` and `calc/test_parser.py`.
|
||||
- Per plan: verify using `python -m unittest -q` plus structural AST assertions.
|
||||
- Key risk: precedence/associativity bug that still passes a weak test — will re-derive expected tree from plan independently.
|
||||
@ -0,0 +1,118 @@
|
||||
# REVIEW — Phase `review`
|
||||
|
||||
**Adversary cold-verification record.**
|
||||
|
||||
## Status
|
||||
|
||||
COMPREHENSIVE PASS @2026-06-16T00:21Z — all D1–D4 items verified.
|
||||
|
||||
---
|
||||
|
||||
## D1 — Full cold re-verify (all prior phase DoD items)
|
||||
|
||||
Cold-verified from work-adv clone at commit `bfd5972` (post-pull).
|
||||
|
||||
### Lexer DoD
|
||||
- INTEGER: `tokenize('42')` → `[Token('NUMBER', 42), Token('EOF', None)]`, `value` is `int` ✓
|
||||
- FLOAT: `tokenize('3.14')` → `[Token('NUMBER', 3.14), Token('EOF', None)]` ✓
|
||||
- LEADING DOT: `tokenize('.5')` → `Token('NUMBER', 0.5)` ✓
|
||||
- OPERATORS: `tokenize('+-*/()')` → PLUS, MINUS, STAR, SLASH, LPAREN, RPAREN, EOF (correct kinds) ✓
|
||||
- WHITESPACE: spaces and tabs skipped ✓
|
||||
- LexError message contains char + position: `unexpected character '$' at position 1` ✓
|
||||
- Unknown chars `@`, `$`, letters raise `LexError` ✓
|
||||
|
||||
**PASS**
|
||||
|
||||
### Parser DoD
|
||||
- Single int: `parse(tokenize('1'))` → `Num(1)` ✓
|
||||
- Single float: `parse(tokenize('3.14'))` → `Num(3.14)` ✓
|
||||
- BinOp shape: `parse(tokenize('1+2'))` → `BinOp('+', Num(1), Num(2))` ✓
|
||||
- Unary shape: `parse(tokenize('-5'))` → `Unary('-', Num(5))` ✓
|
||||
- Precedence: `parse(tokenize('2+3*4'))` → `BinOp('+', Num(2), BinOp('*', Num(3), Num(4)))` (mul binds tighter) ✓
|
||||
- Left-associativity: `parse(tokenize('1-2-3'))` → `BinOp('-', BinOp('-', Num(1), Num(2)), Num(3))` ✓
|
||||
- Empty input: raises `ParseError` ✓
|
||||
- Unclosed paren `(1+`: raises `ParseError` ✓
|
||||
- Two numbers adjacent `1 2`: raises `ParseError` ✓
|
||||
|
||||
**PASS**
|
||||
|
||||
### Evaluator DoD
|
||||
- Arithmetic: `2+3*4`→14, `(2+3)*4`→20, `8-3-2`→3, `-2+5`→3, `2*-3`→-6 ✓
|
||||
- True division: `7/2`→3.5 ✓
|
||||
- Division by zero: `1/0` raises `EvalError("division by zero")`, NOT bare `ZeroDivisionError` ✓
|
||||
- fmt_result: `fmt_result(2.0)`→`'2'`, `fmt_result(3.5)`→`'3.5'`, `fmt_result(42)`→`'42'` ✓
|
||||
- CLI: `python calc.py "2+3*4"` → stdout `14`, exit 0 ✓
|
||||
- CLI: `python calc.py "(2+3)*4"` → stdout `20`, exit 0 ✓
|
||||
- CLI: `python calc.py "7/2"` → stdout `3.5`, exit 0 ✓
|
||||
- CLI: `python calc.py "4/2"` → stdout `2`, exit 0 ✓
|
||||
- CLI error: `python calc.py "1/0"` → stderr `error: division by zero`, exit 1, no traceback ✓
|
||||
- CLI error: `python calc.py "1 +"` → stderr `error: unexpected token 'EOF' (None)`, exit 1 ✓
|
||||
|
||||
**PASS**
|
||||
|
||||
---
|
||||
|
||||
## D2 — Full suite green
|
||||
|
||||
```
|
||||
python -m unittest -v
|
||||
Ran 64 tests in 0.002s
|
||||
OK
|
||||
```
|
||||
|
||||
All 64 tests pass (calc.test_lexer, calc.test_parser, calc.test_evaluator). Zero failures, zero errors.
|
||||
|
||||
**PASS**
|
||||
|
||||
---
|
||||
|
||||
## D3 — Cross-feature break-it
|
||||
|
||||
All tests run independently against the actual CLI and Python API:
|
||||
|
||||
| Expression | Expected | Actual | Result |
|
||||
|---|---|---|---|
|
||||
| `-(-(1+2))` | `3` | `3` | PASS |
|
||||
| `2+3*4-5/5` | `13` | `13` (raw 13.0, fmt→13) | PASS |
|
||||
| `--5` | `5` | `5` | PASS |
|
||||
| `((((3))))` | `3` | `3` | PASS |
|
||||
| `1+2*3+4*5+6` | `33` | `33` | PASS |
|
||||
| `( 1.5 + 2.5 ) * 2` | `8` | `8` (raw 8.0, fmt→8) | PASS |
|
||||
| ` 2.5 + ( 3.5 * 2 ) ` | `9.5` | `9.5` | PASS |
|
||||
| `(1+2)*(3+4)` | `21` | `21` | PASS |
|
||||
|
||||
Error propagation:
|
||||
|
||||
| Input | Expected error type | Actual | Result |
|
||||
|---|---|---|---|
|
||||
| `1 @ 2` | `LexError` | `LexError: unexpected character '@' at position 2` | PASS |
|
||||
| `1/0` | `EvalError` | `EvalError: division by zero` (no bare `ZeroDivisionError`) | PASS |
|
||||
| `(1+` | `ParseError` | `ParseError: unexpected token 'EOF' (None)` | PASS |
|
||||
| `bad input @#` | CLI exit 1 | `error: unexpected character 'b' at position 0`, exit 1 | PASS |
|
||||
|
||||
CLI exit codes:
|
||||
- Valid expressions → exit 0 ✓
|
||||
- Invalid expressions (lex/parse/eval errors) → exit 1 ✓
|
||||
- No tracebacks on errors ✓
|
||||
|
||||
Note: `2+3*4-5/5` raw result is `13.0` (float, because `5/5` returns `1.0`), but `fmt_result(13.0)` → `'13'` — correct behavior.
|
||||
|
||||
**No defects found. PASS**
|
||||
|
||||
---
|
||||
|
||||
## D4 — Findings cleared
|
||||
|
||||
No findings were filed. No VETO. Nothing to clear.
|
||||
|
||||
**PASS**
|
||||
|
||||
---
|
||||
|
||||
## OVERALL VERDICT
|
||||
|
||||
**review(all): PASS @2026-06-16T00:21Z**
|
||||
|
||||
Comprehensive cold-verification of all D1–D4 from the review phase plan (covering lex, parse, eval, and CLI) passes in full. 64 unit tests green. All cross-feature integration probes pass. No defects, no VETO.
|
||||
|
||||
Builder may now write `## DONE` to STATUS-review.md.
|
||||
@ -0,0 +1,104 @@
|
||||
# STATUS — Phase `eval`
|
||||
|
||||
## DONE
|
||||
|
||||
All D1–D5 gates Adversary-verified PASS @2026-06-16T00:18Z (REVIEW-eval.md). No VETO.
|
||||
|
||||
## Gate: ALL CLAIMED, awaiting Adversary comprehensive verification
|
||||
|
||||
---
|
||||
|
||||
## D1 — arithmetic
|
||||
**WHAT:** `evaluate(parse(tokenize(s)))` is correct for `+`, `-`, `*`, `/`, precedence, parens, and unary minus.
|
||||
**HOW:**
|
||||
```bash
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse; from calc.evaluator import evaluate; print(evaluate(parse(tokenize('2+3*4'))))"
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse; from calc.evaluator import evaluate; print(evaluate(parse(tokenize('(2+3)*4'))))"
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse; from calc.evaluator import evaluate; print(evaluate(parse(tokenize('8-3-2'))))"
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse; from calc.evaluator import evaluate; print(evaluate(parse(tokenize('-2+5'))))"
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse; from calc.evaluator import evaluate; print(evaluate(parse(tokenize('2*-3'))))"
|
||||
```
|
||||
**EXPECTED:** `14`, `20`, `3`, `3`, `-6`
|
||||
**WHERE:** `calc/evaluator.py`, `calc/test_evaluator.py::TestArithmetic`
|
||||
|
||||
---
|
||||
|
||||
## D2 — division
|
||||
**WHAT:** `/` is true division; division by zero raises `EvalError`, not bare `ZeroDivisionError`.
|
||||
**HOW:**
|
||||
```bash
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse; from calc.evaluator import evaluate; print(evaluate(parse(tokenize('7/2'))))"
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse; from calc.evaluator import evaluate, EvalError
|
||||
try:
|
||||
evaluate(parse(tokenize('1/0')))
|
||||
except EvalError as e:
|
||||
print('EvalError:', e)
|
||||
except ZeroDivisionError:
|
||||
print('FAIL: bare ZeroDivisionError escaped')
|
||||
"
|
||||
```
|
||||
**EXPECTED:** `3.5`; then `EvalError: division by zero`
|
||||
**WHERE:** `calc/evaluator.py`, `calc/test_evaluator.py::TestDivision`
|
||||
|
||||
---
|
||||
|
||||
## D3 — result type
|
||||
**WHAT:** Whole-valued floats display without trailing `.0`; non-whole floats display normally.
|
||||
**Rule:** `fmt_result(v)` in `calc/evaluator.py`: if `isinstance(v, float) and v.is_integer()` → `str(int(v))`, else `str(v)`.
|
||||
**HOW:**
|
||||
```bash
|
||||
python calc.py "4/2"
|
||||
python calc.py "7/2"
|
||||
```
|
||||
**EXPECTED:** `2`, `3.5`
|
||||
**WHERE:** `calc/evaluator.py::fmt_result`, `calc/test_evaluator.py::TestResultType`, `calc.py`
|
||||
|
||||
---
|
||||
|
||||
## D4 — CLI
|
||||
**WHAT:** `python calc.py "2+3*4"` prints `14` and exits 0; errors print to stderr and exit non-zero with no traceback.
|
||||
**HOW:**
|
||||
```bash
|
||||
python calc.py "2+3*4" # stdout: 14, exit 0
|
||||
python calc.py "(2+3)*4" # stdout: 20, exit 0
|
||||
python calc.py "7/2" # stdout: 3.5, exit 0
|
||||
python calc.py "4/2" # stdout: 2, exit 0
|
||||
python calc.py "1/0"; echo "exit:$?" # stderr: error, exit 1
|
||||
python calc.py "1 +"; echo "exit:$?" # stderr: error, exit 1
|
||||
```
|
||||
**EXPECTED:** `14`, `20`, `3.5`, `2`, then error+exit:1, error+exit:1
|
||||
**WHERE:** `calc.py`
|
||||
|
||||
---
|
||||
|
||||
## D5 — tests green + end-to-end
|
||||
**WHAT:** Full unittest suite (lex + parse + eval) passes, 0 failures.
|
||||
**HOW:**
|
||||
```bash
|
||||
python -m unittest -q
|
||||
```
|
||||
**EXPECTED:** `Ran 64 tests in X.XXXs\nOK`
|
||||
**WHERE:** `calc/test_lexer.py`, `calc/test_parser.py`, `calc/test_evaluator.py`
|
||||
|
||||
---
|
||||
|
||||
## Verification commands (for Adversary cold-verify)
|
||||
|
||||
```bash
|
||||
python -m unittest -q
|
||||
python calc.py "2+3*4"
|
||||
python calc.py "(2+3)*4"
|
||||
python calc.py "7/2"
|
||||
python calc.py "4/2"
|
||||
python calc.py "1/0"; echo "exit:$?"
|
||||
python calc.py "1 +"; echo "exit:$?"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Adversary Verdict @2026-06-16T00:18Z
|
||||
|
||||
**COMPREHENSIVE PASS — all D1–D5 gates verified cold.**
|
||||
|
||||
Cold-verified from work-adv clone (commit 21be8f5). Full verdicts in REVIEW-eval.md.
|
||||
Builder may now write `## DONE` to this file.
|
||||
@ -0,0 +1,43 @@
|
||||
# STATUS — phase `lex`
|
||||
|
||||
## DONE
|
||||
|
||||
All DoD items implemented, tests green (21/21), self-certified per DEFERRED review cadence.
|
||||
|
||||
---
|
||||
|
||||
## Gates
|
||||
|
||||
### D1 — numbers
|
||||
**WHAT:** Integers and floats tokenize to `NUMBER` tokens with correct Python-typed values.
|
||||
**HOW:** `python -m unittest -q`
|
||||
**EXPECTED:** 21 tests, 0 failures
|
||||
**WHERE:** `calc/lexer.py`, `calc/test_lexer.py`
|
||||
|
||||
### D2 — operators & parens
|
||||
**WHAT:** `+ - * / ( )` each produce correct token kinds.
|
||||
**HOW:** `python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize('3.5*(1-2)')])"`
|
||||
**EXPECTED:** `[('NUMBER', 3.5), ('STAR', '*'), ('LPAREN', '('), ('NUMBER', 1), ('MINUS', '-'), ('NUMBER', 2), ('RPAREN', ')'), ('EOF', None)]`
|
||||
**WHERE:** `calc/lexer.py`
|
||||
|
||||
### D3 — whitespace & errors
|
||||
**WHAT:** Spaces/tabs skipped; invalid chars raise `LexError` with char and position.
|
||||
**HOW:** `python -c "from calc.lexer import tokenize; tokenize('1 @ 2')"` — must raise `LexError`
|
||||
**EXPECTED:** `calc.lexer.LexError: unexpected character '@' at position 2`
|
||||
**WHERE:** `calc/lexer.py`
|
||||
|
||||
### D4 — tests green
|
||||
**WHAT:** `calc/test_lexer.py` passes under `python -m unittest`, 0 failures.
|
||||
**HOW:** `python -m unittest -q`
|
||||
**EXPECTED:** `Ran 21 tests in X.XXXs\nOK`
|
||||
**WHERE:** `calc/test_lexer.py`
|
||||
|
||||
---
|
||||
|
||||
## Verification commands (for Adversary cold-verify)
|
||||
|
||||
```bash
|
||||
python -m unittest -q
|
||||
python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize('3.5*(1-2)')])"
|
||||
python -c "from calc.lexer import tokenize; tokenize('1 @ 2')"
|
||||
```
|
||||
@ -0,0 +1,21 @@
|
||||
# STATUS — Phase `parse` (Adversary tracking)
|
||||
|
||||
## Current state
|
||||
WAITING — Builder has not begun `parse` phase. No `calc/parser.py` or `calc/test_parser.py` exist yet.
|
||||
|
||||
## Last checked
|
||||
2026-06-16T00:12Z — only seed + adversary-init commits present; no implementation.
|
||||
|
||||
## Pending verifications
|
||||
None yet — deferred per REVIEW CADENCE rule.
|
||||
|
||||
## AST shape (to be filled by Builder)
|
||||
_Awaiting Builder to document node shapes in this file._
|
||||
|
||||
## DoD tracking (deferred)
|
||||
- D1 — precedence: NOT VERIFIED
|
||||
- D2 — left associativity: NOT VERIFIED
|
||||
- D3 — parentheses: NOT VERIFIED
|
||||
- D4 — unary minus: NOT VERIFIED
|
||||
- D5 — errors: NOT VERIFIED
|
||||
- D6 — tests green: NOT VERIFIED
|
||||
@ -0,0 +1,116 @@
|
||||
# STATUS — Phase `review`
|
||||
|
||||
## DONE
|
||||
|
||||
All D1–D4 gates Adversary-verified PASS @2026-06-16T00:21Z (REVIEW-review.md). No VETO.
|
||||
|
||||
## Gate: D1-D3 CLAIMED — Adversary comprehensive PASS received
|
||||
|
||||
The full calculator accumulation (lex + parse + eval + CLI) is complete and self-certified.
|
||||
The Adversary should cold-verify D1–D3 from a fresh clone and record findings in REVIEW-review.md.
|
||||
|
||||
---
|
||||
|
||||
## D1 — Full cold re-verify
|
||||
|
||||
**WHAT:** From a fresh clone, re-run all DoD items from lex, parse, and eval phases.
|
||||
|
||||
**HOW:**
|
||||
```bash
|
||||
# Clone fresh and run from work dir
|
||||
python -m unittest -q
|
||||
|
||||
# Lexer DoD: tokenize produces correct token lists
|
||||
python -c "from calc.lexer import tokenize; print(tokenize('2+3*4'))"
|
||||
python -c "from calc.lexer import tokenize; print(tokenize('-2'))"
|
||||
python -c "from calc.lexer import tokenize; print(tokenize('3.14'))"
|
||||
|
||||
# Parser DoD: AST shape is correct
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse; import json; ast = parse(tokenize('1+2*3')); print(ast)"
|
||||
|
||||
# Evaluator DoD: arithmetic + division + result type
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse; from calc.evaluator import evaluate; print(evaluate(parse(tokenize('2+3*4'))))"
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse; from calc.evaluator import evaluate; print(evaluate(parse(tokenize('(2+3)*4'))))"
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse; from calc.evaluator import evaluate; print(evaluate(parse(tokenize('8-3-2'))))"
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse; from calc.evaluator import evaluate; print(evaluate(parse(tokenize('-2+5'))))"
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse; from calc.evaluator import evaluate; print(evaluate(parse(tokenize('2*-3'))))"
|
||||
python -c "from calc.lexer import tokenize; from calc.parser import parse; from calc.evaluator import evaluate; print(evaluate(parse(tokenize('7/2'))))"
|
||||
|
||||
# CLI DoD
|
||||
python calc.py "2+3*4"
|
||||
python calc.py "(2+3)*4"
|
||||
python calc.py "7/2"
|
||||
python calc.py "4/2"
|
||||
python calc.py "1/0"; echo "exit:$?"
|
||||
python calc.py "1 +"; echo "exit:$?"
|
||||
```
|
||||
|
||||
**EXPECTED:**
|
||||
- `python -m unittest -q` → `Ran 64 tests in X.XXXs\nOK`
|
||||
- Tokenizer outputs correct token lists
|
||||
- AST shape is `BinOp(+, Num(1), BinOp(*, Num(2), Num(3)))`
|
||||
- `2+3*4` → `14`, `(2+3)*4` → `20`, `8-3-2` → `3`, `-2+5` → `3`, `2*-3` → `-6`, `7/2` → `3.5`
|
||||
- CLI: `14`, `20`, `3.5`, `2`, then `error: division by zero` + exit:1, `error: unexpected token 'EOF'` + exit:1
|
||||
|
||||
**WHERE:** `calc/lexer.py`, `calc/parser.py`, `calc/evaluator.py`, `calc.py`
|
||||
|
||||
---
|
||||
|
||||
## D2 — Full suite green
|
||||
|
||||
**WHAT:** `python -m unittest` passes, 0 failures, 64 tests.
|
||||
|
||||
**HOW:**
|
||||
```bash
|
||||
python -m unittest -q
|
||||
```
|
||||
|
||||
**EXPECTED:** `Ran 64 tests in X.XXXs\nOK`
|
||||
|
||||
**WHERE:** `calc/test_lexer.py`, `calc/test_parser.py`, `calc/test_evaluator.py`
|
||||
|
||||
---
|
||||
|
||||
## D3 — Cross-feature break-it
|
||||
|
||||
**WHAT:** Specific cross-feature interactions verified.
|
||||
|
||||
**HOW:**
|
||||
```bash
|
||||
# Nested unary + parens
|
||||
python calc.py "-(-(1+2))"
|
||||
|
||||
# Precedence chain
|
||||
python calc.py "2+3*4-5/5"
|
||||
|
||||
# Error propagation: lexer→evaluator
|
||||
python calc.py "1 @ 2"; echo "exit:$?"
|
||||
python calc.py "1/0"; echo "exit:$?"
|
||||
python calc.py "(1+"; echo "exit:$?"
|
||||
|
||||
# Whitespace + floats + parens
|
||||
python calc.py " 2.5 + ( 3.5 * 2 ) "
|
||||
python calc.py "( 1 + 2 ) * ( 3 + 4 )"
|
||||
|
||||
# CLI exit codes
|
||||
python calc.py "2+3*4"; echo "exit:$?"
|
||||
python calc.py "bad input @#"; echo "exit:$?"
|
||||
```
|
||||
|
||||
**EXPECTED:**
|
||||
- `-(-(1+2))` → `3`
|
||||
- `2+3*4-5/5` → `13`
|
||||
- `1 @ 2` → stderr `error: unexpected character '@'`, exit:1
|
||||
- `1/0` → stderr `error: division by zero`, exit:1
|
||||
- `(1+` → stderr `error: unexpected token 'EOF'`, exit:1
|
||||
- `2.5 + (3.5 * 2)` → `9.5`
|
||||
- `(1+2)*(3+4)` → `21`
|
||||
- valid input → exit:0; invalid input → exit:1
|
||||
|
||||
**WHERE:** `calc/lexer.py`, `calc/parser.py`, `calc/evaluator.py`, `calc.py`
|
||||
|
||||
---
|
||||
|
||||
## Builder self-verification @2026-06-16
|
||||
|
||||
All cross-feature tests above run locally and produce the expected outputs. See JOURNAL-review.md for exact output transcript.
|
||||
Reference in New Issue
Block a user