736 B
736 B
JOURNAL-lex
Implementation notes
Built calc/lexer.py with:
Tokendataclass withkind: strandvalue: Union[int, float, None]LexError(Exception)for invalid characterstokenize(src: str) -> list[Token]scanning character by character
Number scanning handles all three forms: integer (42), standard float (3.14), leading-dot float (.5), and trailing-dot float (10.). The key invariant: when ch is . we only enter number scanning if the next char is also a digit (to avoid confusing . used as an operator in other contexts). Trailing dot (10.) is handled because after scanning digits we check if the next char is . and absorb it into a float.
14 tests written covering D1-D4 plus edge cases.