-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokens.py
48 lines (44 loc) · 802 Bytes
/
tokens.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
from enum import Enum
class TokenType(Enum):
EOF = -1
NEWLINE = 0
NUMBER =1
IDENT = 2
STRING = 3
# Keywords
LABEL = 101
GOTO = 102
PRINT = 103
INPUT = 104
LET = 105
IF = 106
THEN = 107
ENDIF = 108
WHILE = 109
REPEAT = 110
ENDWHILE = 111
#Operators
EQ = 201
PLUS = 202
MINUS = 203
STAR = 204
SLASH = 205
EQEQ = 206
NOTEQ = 207
LT = 208
LTEQ = 209
GT = 210
GTEQ = 211
TOKEN_TYPES: dict[str, TokenType] = {
"+": TokenType.PLUS,
"-": TokenType.MINUS,
"*": TokenType.STAR,
"/": TokenType.SLASH,
"<": TokenType.LT,
">": TokenType.GT,
"<=": TokenType.LTEQ,
">=": TokenType.GTEQ,
"=": TokenType.EQ,
"==": TokenType.EQEQ,
"!=": TokenType.NOTEQ,
}