diff options
| author | mryouse | 2022-05-10 03:12:57 +0000 |
|---|---|---|
| committer | mryouse | 2022-05-10 03:12:57 +0000 |
| commit | 5770838213b7b1eec90642c47c94cf730d35726f (patch) | |
| tree | c00ad8fc1b6b7d931a049289177906d376dccea7 /lexer.py | |
| parent | 3e70f2ce47ee954640df9ee3b432964c1111b5ed (diff) | |
add '+' functions, fix lexer so they're not numeric
Diffstat (limited to 'lexer.py')
| -rw-r--r-- | lexer.py | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -125,6 +125,15 @@ def lex(inp, tokens): return lex(inp[1:], tokens) # numbers elif nxt in list(DIGITS) or nxt in ("+", "-", "."): + # + and - are symbols, too + if nxt in ("+", "-"): + after = peek(inp[1:]) + if after not in DIGITS: # parse a symbol + token, remainder = lex_symbol(inp) + if peek(remainder) not in (None, CLOSE_PAREN, " "): + raise Exception("spaces required between tokens") + tokens.append(token) + return lex(remainder, tokens) token, remainder = lex_number(inp) tokens.append(token) return lex(remainder, tokens) |
