-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmytoken.py
52 lines (49 loc) · 1.07 KB
/
mytoken.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
PRINT = 'PRINT'
PRINTLN = 'PRINTLN'
READINT = 'READINT'
READSTR = 'READSTR'
LPAREN = 'LPAREN'
RPAREN = 'RPAREN'
SEMICOLON = 'SEMICOLON'
ID = 'ID'
LBRACKET = 'LBRACKET'
RBRACKET = 'RBRACKET'
STRING = 'STRING'
INT = 'INT'
BOOL = 'BOOL'
COMMA = 'COMMA'
ASSIGN = 'ASSIGN'
PLUS = 'PLUS'
MINUS = 'MINUS'
DIVIDE = 'DIVIDE'
MULTIPLY = 'MULTIPLY'
MODULUS = 'MODULUS'
IF = 'IF'
THEN = 'THEN'
ELSEIF = 'ELSEIF'
ELSE = 'ELSE'
END = 'END'
NOT = 'NOT'
AND = 'AND'
OR = 'OR'
EQUAL = 'EQUAL'
LESS_THAN = 'LESS_THAN'
GREATER_THAN = 'GREATER_THAN'
LESS_THAN_EQUAL = 'LESS_THAN_EQUAL'
GREATER_THAN_EQUAL = 'GREATER_THAN_EQUAL'
NOT_EQUAL = 'NOT_EQUAL'
WHILE = 'WHILE'
DO = 'DO'
EOS = 'EOS'
class Token(object):
"""
creates a token class that has a token type (see above), lexeme, line number,
and column number.
"""
def __init__(self, tokentype, lexeme, line, column):
self.tokentype = tokentype
self.lexeme = lexeme
self.line = line
self.column = column
def __str__(self):
return "%s '%s' %s:%s" % (self.tokentype, self.lexeme, self.line, self.column)