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
@@ -0,0 +1,52 @@
from dataclasses import dataclass
from typing import Any
class LexError(Exception):
pass
@dataclass
class Token:
kind: str
value: Any
_OPERATORS = {
'+': 'PLUS',
'-': 'MINUS',
'*': 'STAR',
'/': 'SLASH',
'(': 'LPAREN',
')': 'RPAREN',
}
def tokenize(src: str) -> list:
tokens = []
i = 0
n = len(src)
while i < n:
ch = src[i]
if ch in ' \t':
i += 1
continue
if ch.isdigit() or ch == '.':
j = i
while j < n and (src[j].isdigit() or src[j] == '.'):
j += 1
raw = src[i:j]
try:
value = float(raw) if '.' in raw else int(raw)
except ValueError:
raise LexError(f"malformed number {raw!r} at position {i}")
tokens.append(Token('NUMBER', value))
i = j
continue
if ch in _OPERATORS:
tokens.append(Token(_OPERATORS[ch], ch))
i += 1
continue
raise LexError(f"unexpected character {ch!r} at position {i}")
tokens.append(Token('EOF', None))
return tokens