-
Notifications
You must be signed in to change notification settings - Fork 0
/
ast_nodes.py
52 lines (40 loc) · 1.3 KB
/
ast_nodes.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
class ASTNode:
pass
class NumberNode(ASTNode):
def __init__(self, value):
self.value = value
def __repr__(self):
return f"NumberNode({self.value})"
class IdentifierNode(ASTNode):
def __init__(self, name):
self.name = name
def __repr__(self):
return f"IdentifierNode({self.name})"
class BinaryOpNode(ASTNode):
def __init__(self, left, operator, right):
self.left = left
self.operator = operator
self.right = right
def __repr__(self):
return f"BinaryOpNode({self.left}, {self.operator}, {self.right})"
class AssignmentNode(ASTNode):
def __init__(self, identifier, value):
self.identifier = identifier
self.value = value
def __repr__(self):
return f"AssignmentNode({self.identifier}, {self.value})"
class IfNode(ASTNode):
def __init__(self, condition, body):
self.condition = condition
self.body = body
def __repr__(self):
return f"IfNode({self.condition}, {self.body})"
class WhileNode(ASTNode):
def __init__(self, condition, body):
self.condition = condition
self.body = body
def __repr__(self):
return f"WhileNode({self.condition}, {self.body})"
class PrintNode(ASTNode):
def __init__(self, value):
self.value = value