-
Notifications
You must be signed in to change notification settings - Fork 1
/
Operator.py
32 lines (27 loc) · 857 Bytes
/
Operator.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
class Operator:
"""An operator class"""
allOperators = []
def __init__(self, associativity, symbol, precedence, operands):
# left (l) or right (r)
self.ass = associativity
self.sym = symbol
self.pre = precedence
self.ops = operands
Operator.allOperators.append(self)
plus = Operator("l", "+", 1, 2)
minus = Operator("l", "-", 1, 2)
divide = Operator("l", "/", 2, 2)
modulus = Operator("l", "%", 2, 2)
multiply = Operator("l", "*", 2, 2)
power_of = Operator("r", "^", 3, 2)
left_paran = Operator("l", "(", -1, 0)
right_paran = Operator("l", ")", -1, 0)
def is_op(symbol):
for op in Operator.allOperators:
if op.sym == symbol:
return True
return False
def find(symbol):
for op in Operator.allOperators:
if op.sym == symbol:
return op