Fixed a negative number bug in the tokenizer; started work on a new calc_engine. Mostly working as of this commit.

This commit is contained in:
2020-04-23 14:12:17 -05:00
parent f3ed00e5f2
commit 4750bed929
2 changed files with 137 additions and 234 deletions
+10 -5
View File
@@ -27,13 +27,18 @@ def get_tokens_from_expression_string(expression_string):
elif c == '-' and not parsing_number:
if expression_string[i + 1] == '.' or expression_string[i + 1].isdigit():
tmp = "-"
parsing_number = True
if tokens[-1].type == token.TokenType.exp_end:
tokens.append(token.Token(c, token.TokenType.get_operator(c)))
parsing_number = False
tmp = ""
else:
tokens.append(token.Token('+', token.TokenType.add))
tmp = "-"
parsing_number = True
else:
tokens.append(token.Token(c, token.TokenType.get_operator(c)))
parsing_number = False
tmp = ""
continue
elif c == '(':
if parsing_number:
@@ -44,7 +49,7 @@ def get_tokens_from_expression_string(expression_string):
tmp = ""
continue
elif c == ')':
if parsing_number:
if parsing_number:
tokens.append(token.Token(tmp, token.TokenType.constant))
tokens.append(token.Token(")", token.TokenType.exp_end))
parsing_number = False
@@ -102,5 +107,5 @@ def replace_variables(tokens, new_constants):
def print_token_list(tokens):
for tk in tokens:
print("%s" %(tk.value), end = "")#, token.TokenType.get_token_type_name(tk.type)), end = "")
print("%s " %(tk.value), end = "")#, token.TokenType.get_token_type_name(tk.type)), end = "")
print()