-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_model.py
174 lines (99 loc) · 3.14 KB
/
parse_model.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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
class Program:
def __init__(self, elem=None, program=None):
if program is not None:
self.elements = program.elements
else:
self.elements = []
if elem is not None:
self.elements.append(elem)
class Literal:
def __init__(self, value):
self.value = value
def __str__(self):
return self.value
class Identifier:
def __init__(self, value):
self.value = value
def __str__(self):
return self.value
class AttributeRef:
def __init__(self, left_val, right_val):
self.left_val = left_val
self.right_val = right_val
class UnaryExpression:
def __init__(self, value, operator):
self.value = value
self.operator = operator
class BinaryExpression:
def __init__(self, op1, operator, op2):
self.op1 = op1
self.op2 = op2
self.operator = operator
class ConditionalExpression:
def __init__(self, success, requirement, failure):
self.success = success
self.requirement = requirement
self.failure = failure
class Call:
def __init__(self, caller, arguments):
self.caller = caller
self.arguments = arguments
class Assignment:
def __init__(self, target, expression):
self.target = target
self.expression = expression
class AugmentedAssignment:
def __init__(self, target, operator, expression):
self.target = target
self.operator = operator
self.expression = expression
class PassStmt:
def __init__(self): pass
class PrintStmt:
def __init__(self, arguments):
self.arguments = arguments
class ReturnStmt:
def __init__(self, expression=None):
self.expression = expression
class BreakStmt:
def __init__(self): pass
class ContinueStmt:
def __init__(self): pass
class ImportStmt:
def __init__(self, module_to_import):
self.module = module_to_import
class StmtList:
def __init__(self, first_statement=None):
if first_statement is None:
self.statement_list = []
else:
self.statement_list = [first_statement]
def add_stmt(self, new_stmt):
self.statement_list.append(new_stmt)
class IndentedStmtList:
def __init__(self, first_statement=None):
if first_statement is None:
self.statement_list = []
else:
self.statement_list = [first_statement]
def add_stmt(self, new_stmt):
self.statement_list.append(new_stmt)
class WhileStmt:
def __init__(self, condition, suite, else_suite=None):
self.condition = condition
self.suite = suite
self.else_suite = else_suite
class IfStmt:
def __init__(self, condition_suite_blocks, else_suite=None):
self.blocks = condition_suite_blocks
self.else_suite = else_suite
class FuncDef:
def __init__(self, name, parameters, suite):
self.name = name
self.parameters = parameters
self.suite = suite
class ClassDef:
def __init__(self, name, parent, methods):
self.name = name
self.parent = parent
self.methods = methods