2.6 KiB
STATUS — phase lex
Gates
D1 — numbers
What: Integers and floats tokenize to NUMBER with correct numeric value (int or float).
Command:
python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize('42')])"
python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize('3.14')])"
python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize('.5')])"
python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize('10.')])"
Expected: NUMBER with int value for integers; float for 3.14, .5, 10.
Observed:
[('NUMBER', 42), ('EOF', None)] # int
[('NUMBER', 3.14), ('EOF', None)] # float
[('NUMBER', 0.5), ('EOF', None)] # leading dot
[('NUMBER', 10.0), ('EOF', None)] # trailing dot
Result: PASS
D2 — operators & parens
What: + - * / ( ) each tokenize to their correct kind.
Command:
python -c "from calc.lexer import tokenize; print([t.kind for t in tokenize('1+2*3')])"
Expected: ['NUMBER', 'PLUS', 'NUMBER', 'STAR', 'NUMBER', 'EOF']
Observed: ['NUMBER', 'PLUS', 'NUMBER', 'STAR', 'NUMBER', 'EOF']
Result: PASS
D3 — whitespace & errors
What: Spaces/tabs skipped; invalid chars raise LexError with char and position.
Command:
python -c "from calc.lexer import tokenize; print([t.kind for t in tokenize(' 12 + 3 ')])"
python -c "from calc.lexer import tokenize; tokenize('1 @ 2')"
Expected: Whitespace version → ['NUMBER', 'PLUS', 'NUMBER', 'EOF']; @ raises LexError with @ and position 2 in message.
Observed:
- Whitespace:
['NUMBER', 'PLUS', 'NUMBER', 'EOF'] - LexError:
calc.lexer.LexError: unexpected character '@' at position 2
Result: PASS
D4 — tests green
What: calc/test_lexer.py passes python -m unittest, 0 failures, covering D1–D3.
Command:
python -m unittest -q
Expected: Ran N tests in ... OK
Observed:
----------------------------------------------------------------------
Ran 18 tests in 0.000s
OK
Result: PASS
Exact plan verification commands
python -m unittest -q
# → Ran 18 tests in 0.000s OK
python -c "from calc.lexer import tokenize; print([(t.kind,t.value) for t in tokenize('3.5*(1-2)')])"
# → [('NUMBER', 3.5), ('STAR', '*'), ('LPAREN', '('), ('NUMBER', 1), ('MINUS', '-'), ('NUMBER', 2), ('RPAREN', ')'), ('EOF', None)]
python -c "from calc.lexer import tokenize; tokenize('1 @ 2')"
# → calc.lexer.LexError: unexpected character '@' at position 2