-
Notifications
You must be signed in to change notification settings - Fork 0
/
ast_iki.py
117 lines (86 loc) · 2.63 KB
/
ast_iki.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
class IKINode:
def __init__(self):
self.name = "IKINode"
def accept(self, visitor, parent=None):
method_name = 'visit_' + self.name
visitor_method = getattr(visitor, method_name)
return visitor_method(self, parent)
class Program(IKINode):
def __init__(self, block):
super().__init__()
self.name = "Program"
self.block = block
class Block(IKINode):
def __init__(self, statements):
super().__init__()
self.name = "Block"
self.statements = statements
class Statement(IKINode):
def __init__(self):
super().__init__()
self.name = "Statement"
class Declaration(Statement):
def __init__(self, variable, type_):
super().__init__()
self.name = "Declaration"
self.variable = variable
self.type_ = type_
class Assignment(Statement):
def __init__(self, var_exp, exp):
super().__init__()
self.name = "Assignment"
self.var_exp = var_exp
self.exp = exp
class Read(Statement):
def __init__(self, var_exps):
super().__init__()
self.name = "Read"
self.var_exps = var_exps
class Write(Statement):
def __init__(self, exps):
super().__init__()
self.name = "Write"
self.exps = exps
class WhileLoop(Statement):
def __init__(self, exp, block):
super().__init__()
self.name = "WhileLoop"
self.exp = exp
self.block = block
class Expression(IKINode):
def __init__(self):
super().__init__()
self.name = "Expression"
class BinaryOperator(Expression):
def __init__(self, operator, left_operand, right_operand):
super().__init__()
self.name = "BinaryOperator"
self.operator = operator
self.left_operand = left_operand
self.right_operand = right_operand
class UnaryOperator(Expression):
def __init__(self, operator, operand):
super().__init__()
self.name = "UnaryOperator"
self.operator = operator
self.operand = operand
class Literal(Expression):
def __init__(self, value):
super().__init__()
self.name = "Literal"
self.value = value
class VarExp(Expression):
def __init__(self, identifier):
super().__init__()
self.name = "VarExp"
self.identifier = identifier
class Identifier(IKINode):
def __init__(self, name):
super().__init__()
self.name = "Identifier"
self.identifier_name = name
class Type(IKINode):
def __init__(self, type_name):
super().__init__()
self.name = "Type"
self.type_name = type_name