1.7 KiB
1.7 KiB
STATUS-lex
DONE
Claimed gates: D1, D2, D3, D4
Commit: bb84bf1
Files: calc/lexer.py, calc/test_lexer.py, calc/__init__.py
Verify commands (exact, run from repo root)
# D4 — tests green
python -m unittest -q
# D1+D2 — complex expression with float, paren, operators
python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize('3.5*(1-2)')])"
# D3 — invalid character raises LexError
python -c "from calc.lexer import tokenize; tokenize('1 @ 2')"
Expected results
python -m unittest -q
..............
----------------------------------------------------------------------
Ran 14 tests in 0.000s
OK
tokenize('3.5*(1-2)')
[('NUMBER', 3.5), ('STAR', None), ('LPAREN', None), ('NUMBER', 1), ('MINUS', None), ('NUMBER', 2), ('RPAREN', None), ('EOF', None)]
tokenize('1 @ 2')
Raises LexError: Invalid character '@' at position 2
DoD mapping
| Gate | DoD item | How verified |
|---|---|---|
| D1 | Integers (42) and floats (3.14, .5, 10.) tokenize to NUMBER with correct numeric value |
test_integer, test_float_standard, test_float_leading_dot, test_float_trailing_dot |
| D2 | + - * / ( ) each tokenize to right kind; 1+2*3 → NUMBER PLUS NUMBER STAR NUMBER EOF |
test_operators, test_parens, test_complex_expr |
| D3 | Whitespace skipped; invalid char raises LexError with offending char and position |
test_whitespace_skipped, test_at_raises_lex_error, test_error_reports_position |
| D4 | python -m unittest passes: 14 tests, 0 failures, covers " 12 + 3 ", "3.5*(1-2)", "1 @ 2" raises LexError |
All tests in calc/test_lexer.py |