-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokens.py
63 lines (54 loc) · 1.18 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from enum import Enum, auto
class Token:
def __init__(self, type_, lexeme, literal, line):
self.type_ = type_
self.lexeme = lexeme
self.literal = literal
self.line = line
def __repr__(self):
return f"{self.type_} {self.lexeme} {self.literal}"
class TokenType(Enum):
# single-character tokens
LEFT_PAREN = auto()
RIGHT_PAREN = auto()
LEFT_BRACE = auto()
RIGHT_BRACE = auto()
COMMA = auto()
DOT = auto()
MINUS = auto()
PLUS = auto()
SEMICOLON = auto()
SLASH = auto()
STAR = auto()
# one or two character tokens
BANG = auto()
BANG_EQUAL = auto()
EQUAL = auto()
EQUAL_EQUAL = auto()
GREATER = auto()
GREATER_EQUAL = auto()
LESS = auto()
LESS_EQUAL = auto()
# literals
IDENTIFIER = auto()
STRING = auto()
NUMBER = auto()
# keywords
AND = auto()
BREAK = auto()
CLASS = auto()
ELSE = auto()
FALSE = auto()
FUN = auto()
FOR = auto()
IF = auto()
NIL = auto()
OR = auto()
PRINT = auto()
RETURN = auto()
SUPER = auto()
THIS = auto()
TRUE = auto()
LET = auto()
WHILE = auto()
EOF = auto()