-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoken.py
More file actions
36 lines (31 loc) · 744 Bytes
/
Copy pathtoken.py
File metadata and controls
36 lines (31 loc) · 744 Bytes
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
#!/usr/bin/env python3
INTEGER = 'INTEGER'
PLUS = 'PLUS'
MINUS = 'MINUS'
MUL = 'TIMES'
DIV = 'DIVIDED_BY'
LPAREN = '('
RPAREN = ')'
EOF = 'EOF'
OPS = {
'+': PLUS,
'-': MINUS,
'*': MUL,
'/': DIV,
'(': LPAREN,
')': RPAREN
}
class Token(object):
def __init__(self, type, value):
# token type: INTEGER, PLUS, MINUS, EOF
self.type = type
# token value: [0-9+] or None
self.value = value
def __str__(self):
'''String representation of the instance.'''
return 'Token({type}, {value})'.format(
type=self.type,
value=repr(self.value)
)
def __repr__(self):
return self.__str__()