A quick and hacky fix for main.py to make use of the new Parser object. Also, switched back to using a JSON file for input, can easily be swapped back though.

This commit is contained in:
2020-07-24 11:15:47 -05:00
parent 3cab3f03e8
commit a1c260d0fa
4 changed files with 56 additions and 22 deletions
+14
View File
@@ -34,15 +34,29 @@ class Parser:
def __init__(self, tokens):
if len(tokens) == 0:
raise ValueError("Token list can't be empty")
self.bak = deque()
self.variables = {}
self.tokens = tokens
self.current_token = None
self.advance_current_token()
self.ast = self.generate_ast()
def get_tokens(self):
new_list = []
for t in self.bak:
if t.type == token.TokenType.variable:
if t.value in self.variables:
new_list.append(token.Token(self.variables[t.value], token.TokenType.constant))
else:
new_list.append(token.Token(t.value, t.type))
return new_list
def advance_current_token(self):
if len(self.tokens) > 0:
if self.current_token != None: self.bak.append(self.current_token)
self.current_token = self.tokens.popleft()
def factor(self):