-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAST.py
More file actions
135 lines (112 loc) · 3.51 KB
/
AST.py
File metadata and controls
135 lines (112 loc) · 3.51 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
class Node:
def __init__(self, line_no):
self.line_no = line_no
class Program(Node):
def __init__(self, line_no, lines):
super().__init__(line_no)
self.lines = lines
# instrukcje złożone
class Block(Node):
def __init__(self, line_no, lines):
super().__init__(line_no)
self.lines = lines
class FunctionCall(Node):
def __init__(self, line_no, name, arg):
super().__init__(line_no)
self.name = name
self.arg = arg
class UnaryExpr(Node):
def __init__(self, line_no, op, arg):
super().__init__(line_no)
self.op = "MINUS" if op == "-" else "TRANSPOSE"
self.arg = arg
# wyrażenia binarne
class BinaryExpr(Node):
def __init__(self, line_no, op, left, right):
super().__init__(line_no)
self.op = op
self.left = left
self.right = right
class IntNum(Node):
def __init__(self, line_no, value):
super().__init__(line_no)
self.value = int(value)
class FloatNum(Node):
def __init__(self, line_no, value):
super().__init__(line_no)
self.value = float(value)
class String(Node):
def __init__(self, line_no, value):
super().__init__(line_no)
self.value = value
class Vector(Node):
def __init__(self, line_no, values):
super().__init__(line_no)
self.values = values
class Matrix(Node):
def __init__(self, line_no, rows):
super().__init__(line_no)
self.rows = rows
class Id(Node):
def __init__(self, line_no, name):
super().__init__(line_no)
self.name = name
# instrukcje przypisania
class Assignment(Node):
def __init__(self, line_no, op, variable, value):
super().__init__(line_no)
self.op = op
self.variable = variable
self.value = value
# instrukcje warunkowe if-else
class IfStatement(Node):
def __init__(self, line_no, condition, then_branch, else_branch=None):
super().__init__(line_no)
self.condition = condition
self.then_branch = then_branch
self.else_branch = else_branch
# pętle: while oraz for
class WhileStatement(Node):
def __init__(self, line_no, condition, body):
super().__init__(line_no)
self.condition = condition
self.body = body
class Range(Node):
def __init__(self, line_no, start, end):
super().__init__(line_no)
self.start = start
self.end = end
class ForStatement(Node):
def __init__(self, line_no, variable, start, end, body):
super().__init__(line_no)
self.variable = variable
self.range = Range(line_no, start, end)
self.body = body
# instrukcje break, continue oraz return
class BreakStatement(Node):
def __init__(self, line_no):
super().__init__(line_no)
class ContinueStatement(Node):
def __init__(self, line_no):
super().__init__(line_no)
class ReturnStatement(Node):
def __init__(self, line_no, value=None):
super().__init__(line_no)
self.value = value
# instrukcje print
class PrintStatement(Node):
def __init__(self, line_no, values):
super().__init__(line_no)
self.values = values
# tablice oraz ich zakresy
class MatrixRefference(Node):
def __init__(self, line_no, variable, reffs):
super().__init__(line_no)
self.variable = variable
self.reffs = reffs
class Condition(Node):
def __init__(self, line_no, op, left, right):
super().__init__(line_no)
self.op = op
self.left = left
self.right = right