Skip to content

AST

AST classes and functions.

BinaryExprAST

Bases: ExprAST

AST class for the binary operator.

Source code in src/arx/ast.py
131
132
133
134
135
136
137
138
139
140
141
142
class BinaryExprAST(ExprAST):
    """AST class for the binary operator."""

    def __init__(
        self, loc: SourceLocation, op: str, lhs: ExprAST, rhs: ExprAST
    ) -> None:
        """Initialize the BinaryExprAST instance."""
        super().__init__(loc)
        self.op = op
        self.lhs = lhs
        self.rhs = rhs
        self.kind = ExprKind.BinaryOpKind

__init__(loc, op, lhs, rhs)

Initialize the BinaryExprAST instance.

Source code in src/arx/ast.py
134
135
136
137
138
139
140
141
142
def __init__(
    self, loc: SourceLocation, op: str, lhs: ExprAST, rhs: ExprAST
) -> None:
    """Initialize the BinaryExprAST instance."""
    super().__init__(loc)
    self.op = op
    self.lhs = lhs
    self.rhs = rhs
    self.kind = ExprKind.BinaryOpKind

BlockAST

Bases: ExprAST

The AST tree.

Source code in src/arx/ast.py
70
71
72
73
74
75
76
77
78
class BlockAST(ExprAST):
    """The AST tree."""

    nodes: List[ExprAST]

    def __init__(self) -> None:
        """Initialize the BlockAST instance."""
        super().__init__()
        self.nodes: List[ExprAST] = []

__init__()

Initialize the BlockAST instance.

Source code in src/arx/ast.py
75
76
77
78
def __init__(self) -> None:
    """Initialize the BlockAST instance."""
    super().__init__()
    self.nodes: List[ExprAST] = []

CallExprAST

Bases: ExprAST

AST class for function call.

Source code in src/arx/ast.py
145
146
147
148
149
150
151
152
153
154
155
class CallExprAST(ExprAST):
    """AST class for function call."""

    def __init__(
        self, loc: SourceLocation, callee: str, args: List[ExprAST]
    ) -> None:
        """Initialize the CallExprAST instance."""
        super().__init__(loc)
        self.callee = callee
        self.args = args
        self.kind = ExprKind.CallKind

__init__(loc, callee, args)

Initialize the CallExprAST instance.

Source code in src/arx/ast.py
148
149
150
151
152
153
154
155
def __init__(
    self, loc: SourceLocation, callee: str, args: List[ExprAST]
) -> None:
    """Initialize the CallExprAST instance."""
    super().__init__(loc)
    self.callee = callee
    self.args = args
    self.kind = ExprKind.CallKind

ExprAST

AST main expression class.

Source code in src/arx/ast.py
58
59
60
61
62
63
64
65
66
67
class ExprAST:
    """AST main expression class."""

    loc: SourceLocation
    kind: ExprKind

    def __init__(self, loc: SourceLocation = SourceLocation(0, 0)) -> None:
        """Initialize the ExprAST instance."""
        self.kind = ExprKind.GenericKind
        self.loc = loc

__init__(loc=SourceLocation(0, 0))

Initialize the ExprAST instance.

Source code in src/arx/ast.py
64
65
66
67
def __init__(self, loc: SourceLocation = SourceLocation(0, 0)) -> None:
    """Initialize the ExprAST instance."""
    self.kind = ExprKind.GenericKind
    self.loc = loc

ExprKind

Bases: Enum

The expression kind class used for downcasting.

Source code in src/arx/ast.py
 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
class ExprKind(Enum):
    """The expression kind class used for downcasting."""

    GenericKind = -1
    ModuleKind = -2

    # variables
    VariableKind = -10
    VarKind = -11  # var keyword for variable declaration

    # operators
    UnaryOpKind = -20
    BinaryOpKind = -21

    # functions
    PrototypeKind = -30
    FunctionKind = -31
    CallKind = -32
    ReturnKind = -33

    # control flow
    IfKind = -40
    ForKind = -41

    # data types
    NullDTKind = -100
    BooleanDTKind = -101
    Int8DTKind = -102
    UInt8DTKind = -103
    Int16DTKind = -104
    UInt16DTKind = -105
    Int32DTKind = -106
    UInt32DTKind = -107
    Int64DTKind = -108
    UInt64DTKind = -109
    FloatDTKind = -110
    DoubleDTKind = -111
    BinaryDTKind = -112
    StringDTKind = -113
    FixedSizeBinaryDTKind = -114
    Date32DTKind = -115
    Date64DTKind = -116
    TimestampDTKind = -117
    Time32DTKind = -118
    Time64DTKind = -119
    Decimal128DTKind = -120
    Decimal256DTKind = -121

FloatExprAST

Bases: ExprAST

AST for the literal float number.

