Fixed a bug in the calc_engine where an expression '(a)^(b), where 'a' and 'b' are any float, would cause a crash and patched the tokenizer to better handle negative numbers.

This commit is contained in:
2020-04-24 02:22:05 -05:00
parent 85d61366a7
commit d93de4d3d6
2 changed files with 24 additions and 15 deletions
+8 -3
View File
@@ -27,14 +27,19 @@ 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():
if tokens[-1].type == token.TokenType.exp_end:
if token.TokenType.get_operator(tokens[-1].value) == token.TokenType.unknown:#tokens[-1].type == token.TokenType
print(tokens[-1].value)
tokens.append(token.Token('+', token.TokenType.add))
parsing_number = True
tmp = "-"
'''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))
#tokens.append(token.Token('+', token.TokenType.add))
tmp = "-"
parsing_number = True
parsing_number = True'''
else:
tokens.append(token.Token(c, token.TokenType.get_operator(c)))
parsing_number = False