1.6 KiB
STATUS — phase lex
Gates
D1 — numbers
Command: python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize('42')])"
Expected: [('NUMBER', 42), ('EOF', None)]
Observed: [('NUMBER', 42), ('EOF', None)] ✓
Also verified: 3.14 → NUMBER(3.14) (float), .5 → NUMBER(0.5) (float), 10. → NUMBER(10.0) (float).
D2 — operators & parens
Command: python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize('1+2*3')])"
Expected: NUMBER PLUS NUMBER STAR NUMBER EOF
Observed: [('NUMBER', 1), ('PLUS', '+'), ('NUMBER', 2), ('STAR', '*'), ('NUMBER', 3), ('EOF', None)] ✓
D3 — whitespace & errors
Command (whitespace): python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize(' 12 + 3 ')])"
Observed: [('NUMBER', 12), ('PLUS', '+'), ('NUMBER', 3), ('EOF', None)] ✓
Command (LexError): python -c "from calc.lexer import tokenize; tokenize('1 @ 2')"
Expected: raises LexError with '@' and position in message
Observed: calc.lexer.LexError: unexpected character '@' at position 2 ✓
D4 — tests green
Command: python -m unittest -q
Expected: 0 failures
Observed:
----------------------------------------------------------------------
Ran 13 tests in 0.001s
OK
✓
Complex expression check:
Command: python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize('3.5*(1-2)')])"
Observed: [('NUMBER', 3.5), ('STAR', '*'), ('LPAREN', '('), ('NUMBER', 1), ('MINUS', '-'), ('NUMBER', 2), ('RPAREN', ')'), ('EOF', None)] ✓