Updated the tokenizer to include a method to replace variable tokens with the values provided in a list.

This commit is contained in:
2020-04-13 09:10:14 -05:00
parent 7605bcdf68
commit c75905d13c
3 changed files with 25 additions and 14 deletions
+10 -4
View File
@@ -69,10 +69,16 @@ def get_tokens_from_expression_string(expression_string):
tokens.append(token.CToken(c + str(symbols_dic[c]), token.TokenType.variable))
parsing_number = False
tmp = ""
#When building this list we've effectively ordered the tokens in reverse order from how we want to
#process them. So, reverse the order of the list before returning them to the caller, we don't want
#the caller to have to worry about such a minor detail.
tokens.reverse()
return tokens
def replace_variables(tokens, new_constants):
newTokenList = []
for t in tokens:
if t.type == token.TokenType.variable:
newTokenList.append(token.CToken(new_constants.pop(0), token.TokenType.constant))
else:
newTokenList.append(t)
return newTokenList