-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnodes.py
34 lines (25 loc) · 779 Bytes
/
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
import tokens
class NumberNode:
def __init__(self, value: float):
self.value = value
def __repr__(self) -> str:
return str(self.value)
class BinaryNode:
def __init__(self, type: str, left_node, right_node):
self.type = type
self.left_node = left_node
self.right_node = right_node
def __repr__(self) -> str:
return (
"("
+ str(self.left_node)
+ tokens.operator_to_character(self.type)
+ str(self.right_node)
+ ")"
)
class UnaryNode:
def __init__(self, type: str, node):
self.type = type
self.node = node
def __repr__(self) -> str:
return "(" + tokens.operator_to_character(self.type) + str(self.node) + ")"