-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoken.py
More file actions
43 lines (35 loc) · 698 Bytes
/
token.py
File metadata and controls
43 lines (35 loc) · 698 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
37
38
39
40
41
42
43
tokentype = {
'INT': 'INT',
'FLOAT': 'FLOAT',
'STRING': 'STRING',
'CHAR': 'CHAR',
'+': 'PLUS',
'-': 'MINUS',
'*': 'MUL',
'/': 'DIV',
'=': 'ASSIGN',
'%': 'MODULO',
':': 'COLON',
';': 'SEMICOLON',
'<': 'LT',
'>': 'GT',
'[': 'O_BRACKET',
']': 'C_BRACKET',
'(': 'O_PAREN',
')': 'C_PAREN',
'{': 'O_BRACE',
'}': 'C_BRACE',
'&': 'AND',
'|': 'OR',
'!': 'NOT',
'^': 'EXPO',
'ID': 'ID',
'EOF': 'EOF'
}
class Token:
def __init__(self, type, value):
self.type = type
self.value = value
def __str__(self):
return f'<{self.type}: {self.value}>'
__repr__ = __str__