feat: Add numbers and arithmetic operations

This commit is contained in:
Alvin
2025-07-22 16:12:23 +02:00
parent ad1d46b6e7
commit 735ae8e068
4 changed files with 95 additions and 13 deletions

View File

@@ -38,6 +38,25 @@ class Lexer:
self.pos = string_end + 1
return Token('STRING', string)
if current_char.isdigit():
start_pos = self.pos
while self.pos < len(self.text) and self.text[self.pos].isdigit():
self.pos += 1
return Token('INTEGER', int(self.text[start_pos:self.pos]))
if current_char == '+':
self.pos += 1
return Token('PLUS', '+')
if current_char == '-':
self.pos += 1
return Token('MINUS', '-')
if current_char == '*':
self.pos += 1
return Token('MUL', '*')
if current_char == '/':
self.pos += 1
return Token('DIV', '/')
# Match keywords
if re.match(r'\bUwU Boy\b', self.text[self.pos:]):
self.pos += 7