-
Notifications
You must be signed in to change notification settings - Fork 0
/
ToyCLexer.py
263 lines (246 loc) · 14.3 KB
/
ToyCLexer.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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# Generated from ToyC.g4 by ANTLR 4.9
from antlr4 import *
from io import StringIO
from typing.io import TextIO
import sys
def serializedATN():
with StringIO() as buf:
buf.write("\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\66")
buf.write("\u0164\b\1\4\2\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7")
buf.write("\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t\13\4\f\t\f\4\r\t\r")
buf.write("\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22\t\22\4\23")
buf.write("\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30")
buf.write("\4\31\t\31\4\32\t\32\4\33\t\33\4\34\t\34\4\35\t\35\4\36")
buf.write("\t\36\4\37\t\37\4 \t \4!\t!\4\"\t\"\4#\t#\4$\t$\4%\t%")
buf.write("\4&\t&\4\'\t\'\4(\t(\4)\t)\4*\t*\4+\t+\4,\t,\4-\t-\4.")
buf.write("\t.\4/\t/\4\60\t\60\4\61\t\61\4\62\t\62\4\63\t\63\4\64")
buf.write("\t\64\4\65\t\65\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3")
buf.write("\3\3\3\3\4\3\4\3\5\3\5\3\6\3\6\3\7\3\7\3\b\3\b\3\t\3\t")
buf.write("\3\n\3\n\3\13\3\13\3\f\3\f\3\r\3\r\3\16\3\16\3\16\3\17")
buf.write("\3\17\3\17\3\17\3\17\3\20\3\20\3\20\3\20\3\20\3\20\3\21")
buf.write("\3\21\3\21\3\21\3\22\3\22\3\22\3\22\3\22\3\22\3\22\3\23")
buf.write("\3\23\3\24\3\24\3\24\3\25\3\25\3\25\3\26\3\26\3\27\3\27")
buf.write("\3\30\3\30\3\31\3\31\3\32\3\32\3\33\3\33\3\33\3\34\3\34")
buf.write("\3\34\3\35\3\35\3\35\3\36\3\36\3\36\3\37\3\37\3\37\3\37")
buf.write("\3 \3 \3 \3 \3 \3 \3 \3!\3!\3!\3!\3!\3\"\3\"\3\"\3\"\3")
buf.write("\"\3\"\3\"\3#\3#\3#\3#\3#\3$\3$\3$\3$\3$\3$\3$\3%\3%\3")
buf.write("%\3%\3%\3&\3&\3&\3&\3&\3&\3&\3\'\3\'\3\'\3\'\3\'\3\'\3")
buf.write("(\3(\3)\3)\3)\3)\3)\3*\3*\7*\u0100\n*\f*\16*\u0103\13")
buf.write("*\3+\6+\u0106\n+\r+\16+\u0107\3,\6,\u010b\n,\r,\16,\u010c")
buf.write("\3,\3,\6,\u0111\n,\r,\16,\u0112\3-\3-\3-\3-\3.\3.\7.\u011b")
buf.write("\n.\f.\16.\u011e\13.\3.\3.\3/\6/\u0123\n/\r/\16/\u0124")
buf.write("\3/\3/\5/\u0129\n/\3\60\3\60\3\60\3\60\5\60\u012f\n\60")
buf.write("\3\61\3\61\3\61\3\61\3\61\3\61\3\61\3\61\3\61\3\61\3\61")
buf.write("\5\61\u013c\n\61\3\62\3\62\3\63\3\63\3\63\3\63\7\63\u0144")
buf.write("\n\63\f\63\16\63\u0147\13\63\3\63\5\63\u014a\n\63\3\63")
buf.write("\3\63\3\63\3\63\3\64\3\64\3\64\3\64\7\64\u0154\n\64\f")
buf.write("\64\16\64\u0157\13\64\3\64\3\64\3\64\3\64\3\64\3\65\6")
buf.write("\65\u015f\n\65\r\65\16\65\u0160\3\65\3\65\5\u011c\u0145")
buf.write("\u0155\2\66\3\3\5\4\7\5\t\6\13\7\r\b\17\t\21\n\23\13\25")
buf.write("\f\27\r\31\16\33\17\35\20\37\21!\22#\23%\24\'\25)\26+")
buf.write("\27-\30/\31\61\32\63\33\65\34\67\359\36;\37= ?!A\"C#E")
buf.write("$G%I&K\'M(O)Q*S+U,W-Y.[/]\60_\61a\62c\63e\64g\65i\66\3")
buf.write("\2\t\5\2C\\aac|\6\2\62;C\\aac|\3\2\62;\4\2C\\c|\6\2##")
buf.write(",-//\61\61\7\2##((,-//\u0080\u0080\5\2\13\f\17\17\"\"")
buf.write("\2\u0175\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3\2\2\2\2\t\3\2\2")
buf.write("\2\2\13\3\2\2\2\2\r\3\2\2\2\2\17\3\2\2\2\2\21\3\2\2\2")
buf.write("\2\23\3\2\2\2\2\25\3\2\2\2\2\27\3\2\2\2\2\31\3\2\2\2\2")
buf.write("\33\3\2\2\2\2\35\3\2\2\2\2\37\3\2\2\2\2!\3\2\2\2\2#\3")
buf.write("\2\2\2\2%\3\2\2\2\2\'\3\2\2\2\2)\3\2\2\2\2+\3\2\2\2\2")
buf.write("-\3\2\2\2\2/\3\2\2\2\2\61\3\2\2\2\2\63\3\2\2\2\2\65\3")
buf.write("\2\2\2\2\67\3\2\2\2\29\3\2\2\2\2;\3\2\2\2\2=\3\2\2\2\2")
buf.write("?\3\2\2\2\2A\3\2\2\2\2C\3\2\2\2\2E\3\2\2\2\2G\3\2\2\2")
buf.write("\2I\3\2\2\2\2K\3\2\2\2\2M\3\2\2\2\2O\3\2\2\2\2Q\3\2\2")
buf.write("\2\2S\3\2\2\2\2U\3\2\2\2\2W\3\2\2\2\2Y\3\2\2\2\2[\3\2")
buf.write("\2\2\2]\3\2\2\2\2_\3\2\2\2\2a\3\2\2\2\2c\3\2\2\2\2e\3")
buf.write("\2\2\2\2g\3\2\2\2\2i\3\2\2\2\3k\3\2\2\2\5t\3\2\2\2\7v")
buf.write("\3\2\2\2\tx\3\2\2\2\13z\3\2\2\2\r|\3\2\2\2\17~\3\2\2\2")
buf.write("\21\u0080\3\2\2\2\23\u0082\3\2\2\2\25\u0084\3\2\2\2\27")
buf.write("\u0086\3\2\2\2\31\u0088\3\2\2\2\33\u008a\3\2\2\2\35\u008d")
buf.write("\3\2\2\2\37\u0092\3\2\2\2!\u0098\3\2\2\2#\u009c\3\2\2")
buf.write("\2%\u00a3\3\2\2\2\'\u00a5\3\2\2\2)\u00a8\3\2\2\2+\u00ab")
buf.write("\3\2\2\2-\u00ad\3\2\2\2/\u00af\3\2\2\2\61\u00b1\3\2\2")
buf.write("\2\63\u00b3\3\2\2\2\65\u00b5\3\2\2\2\67\u00b8\3\2\2\2")
buf.write("9\u00bb\3\2\2\2;\u00be\3\2\2\2=\u00c1\3\2\2\2?\u00c5\3")
buf.write("\2\2\2A\u00cc\3\2\2\2C\u00d1\3\2\2\2E\u00d8\3\2\2\2G\u00dd")
buf.write("\3\2\2\2I\u00e4\3\2\2\2K\u00e9\3\2\2\2M\u00f0\3\2\2\2")
buf.write("O\u00f6\3\2\2\2Q\u00f8\3\2\2\2S\u00fd\3\2\2\2U\u0105\3")
buf.write("\2\2\2W\u010a\3\2\2\2Y\u0114\3\2\2\2[\u0118\3\2\2\2]\u0122")
buf.write("\3\2\2\2_\u012e\3\2\2\2a\u013b\3\2\2\2c\u013d\3\2\2\2")
buf.write("e\u013f\3\2\2\2g\u014f\3\2\2\2i\u015e\3\2\2\2kl\7%\2\2")
buf.write("lm\7k\2\2mn\7p\2\2no\7e\2\2op\7n\2\2pq\7w\2\2qr\7f\2\2")
buf.write("rs\7g\2\2s\4\3\2\2\2tu\7>\2\2u\6\3\2\2\2vw\7@\2\2w\b\3")
buf.write("\2\2\2xy\7*\2\2y\n\3\2\2\2z{\7+\2\2{\f\3\2\2\2|}\7}\2")
buf.write("\2}\16\3\2\2\2~\177\7\177\2\2\177\20\3\2\2\2\u0080\u0081")
buf.write("\7.\2\2\u0081\22\3\2\2\2\u0082\u0083\7=\2\2\u0083\24\3")
buf.write("\2\2\2\u0084\u0085\7?\2\2\u0085\26\3\2\2\2\u0086\u0087")
buf.write("\7]\2\2\u0087\30\3\2\2\2\u0088\u0089\7_\2\2\u0089\32\3")
buf.write("\2\2\2\u008a\u008b\7k\2\2\u008b\u008c\7h\2\2\u008c\34")
buf.write("\3\2\2\2\u008d\u008e\7g\2\2\u008e\u008f\7n\2\2\u008f\u0090")
buf.write("\7u\2\2\u0090\u0091\7g\2\2\u0091\36\3\2\2\2\u0092\u0093")
buf.write("\7y\2\2\u0093\u0094\7j\2\2\u0094\u0095\7k\2\2\u0095\u0096")
buf.write("\7n\2\2\u0096\u0097\7g\2\2\u0097 \3\2\2\2\u0098\u0099")
buf.write("\7h\2\2\u0099\u009a\7q\2\2\u009a\u009b\7t\2\2\u009b\"")
buf.write("\3\2\2\2\u009c\u009d\7t\2\2\u009d\u009e\7g\2\2\u009e\u009f")
buf.write("\7v\2\2\u009f\u00a0\7w\2\2\u00a0\u00a1\7t\2\2\u00a1\u00a2")
buf.write("\7p\2\2\u00a2$\3\2\2\2\u00a3\u00a4\7#\2\2\u00a4&\3\2\2")
buf.write("\2\u00a5\u00a6\7(\2\2\u00a6\u00a7\7(\2\2\u00a7(\3\2\2")
buf.write("\2\u00a8\u00a9\7~\2\2\u00a9\u00aa\7~\2\2\u00aa*\3\2\2")
buf.write("\2\u00ab\u00ac\7/\2\2\u00ac,\3\2\2\2\u00ad\u00ae\7-\2")
buf.write("\2\u00ae.\3\2\2\2\u00af\u00b0\7,\2\2\u00b0\60\3\2\2\2")
buf.write("\u00b1\u00b2\7\61\2\2\u00b2\62\3\2\2\2\u00b3\u00b4\7\'")
buf.write("\2\2\u00b4\64\3\2\2\2\u00b5\u00b6\7?\2\2\u00b6\u00b7\7")
buf.write("?\2\2\u00b7\66\3\2\2\2\u00b8\u00b9\7#\2\2\u00b9\u00ba")
buf.write("\7?\2\2\u00ba8\3\2\2\2\u00bb\u00bc\7>\2\2\u00bc\u00bd")
buf.write("\7?\2\2\u00bd:\3\2\2\2\u00be\u00bf\7@\2\2\u00bf\u00c0")
buf.write("\7?\2\2\u00c0<\3\2\2\2\u00c1\u00c2\7k\2\2\u00c2\u00c3")
buf.write("\7p\2\2\u00c3\u00c4\7v\2\2\u00c4>\3\2\2\2\u00c5\u00c6")
buf.write("\7f\2\2\u00c6\u00c7\7q\2\2\u00c7\u00c8\7w\2\2\u00c8\u00c9")
buf.write("\7d\2\2\u00c9\u00ca\7n\2\2\u00ca\u00cb\7g\2\2\u00cb@\3")
buf.write("\2\2\2\u00cc\u00cd\7e\2\2\u00cd\u00ce\7j\2\2\u00ce\u00cf")
buf.write("\7c\2\2\u00cf\u00d0\7t\2\2\u00d0B\3\2\2\2\u00d1\u00d2")
buf.write("\7u\2\2\u00d2\u00d3\7v\2\2\u00d3\u00d4\7t\2\2\u00d4\u00d5")
buf.write("\7k\2\2\u00d5\u00d6\7p\2\2\u00d6\u00d7\7i\2\2\u00d7D\3")
buf.write("\2\2\2\u00d8\u00d9\7x\2\2\u00d9\u00da\7q\2\2\u00da\u00db")
buf.write("\7k\2\2\u00db\u00dc\7f\2\2\u00dcF\3\2\2\2\u00dd\u00de")
buf.write("\7u\2\2\u00de\u00df\7v\2\2\u00df\u00e0\7t\2\2\u00e0\u00e1")
buf.write("\7n\2\2\u00e1\u00e2\7g\2\2\u00e2\u00e3\7p\2\2\u00e3H\3")
buf.write("\2\2\2\u00e4\u00e5\7c\2\2\u00e5\u00e6\7v\2\2\u00e6\u00e7")
buf.write("\7q\2\2\u00e7\u00e8\7k\2\2\u00e8J\3\2\2\2\u00e9\u00ea")
buf.write("\7r\2\2\u00ea\u00eb\7t\2\2\u00eb\u00ec\7k\2\2\u00ec\u00ed")
buf.write("\7p\2\2\u00ed\u00ee\7v\2\2\u00ee\u00ef\7h\2\2\u00efL\3")
buf.write("\2\2\2\u00f0\u00f1\7u\2\2\u00f1\u00f2\7e\2\2\u00f2\u00f3")
buf.write("\7c\2\2\u00f3\u00f4\7p\2\2\u00f4\u00f5\7h\2\2\u00f5N\3")
buf.write("\2\2\2\u00f6\u00f7\7(\2\2\u00f7P\3\2\2\2\u00f8\u00f9\7")
buf.write("i\2\2\u00f9\u00fa\7g\2\2\u00fa\u00fb\7v\2\2\u00fb\u00fc")
buf.write("\7u\2\2\u00fcR\3\2\2\2\u00fd\u0101\t\2\2\2\u00fe\u0100")
buf.write("\t\3\2\2\u00ff\u00fe\3\2\2\2\u0100\u0103\3\2\2\2\u0101")
buf.write("\u00ff\3\2\2\2\u0101\u0102\3\2\2\2\u0102T\3\2\2\2\u0103")
buf.write("\u0101\3\2\2\2\u0104\u0106\t\4\2\2\u0105\u0104\3\2\2\2")
buf.write("\u0106\u0107\3\2\2\2\u0107\u0105\3\2\2\2\u0107\u0108\3")
buf.write("\2\2\2\u0108V\3\2\2\2\u0109\u010b\t\4\2\2\u010a\u0109")
buf.write("\3\2\2\2\u010b\u010c\3\2\2\2\u010c\u010a\3\2\2\2\u010c")
buf.write("\u010d\3\2\2\2\u010d\u010e\3\2\2\2\u010e\u0110\7\60\2")
buf.write("\2\u010f\u0111\t\4\2\2\u0110\u010f\3\2\2\2\u0111\u0112")
buf.write("\3\2\2\2\u0112\u0110\3\2\2\2\u0112\u0113\3\2\2\2\u0113")
buf.write("X\3\2\2\2\u0114\u0115\7)\2\2\u0115\u0116\13\2\2\2\u0116")
buf.write("\u0117\7)\2\2\u0117Z\3\2\2\2\u0118\u011c\7$\2\2\u0119")
buf.write("\u011b\13\2\2\2\u011a\u0119\3\2\2\2\u011b\u011e\3\2\2")
buf.write("\2\u011c\u011d\3\2\2\2\u011c\u011a\3\2\2\2\u011d\u011f")
buf.write("\3\2\2\2\u011e\u011c\3\2\2\2\u011f\u0120\7$\2\2\u0120")
buf.write("\\\3\2\2\2\u0121\u0123\t\5\2\2\u0122\u0121\3\2\2\2\u0123")
buf.write("\u0124\3\2\2\2\u0124\u0122\3\2\2\2\u0124\u0125\3\2\2\2")
buf.write("\u0125\u0128\3\2\2\2\u0126\u0127\7\60\2\2\u0127\u0129")
buf.write("\7j\2\2\u0128\u0126\3\2\2\2\u0128\u0129\3\2\2\2\u0129")
buf.write("^\3\2\2\2\u012a\u012b\7(\2\2\u012b\u012f\7(\2\2\u012c")
buf.write("\u012d\7~\2\2\u012d\u012f\7~\2\2\u012e\u012a\3\2\2\2\u012e")
buf.write("\u012c\3\2\2\2\u012f`\3\2\2\2\u0130\u013c\t\6\2\2\u0131")
buf.write("\u0132\7?\2\2\u0132\u013c\7?\2\2\u0133\u0134\7#\2\2\u0134")
buf.write("\u013c\7?\2\2\u0135\u013c\7>\2\2\u0136\u0137\7>\2\2\u0137")
buf.write("\u013c\7?\2\2\u0138\u013c\7@\2\2\u0139\u013a\7@\2\2\u013a")
buf.write("\u013c\7?\2\2\u013b\u0130\3\2\2\2\u013b\u0131\3\2\2\2")
buf.write("\u013b\u0133\3\2\2\2\u013b\u0135\3\2\2\2\u013b\u0136\3")
buf.write("\2\2\2\u013b\u0138\3\2\2\2\u013b\u0139\3\2\2\2\u013cb")
buf.write("\3\2\2\2\u013d\u013e\t\7\2\2\u013ed\3\2\2\2\u013f\u0140")
buf.write("\7\61\2\2\u0140\u0141\7\61\2\2\u0141\u0145\3\2\2\2\u0142")
buf.write("\u0144\13\2\2\2\u0143\u0142\3\2\2\2\u0144\u0147\3\2\2")
buf.write("\2\u0145\u0146\3\2\2\2\u0145\u0143\3\2\2\2\u0146\u0149")
buf.write("\3\2\2\2\u0147\u0145\3\2\2\2\u0148\u014a\7\17\2\2\u0149")
buf.write("\u0148\3\2\2\2\u0149\u014a\3\2\2\2\u014a\u014b\3\2\2\2")
buf.write("\u014b\u014c\7\f\2\2\u014c\u014d\3\2\2\2\u014d\u014e\b")
buf.write("\63\2\2\u014ef\3\2\2\2\u014f\u0150\7\61\2\2\u0150\u0151")
buf.write("\7,\2\2\u0151\u0155\3\2\2\2\u0152\u0154\13\2\2\2\u0153")
buf.write("\u0152\3\2\2\2\u0154\u0157\3\2\2\2\u0155\u0156\3\2\2\2")
buf.write("\u0155\u0153\3\2\2\2\u0156\u0158\3\2\2\2\u0157\u0155\3")
buf.write("\2\2\2\u0158\u0159\7,\2\2\u0159\u015a\7\61\2\2\u015a\u015b")
buf.write("\3\2\2\2\u015b\u015c\b\64\2\2\u015ch\3\2\2\2\u015d\u015f")
buf.write("\t\b\2\2\u015e\u015d\3\2\2\2\u015f\u0160\3\2\2\2\u0160")
buf.write("\u015e\3\2\2\2\u0160\u0161\3\2\2\2\u0161\u0162\3\2\2\2")
buf.write("\u0162\u0163\b\65\2\2\u0163j\3\2\2\2\20\2\u0101\u0107")
buf.write("\u010c\u0112\u011c\u0124\u0128\u012e\u013b\u0145\u0149")
buf.write("\u0155\u0160\3\b\2\2")
return buf.getvalue()
class ToyCLexer(Lexer):
atn = ATNDeserializer().deserialize(serializedATN())
decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ]
T__0 = 1
T__1 = 2
T__2 = 3
T__3 = 4
T__4 = 5
T__5 = 6
T__6 = 7
T__7 = 8
T__8 = 9
T__9 = 10
T__10 = 11
T__11 = 12
T__12 = 13
T__13 = 14
T__14 = 15
T__15 = 16
T__16 = 17
T__17 = 18
T__18 = 19
T__19 = 20
T__20 = 21
T__21 = 22
T__22 = 23
T__23 = 24
T__24 = 25
T__25 = 26
T__26 = 27
T__27 = 28
T__28 = 29
T__29 = 30
T__30 = 31
T__31 = 32
T__32 = 33
T__33 = 34
T__34 = 35
T__35 = 36
T__36 = 37
T__37 = 38
T__38 = 39
T__39 = 40
ID = 41
INT = 42
DOUBLE = 43
CHAR = 44
STRING = 45
LIB = 46
Conjunction = 47
Operator = 48
UnaryOperator = 49
LineComment = 50
BlockComment = 51
WS = 52
channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN" ]
modeNames = [ "DEFAULT_MODE" ]
literalNames = [ "<INVALID>",
"'#include'", "'<'", "'>'", "'('", "')'", "'{'", "'}'", "','",
"';'", "'='", "'['", "']'", "'if'", "'else'", "'while'", "'for'",
"'return'", "'!'", "'&&'", "'||'", "'-'", "'+'", "'*'", "'/'",
"'%'", "'=='", "'!='", "'<='", "'>='", "'int'", "'double'",
"'char'", "'string'", "'void'", "'strlen'", "'atoi'", "'printf'",
"'scanf'", "'&'", "'gets'" ]
symbolicNames = [ "<INVALID>",
"ID", "INT", "DOUBLE", "CHAR", "STRING", "LIB", "Conjunction",
"Operator", "UnaryOperator", "LineComment", "BlockComment",
"WS" ]
ruleNames = [ "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6",
"T__7", "T__8", "T__9", "T__10", "T__11", "T__12", "T__13",
"T__14", "T__15", "T__16", "T__17", "T__18", "T__19",
"T__20", "T__21", "T__22", "T__23", "T__24", "T__25",
"T__26", "T__27", "T__28", "T__29", "T__30", "T__31",
"T__32", "T__33", "T__34", "T__35", "T__36", "T__37",
"T__38", "T__39", "ID", "INT", "DOUBLE", "CHAR", "STRING",
"LIB", "Conjunction", "Operator", "UnaryOperator", "LineComment",
"BlockComment", "WS" ]
grammarFileName = "ToyC.g4"
def __init__(self, input=None, output:TextIO = sys.stdout):
super().__init__(input, output)
self.checkVersion("4.9")
self._interp = LexerATNSimulator(self, self.atn, self.decisionsToDFA, PredictionContextCache())
self._actions = None
self._predicates = None