-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathast_nodes.rb
More file actions
326 lines (261 loc) · 5.42 KB
/
Copy pathast_nodes.rb
File metadata and controls
326 lines (261 loc) · 5.42 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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
class ASTNode
attr_accessor :line
def initialize(line = nil)
@line = line
end
end
class ProgramNode < ASTNode
attr_accessor :statements
def initialize
super
@statements = []
end
end
class SetStatement < ASTNode
attr_accessor :variable, :value
def initialize(variable, value)
super()
@variable = variable
@value = value
end
end
class PrintStatement < ASTNode
attr_accessor :expression
def initialize(expression)
super()
@expression = expression
end
end
class IfStatement < ASTNode
attr_accessor :condition, :if_body, :elsif_branches, :else_body
def initialize(condition, if_body, elsif_branches = [], else_body = [])
super()
@condition = condition
@if_body = if_body
@elsif_branches = elsif_branches
@else_body = else_body
end
end
class WhileStatement < ASTNode
attr_accessor :condition, :body
def initialize(condition, body)
super()
@condition = condition
@body = body
end
end
class ForStatement < ASTNode
attr_accessor :variable, :start_value, :end_value, :body
def initialize(variable, start_value, end_value, body)
super()
@variable = variable
@start_value = start_value
@end_value = end_value
@body = body
end
end
class ClassDefinition < ASTNode
attr_accessor :name, :attributes, :methods
def initialize(name, attributes)
super()
@name = name
@attributes = attributes
@methods = {}
end
end
class MethodDefinition < ASTNode
attr_accessor :name, :class_name, :parameters, :body
def initialize(name, class_name, parameters, body)
super()
@name = name
@class_name = class_name
@parameters = parameters
@body = body
end
end
class FunctionDefinition < ASTNode
attr_accessor :name, :parameters, :body
def initialize(name, parameters, body)
super()
@name = name
@parameters = parameters
@body = body
end
end
class TryCatchStatement < ASTNode
attr_accessor :try_body, :catch_body
def initialize(try_body, catch_body)
super()
@try_body = try_body
@catch_body = catch_body
end
end
class ReturnStatement < ASTNode
attr_accessor :expression
def initialize(expression)
super()
@expression = expression
end
end
class BreakStatement < ASTNode
end
class ContinueStatement < ASTNode
end
class NewInstance < ASTNode
attr_accessor :class_name, :arguments
def initialize(class_name, arguments)
super()
@class_name = class_name
@arguments = arguments
end
end
class CallExpression < ASTNode
attr_accessor :name, :object, :arguments
def initialize(name, object = nil, arguments = [])
super()
@name = name
@object = object
@arguments = arguments
end
end
class GetAttribute < ASTNode
attr_accessor :attribute, :object
def initialize(attribute, object)
super()
@attribute = attribute
@object = object
end
end
class SetAttribute < ASTNode
attr_accessor :attribute, :object, :value
def initialize(attribute, object, value)
super()
@attribute = attribute
@object = object
@value = value
end
end
class BinaryOperation < ASTNode
attr_accessor :left, :operator, :right
def initialize(left, operator, right)
super()
@left = left
@operator = operator
@right = right
end
end
class UnaryOperation < ASTNode
attr_accessor :operator, :operand
def initialize(operator, operand)
super()
@operator = operator
@operand = operand
end
end
class Literal < ASTNode
attr_accessor :value
def initialize(value)
super()
@value = value
end
end
class Variable < ASTNode
attr_accessor :name
def initialize(name)
super()
@name = name
end
end
class ArrayLiteral < ASTNode
attr_accessor :elements
def initialize(elements)
super()
@elements = elements
end
end
class DictionaryLiteral < ASTNode
attr_accessor :entries
def initialize(entries)
super()
@entries = entries
end
end
class PushStatement < ASTNode
attr_accessor :value, :array
def initialize(value, array)
super()
@value = value
@array = array
end
end
class PopStatement < ASTNode
attr_accessor :array
def initialize(array)
super()
@array = array
end
end
class SetIndexStatement < ASTNode
attr_accessor :index, :array, :value
def initialize(index, array, value)
super()
@index = index
@array = array
@value = value
end
end
class DictionarySetStatement < ASTNode
attr_accessor :key, :dictionary, :value
def initialize(key, dictionary, value)
super()
@key = key
@dictionary = dictionary
@value = value
end
end
class RemoveValueStatement < ASTNode
attr_accessor :value, :array
def initialize(value, array)
super()
@value = value
@array = array
end
end
class LengthExpression < ASTNode
attr_accessor :array
def initialize(array)
super()
@array = array
end
end
class IndexExpression < ASTNode
attr_accessor :index, :array
def initialize(index, array)
super()
@index = index
@array = array
end
end
class DictionaryGetExpression < ASTNode
attr_accessor :key, :dictionary
def initialize(key, dictionary)
super()
@key = key
@dictionary = dictionary
end
end
class IncludesExpression < ASTNode
attr_accessor :value, :array
def initialize(value, array)
super()
@value = value
@array = array
end
end
class InputExpression < ASTNode
attr_accessor :prompt
def initialize(prompt)
super()
@prompt = prompt
end
end