Source code in src/arx/ast.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
class FloatExprAST(ExprAST):
    """AST for the literal float number."""

    value: float

    def __init__(self, val: float) -> None:
        """Initialize the FloatAST instance."""
        super().__init__()
        self.value = val
        self.kind = ExprKind.FloatDTKind

__init__(val)

Initialize the FloatAST instance.

Source code in src/arx/ast.py
 98
 99
100
101
102
def __init__(self, val: float) -> None:
    """Initialize the FloatAST instance."""
    super().__init__()
    self.value = val
    self.kind = ExprKind.FloatDTKind

ForStmtAST

Bases: ExprAST

AST class for For statement.

Source code in src/arx/ast.py
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
class ForStmtAST(ExprAST):
    """AST class for `For` statement."""

    var_name: str
    start: ExprAST
    end: ExprAST
    step: ExprAST
    body: BlockAST

    def __init__(
        self,
        var_name: str,
        start: ExprAST,
        end: ExprAST,
        step: ExprAST,
        body: BlockAST,
    ) -> None:
        """Initialize the ForStmtAST instance."""
        super().__init__()
        self.var_name = var_name
        self.start = start
        self.end = end
        self.step = step
        self.body = body
        self.kind = ExprKind.ForKind

__init__(var_name, start, end, step, body)

Initialize the ForStmtAST instance.

Source code in src/arx/ast.py
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
def __init__(
    self,
    var_name: str,
    start: ExprAST,
    end: ExprAST,
    step: ExprAST,
    body: BlockAST,
) -> None:
    """Initialize the ForStmtAST instance."""
    super().__init__()
    self.var_name = var_name
    self.start = start
    self.end = end
    self.step = step
    self.body = body
    self.kind = ExprKind.ForKind

FunctionAST

Bases: ExprAST

AST class for function definition.

Source code in src/arx/ast.py
267
268
269
270
271
272
273
274
275
276
277
278
class FunctionAST(ExprAST):
    """AST class for function definition."""

    proto: PrototypeAST
    body: BlockAST

    def __init__(self, proto: PrototypeAST, body: BlockAST) -> None:
        """Initialize the FunctionAST instance."""
        super().__init__()
        self.proto = proto
        self.body = body
        self.kind = ExprKind.FunctionKind

__init__(proto, body)

Initialize the FunctionAST instance.

Source code in src/arx/ast.py
273
274
275
276
277
278
def __init__(self, proto: PrototypeAST, body: BlockAST) -> None:
    """Initialize the FunctionAST instance."""
    super().__init__()
    self.proto = proto
    self.body = body
    self.kind = ExprKind.FunctionKind

IfStmtAST

Bases: ExprAST

AST class for if statement.

Source code in src/arx/ast.py
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
class IfStmtAST(ExprAST):
    """AST class for `if` statement."""

    cond: ExprAST
    then_: BlockAST
    else_: BlockAST

    def __init__(
        self,
        loc: SourceLocation,
        cond: ExprAST,
        then_: BlockAST,
        else_: BlockAST,
    ) -> None:
        """Initialize the IfStmtAST instance."""
        super().__init__(loc)
        self.cond = cond
        self.then_ = then_
        self.else_ = else_
        self.kind = ExprKind.IfKind

__init__(loc, cond, then_, else_)

Initialize the IfStmtAST instance.

Source code in src/arx/ast.py
165
166
167
168
169
170
171
172
173
174
175
176
177
def __init__(
    self,
    loc: SourceLocation,
    cond: ExprAST,
    then_: BlockAST,
    else_: BlockAST,
) -> None:
    """Initialize the IfStmtAST instance."""
    super().__init__(loc)
    self.cond = cond
    self.then_ = then_
    self.else_ = else_
    self.kind = ExprKind.IfKind

ModuleAST

Bases: BlockAST

AST main expression class.

Source code in src/arx/ast.py
81
82
83
84
85
86
87
88
89
90
class ModuleAST(BlockAST):
    """AST main expression class."""

    name: str

    def __init__(self, name: str) -> None:
        """Initialize the ExprAST instance."""
        super().__init__()
        self.name = name
        self.kind = ExprKind.ModuleKind

__init__(name)

Initialize the ExprAST instance.

Source code in src/arx/ast.py
86
87
88
89
90
def __init__(self, name: str) -> None:
    """Initialize the ExprAST instance."""
    super().__init__()
    self.name = name
    self.kind = ExprKind.ModuleKind

PrototypeAST

Bases: ExprAST

AST class for function prototype declaration.

Source code in src/arx/ast.py
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
class PrototypeAST(ExprAST):
    """AST class for function prototype declaration."""

    name: str
    args: List[VariableExprAST]
    type_name: str

    def __init__(
        self,
        loc: SourceLocation,
        name: str,
        type_name: str,
        args: List[VariableExprAST],
    ) -> None:
        """Initialize the PrototypeAST instance."""
        super().__init__()
        self.name = name
        self.args = args
        self.type_name = type_name
        self.line = loc.line
        self.kind = ExprKind.PrototypeKind

    def get_name(self) -> str:
        """Return the prototype name."""
        return self.name

