starting work on math instructions and added support for negative numbers and maybe floats
This commit is contained in:
29
tokenizer.py
29
tokenizer.py
@@ -234,7 +234,10 @@ def tokenize(input_string: str):
|
||||
|
||||
if current_char == "\n":
|
||||
traceback(input_string, "SyntaxError", "Expected a type", line, column, column)
|
||||
|
||||
|
||||
is_number = False
|
||||
if current_char in digits:
|
||||
is_number = True
|
||||
|
||||
start_col = column
|
||||
while pos < len(input_string):
|
||||
@@ -246,16 +249,30 @@ def tokenize(input_string: str):
|
||||
line += 1
|
||||
column = 1
|
||||
break
|
||||
if is_number and not current_char in digits+".":
|
||||
traceback(input_string, "SyntaxError", "Malformed number.", line, start_col, column)
|
||||
|
||||
current_token += current_char
|
||||
|
||||
pos += 1
|
||||
column += 1
|
||||
|
||||
tokens.append(Token(
|
||||
TokenType.TYPE,
|
||||
value=current_token
|
||||
))
|
||||
if not is_number:
|
||||
tokens.append(Token(
|
||||
TokenType.TYPE,
|
||||
value=current_token
|
||||
))
|
||||
else:
|
||||
if "." in current_token:
|
||||
tokens.append(Token(
|
||||
TokenType.FLOAT,
|
||||
value=float("-"+current_token)
|
||||
))
|
||||
else:
|
||||
tokens.append(Token(
|
||||
TokenType.INTEGER,
|
||||
value=int("-"+current_token)
|
||||
))
|
||||
|
||||
current_token = ""
|
||||
elif current_char == "@":
|
||||
@@ -423,7 +440,7 @@ def tokenize(input_string: str):
|
||||
#column += 1
|
||||
break
|
||||
|
||||
if not current_char in digits:
|
||||
if not current_char in digits + ".":
|
||||
traceback(input_string, "SyntaxError", "Malformed number.", line, start_col, column)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user