-
Notifications
You must be signed in to change notification settings - Fork 0
/
token_class.py
37 lines (33 loc) · 1009 Bytes
/
token_class.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
class Token:
"""
Token class is responsible for creating tokens
"""
def __init__(self, type, val, line_num):
"""
Class initializer
Params
======
type (string) = type of token as string
val (string) = value stored at token
line_num (int) = line number
Values
======
type (string) = type of token as string
typedig (int) = type of token as integer
val (string) = value stored at token
line_num (int) = line number
"""
self.type = type
self.val = val
self.line_num = line_num
def __str__(self):
"""
Returns
=======
string: The string representation of Token object, which can be used to print the tokens
"""
return (
"Token(%s, %s)" % (self.type, self.val)
if self.type != "newline"
else "Token(%s, %s)\n" % (self.type, self.val)
)