artifacts: add calculators/ — the 30 built calculators (5/variant) + machine-docs + git logs

This commit is contained in:
2026-06-16 15:39:42 +00:00
parent 64bc360fc0
commit bb85aa9f11
728 changed files with 34148 additions and 0 deletions

View File

@ -0,0 +1,32 @@
#!/usr/bin/env python3
"""calc.py — command-line arithmetic calculator.
Usage: python calc.py "<expression>"
"""
import sys
from calc.lexer import LexError, tokenize
from calc.parser import ParseError, parse
from calc.evaluator import EvalError, evaluate
def main() -> None:
if len(sys.argv) != 2:
print("Usage: calc.py \"<expression>\"", file=sys.stderr)
sys.exit(1)
expr = sys.argv[1]
try:
tokens = tokenize(expr)
ast = parse(tokens)
result = evaluate(ast)
except (LexError, ParseError, EvalError) as exc:
print(f"Error: {exc}", file=sys.stderr)
sys.exit(1)
print(result)
if __name__ == "__main__":
main()