-
Notifications
You must be signed in to change notification settings - Fork 52
/
token.py
executable file
·49 lines (44 loc) · 1.3 KB
/
token.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
#Scott Snow
#Comp 141, Homework 7
#Python Calculator (calculator.py)
class TokenType:
NUMBER_TOKEN = 'NUMBER_TOKEN'
OPERATOR_TOKEN = 'OPERATOR_TOKEN'
PAREN_TOKEN = 'PAREN_TOKEN'
#Python Calculator (token.py)
#Abstract base class to be extended by other token classes
class Token:
def __init__(self):
pass
def getType(self):
return 0
#This class extends the base Token class
#Stores a real number
class NumberToken(Token):
def __init__(self, value):
Token.__init__(self)
self.value = value
def getType(self):
return TokenType.NUMBER_TOKEN
def getValue(self):
return self.value
#This class extends the base Token class
#Stores an operator as a single character
class OperatorToken(Token):
def __init__(self, value):
Token.__init__(self)
self.value = value
def getType(self):
return TokenType.OPERATOR_TOKEN
def getValue(self):
return self.value
#This class extends the base Token class
#Stores parentheses as a single character
class ParenToken(Token):
def __init__(self, value):
Token.__init__(self)
self.value = value
def getType(self):
return TokenType.PAREN_TOKEN
def getValue(self):
return self.value