__init__(loc, name, type_name, args)

Initialize the PrototypeAST instance.

Source code in src/arx/ast.py
235
236
237
238
239
240
241
242
243
244
245
246
247
248
def __init__(
    self,
    loc: SourceLocation,
    name: str,
    type_name: str,
    args: List[VariableExprAST],
) -> None:
    """Initialize the PrototypeAST instance."""
    super().__init__()
    self.name = name
    self.args = args
    self.type_name = type_name
    self.line = loc.line
    self.kind = ExprKind.PrototypeKind

get_name()

Return the prototype name.

Source code in src/arx/ast.py
250
251
252
def get_name(self) -> str:
    """Return the prototype name."""
    return self.name

ReturnStmtAST

Bases: ExprAST

AST class for function return statement.

Source code in src/arx/ast.py
255
256
257
258
259
260
261
262
263
264
class ReturnStmtAST(ExprAST):
    """AST class for function `return` statement."""

    value: ExprAST

    def __init__(self, value: ExprAST) -> None:
        """Initialize the ReturnStmtAST instance."""
        super().__init__()
        self.value = value
        self.kind = ExprKind.ReturnKind

__init__(value)

Initialize the ReturnStmtAST instance.

Source code in src/arx/ast.py
260
261
262
263
264
def __init__(self, value: ExprAST) -> None:
    """Initialize the ReturnStmtAST instance."""
    super().__init__()
    self.value = value
    self.kind = ExprKind.ReturnKind

UnaryExprAST

Bases: ExprAST

AST class for the unary operator.

Source code in src/arx/ast.py
120
121
122
123
124
125
126
127
128
class UnaryExprAST(ExprAST):
    """AST class for the unary operator."""

    def __init__(self, op_code: str, operand: ExprAST) -> None:
        """Initialize the UnaryExprAST instance."""
        super().__init__()
        self.op_code = op_code
        self.operand = operand
        self.kind = ExprKind.UnaryOpKind

__init__(op_code, operand)

Initialize the UnaryExprAST instance.

Source code in src/arx/ast.py
123
124
125
126
127
128
def __init__(self, op_code: str, operand: ExprAST) -> None:
    """Initialize the UnaryExprAST instance."""
    super().__init__()
    self.op_code = op_code
    self.operand = operand
    self.kind = ExprKind.UnaryOpKind

VarExprAST

Bases: ExprAST

AST class for variable declaration.

Source code in src/arx/ast.py
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
class VarExprAST(ExprAST):
    """AST class for variable declaration."""

    var_names: List[Tuple[str, ExprAST]]
    type_name: str
    body: ExprAST

    def __init__(
        self,
        var_names: List[Tuple[str, ExprAST]],
        type_name: str,
        body: ExprAST,
    ) -> None:
        """Initialize the VarExprAST instance."""
        super().__init__()
        self.var_names = var_names
        self.type_name = type_name
        self.body = body
        self.kind = ExprKind.VarKind

__init__(var_names, type_name, body)

Initialize the VarExprAST instance.

Source code in src/arx/ast.py
214
215
216
217
218
219
220
221
222
223
224
225
def __init__(
    self,
    var_names: List[Tuple[str, ExprAST]],
    type_name: str,
    body: ExprAST,
) -> None:
    """Initialize the VarExprAST instance."""
    super().__init__()
    self.var_names = var_names
    self.type_name = type_name
    self.body = body
    self.kind = ExprKind.VarKind

VariableExprAST

Bases: ExprAST

AST class for the variable usage.

Source code in src/arx/ast.py
105
106
107
108
109
110
111
112
113
114
115
116
117
class VariableExprAST(ExprAST):
    """AST class for the variable usage."""

    def __init__(self, loc: SourceLocation, name: str, type_name: str) -> None:
        """Initialize the VariableExprAST instance."""
        super().__init__(loc)
        self.name = name
        self.type_name = type_name
        self.kind = ExprKind.VariableKind

    def get_name(self) -> str:
        """Return the variable name."""
        return self.name

__init__(loc, name, type_name)

Initialize the VariableExprAST instance.

Source code in src/arx/ast.py
108
109
110
111
112
113
def __init__(self, loc: SourceLocation, name: str, type_name: str) -> None:
    """Initialize the VariableExprAST instance."""
    super().__init__(loc)
    self.name = name
    self.type_name = type_name
    self.kind = ExprKind.VariableKind

get_name()

Return the variable name.

Source code in src/arx/ast.py
115
116
117
def get_name(self) -> str:
    """Return the variable name."""
    return self.name