-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparser_nodes.py
80 lines (60 loc) · 2.15 KB
/
parser_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
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
"""This module contains the classes for the nodes of the abstract syntax tree (AST) of the parser."""
class Node:
"""Base class for all nodes in the AST."""
pass
class IndentationNode(Node):
"""Class for nodes that represent indentation."""
def __init__(self, value):
self.value = value
class ExpressionNode(Node):
"""Class for nodes that represent expressions, such as mathematical operations."""
def __init__(self, left, operator, right):
self.left = left
self.operator = operator
self.right = right
def __repr__(self):
return f"ExpressionNode({self.left}, {self.operator}, {self.right})"
def __str__(self):
return self.__repr__()
class NumberNode(Node):
"""Class for nodes that represent numbers (int)."""
def __init__(self, value):
self.value = value
def __repr__(self):
return f"NumberNode({self.value})"
def __str__(self):
return self.__repr__()
class StringNode(Node):
"""Class for nodes that represent strings (str)."""
def __init__(self, value):
self.value = value
def __repr__(self):
return f"StringNode({self.value})"
def __str__(self):
return self.__repr__()
class IfNode(Node):
"""Class for nodes that represent if statements."""
def __init__(self, condition, body):
self.condition = condition
self.body = body
def __repr__(self):
return f"IfNode({self.condition}, {self.body})"
def __str__(self):
return self.__repr__()
class AssignmentNode(Node):
"""Class for nodes that represent variable assignments."""
def __init__(self, identifier, value):
self.identifier = identifier
self.value = value
def __repr__(self):
return f"AssignmentNode({self.identifier}, {self.value})"
def __str__(self):
return self.__repr__()
class CellReferenceNode(Node):
"""Class for nodes that represent cell references."""
def __init__(self, value):
self.value = value
def __repr__(self):
return f"CellReferenceNode({self.value})"
def __str__(self):
return self.__repr__()