-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoken_defs.py
More file actions
executable file
·138 lines (120 loc) · 3.39 KB
/
token_defs.py
File metadata and controls
executable file
·138 lines (120 loc) · 3.39 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#
# WHAT WILL MY TOKEN OBJS LOOK LIKE?
#
#
#
token_defs_operations = {
"ASSIGNMENT": "=" ,
"EQUALITY": "==" ,
"NOT_EQUALITY": "!=" ,
"LESS_EQUAL": "<=" ,
"LESS_THAN": "<" ,
"GRT_THAN": ">" ,
"GRT_EQUAL": ">=" ,
"BIT_AND": "&" ,
"AND": "&&" ,
"BIT_OR": "|" ,
"OR": "||" ,
"NOT": "!" ,
"OPAR": "(" ,
"CPAR": ")" ,
"OSQ": "[" ,
"CSQ": "]" ,
"OCB": "{" ,
"CCB": "}" ,
"ADD": "+" ,
"SUB": "-" ,
"MULT": "*" ,
"DIV": "/" ,
"MOD": "%" ,
"DECIMAL": "."
}
decimal_prefix = {
"EXPONENT": "E",
"NEG_SIGN": "-",
"POS_SIGN": "+",
"DECIMAL": "."
}
token_str_def = {
"STR_QUOTE": "\""
}
key_words = {
"if": "IF_STAT",
"elseif": "ELIF_STAT",
"else": "ELSE_STAT",
"while": "WHILE_STAT",
"for": "FOR_STAT"
}
def create_int_token(token):
return {
"KIND": "INTEGER",
"VALUE": token
}
def create_float(token):
return {
"KIND": "FLOAT",
"VALUE": token
}
def create_str(token):
return {
"KIND": "STRING",
"VALUE": token
}
def create_id(token):
if token in key_words:
return { "KIND": "KEYWORD", "VALUE": token}
return {
"KIND": "ID",
"VALUE": token
}
def create_operation(token):
if token == token_defs_operations["ASSIGNMENT"]:
return {"KIND": "ASSIGNMENT", "VALUE": token}
elif token == token_defs_operations["EQUALITY"]:
return {"KIND": "EQUALITY", "VALUE": token}
elif token == token_defs_operations["NOT_EQUALITY"]:
return {"KIND": "NOT_EQUALITY", "VALUE": token}
elif token == token_defs_operations["LESS_EQUAL"]:
return {"KIND": "LESS_EQUAL", "VALUE": token}
elif token == token_defs_operations["LESS_THAN"]:
return {"KIND": "LESS_THAN", "VALUE": token}
elif token == token_defs_operations["GRT_THAN"]:
return {"KIND": "GRT_THAN", "VALUE": token}
elif token == token_defs_operations["GRT_EQUAL"]:
return {"KIND": "GRT_EQUAL", "VALUE": token}
elif token == token_defs_operations["BIT_AND"]:
return {"KIND": "BIT_AND", "VALUE": token}
elif token == token_defs_operations["AND"]:
return {"KIND": "AND", "VALUE": token}
elif token == token_defs_operations["BIT_OR"]:
return {"KIND": "BIT_OR", "VALUE": token}
elif token == token_defs_operations["OR"]:
return {"KIND": "OR", "VALUE": token}
elif token == token_defs_operations["NOT"]:
return {"KIND": "NOT", "VALUE": token}
elif token == token_defs_operations["OPAR"]:
return {"KIND": "OPAR", "VALUE": token}
elif token == token_defs_operations["CPAR"]:
return {"KIND": "CPAR", "VALUE": token}
elif token == token_defs_operations["OSQ"]:
return {"KIND": "OSQ", "VALUE": token}
elif token == token_defs_operations["CSQ"]:
return {"KIND": "CSQ", "VALUE": token}
elif token == token_defs_operations["OCB"]:
return {"KIND": "OCB", "VALUE": token}
elif token == token_defs_operations["CCB"]:
return {"KIND": "CCB", "VALUE": token}
elif token == token_defs_operations["ADD"]:
return {"KIND": "ADD", "VALUE": token}
elif token == token_defs_operations["SUB"]:
return {"KIND": "SUB", "VALUE": token}
elif token == token_defs_operations["MULT"]:
return {"KIND": "MULT", "VALUE": token}
elif token == token_defs_operations["DIV"]:
return {"KIND": "DIV", "VALUE": token}
elif token == token_defs_operations["MOD"]:
return {"KIND": "MOD", "VALUE": token}
elif token == token_defs_operations["DECIMAL"]:
return {"KIND": "DECIMAL", "VALUE": token}
def create_EOF():
return {"KIND": "EOF"}