-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToken.py
More file actions
23 lines (19 loc) · 678 Bytes
/
Token.py
File metadata and controls
23 lines (19 loc) · 678 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
INTEGER, PLUS, MINUS, DIVIDE, MULTIPLY, EOF = 'INTEGER', 'PLUS', 'MINUS','DIVIDE', 'MULTIPLY', 'EOF'
class Token(object):
def __init__(self, type, value):
# token type: INTEGER, PLUS, MINUS, or EOF
self.type = type
# token value: non-negative integer value, '+', '-', or None
self.value = value
def __str__(self):
"""String representation of the class instance.
Examples:
Token(INTEGER, 3)
Token(PLUS, '+')
"""
return 'Token({type}, {value})'.format(
type=self.type,
value=repr(self.value)
)
def __repr__(self):
return self.__str__()