-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathengparser.py
48 lines (34 loc) · 1.32 KB
/
engparser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from engnode import *
class EngParser:
def parsetokens(self, tokens):
nodelst = []
for token in tokens:
if(token.type == "display"):
nodelst.append(self.parseDisplay(token.val[0]))
elif(token.type == "simpleassign"):
nodelst.append(self.parseSimpleAssign(token.var, token.val[0]))
elif(token.type == "numericcomparativeassign"):
nodelst.append(self.parseNumericComparativeAssign(token.var, token.val))
elif(token.type == "evaluatedassign"):
nodelst.append(self.parseEvaluatedAssign(token.var, token.val))
elif(token.type == "jump"):
nodelst.append(self.parseJump(token.val))
elif(token.type == "end"):
nodelst.append(EndNode())
else:
print("Error unknown Type Parser")
raise ValueError
return nodelst
def parseDisplay(self, displayval):
return DisplayNode(displayval)
def parseSimpleAssign(self, var, value):
return SimpleAssignNode(var, value)
def parseNumericComparativeAssign(self, var, value):
if(len(value) == 5): #Is equal to
return EvaluatedAssignNode(var, value[0], "equals", value[-1])
else: #is not equal to
return EvaluatedAssignNode(var, value[0], "!equals", value[-1])
def parseEvaluatedAssign(self, var, value):
return EvaluatedAssignNode(var, value[0], value[1], value[2])
def parseJump(self, value):
return JumpNode(value[0], value[-1])