-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAST.py
More file actions
124 lines (80 loc) · 2.43 KB
/
AST.py
File metadata and controls
124 lines (80 loc) · 2.43 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
class Node(object):
def accept(self, visitor):
result = visitor.visit(self)
return result
def iaccept(self, visitor):
result = visitor.visit(self)
if isinstance(result, list):
if result:
return result[0]
else:
return None
else:
return result
class Identifier(Node):
def __init__(self, identifier):
self.identifier = identifier
class Variable(Node):
def __init__(self, identifier):
self.identifier = identifier
class BinExpr(Node):
def __init__(self, op, left, right):
self.op = op
self.left = left
self.right = right
class Program(Node):
def __init__(self, instructions):
self.instructions = instructions
class Assignment(Node):
def __init__(self, identifier, value):
self.identifier = identifier
self.value = value
class Instructions(Node):
def __init__(self, instruction, instructions):
self.instructions = []
if instruction:
self.instructions.append(instruction)
if instructions:
self.instructions.extend(instructions.instructions)
class Const(Node):
def __init__(self, value):
self.value = value
class Number(Const):
pass
class String(Const):
pass
class Boolean(Const):
pass
class DoubleParenArithmetic(Node):
def __init__(self, expression):
self.expression = expression
class If(Node):
def __init__(self, expression, instructions, elseinstructions):
self.expression = expression
self.instructions = instructions
self.elseinstructions = elseinstructions
class Break(Node):
pass
class Continue(Node):
pass
class While(Node):
def __init__(self, expression, instructions):
self.expression = expression
self.instructions = instructions
class Echo(Node):
def __init__(self, expression):
self.expression = expression
class CommandCall(Node):
def __init__(self, command, switches, arguments):
self.command = command
self.arguments = arguments
self.switches = switches
class CommandSwitch(Node):
def __init__(self, switch):
self.switch = switch
class ArgumentList(Node):
def __init__(self, argument_list):
self.argument_list = argument_list
class SwitchList(Node):
def __init__(self, switch_list):
self.switch_list = switch_list