-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoken_list_format.html
More file actions
359 lines (326 loc) · 6.79 KB
/
Copy pathtoken_list_format.html
File metadata and controls
359 lines (326 loc) · 6.79 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
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Output Format for Lexical Analyzer</title>
</head>
<body>
<h2><u>Output Format for Lexical Analyzer</u></h2>
<p>
Your lexical analyzer should output each token identified from the inputted MINI-L program.
Each token should appear on a separate line of output, and the tokens should appear in the
output in the same order as they appear in the inputted MINI-L program. To facilitate grading,
the tokens must be outputted in the format described in the table <a href="#table">below</a>.
</p>
<p>
There are two types of lexical errors that your lexical analyzer should catch. They are described <a href="#errors">below</a>.
</p>
<p>
Note: for this phase of the project, even syntactically incorrect MINI-L programs may still be
parsed successfully into a list of tokens. The next phase of this project is where
syntax errors will be captured.
</p>
<hr>
<a name="table"></a>
<h3>List of Tokens</h3>
<p>
The following table describes the different kinds of tokens that may be outputted by
your lexical analyzer. <i>Comments</i> and <i>whitespace</i> should be ignored by your
lexical analyzer (you should not output any tokens for these).
</p>
<br>
<table border="1" cellpadding="3">
<tr bgcolor="#FFFFCC">
<td><b>Lexical Pattern in the Inputted MINI-L Program</b></td>
<td><b>Token that Should Be Outputted</b></td>
</tr>
<tr>
<td colspan="2" bgcolor="#EEEEEE"><center><i>Reserved Words</i></center></td>
</tr>
<tr>
<td>function</td>
<td>FUNCTION</td>
</tr>
<tr>
<td>beginparams</td>
<td>BEGIN_PARAMS</td>
</tr>
<tr>
<td>endparams</td>
<td>END_PARAMS</td>
</tr>
<tr>
<td>beginlocals</td>
<td>BEGIN_LOCALS</td>
</tr>
<tr>
<td>endlocals</td>
<td>END_LOCALS</td>
</tr>
<tr>
<td>beginbody</td>
<td>BEGIN_BODY</td>
</tr>
<tr>
<td>endbody</td>
<td>END_BODY</td>
</tr>
<tr>
<td>integer</td>
<td>INTEGER</td>
</tr>
<tr>
<td>array</td>
<td>ARRAY</td>
</tr>
<tr>
<td>enum</td>
<td>ENUM</td>
</tr>
<tr>
<td>of</td>
<td>OF</td>
</tr>
<tr>
<td>if</td>
<td>IF</td>
</tr>
<tr>
<td>then</td>
<td>THEN</td>
</tr>
<tr>
<td>endif</td>
<td>ENDIF</td>
</tr>
<tr>
<td>else</td>
<td>ELSE</td>
</tr>
<tr>
<td>for</td>
<td>FOR</td>
</tr>
<tr>
<td>while</td>
<td>WHILE</td>
</tr>
<tr>
<td>do</td>
<td>DO</td>
</tr>
<tr>
<td>beginloop</td>
<td>BEGINLOOP</td>
</tr>
<tr>
<td>endloop</td>
<td>ENDLOOP</td>
</tr>
<tr>
<td>continue</td>
<td>CONTINUE</td>
</tr>
<tr>
<td>read</td>
<td>READ</td>
</tr>
<tr>
<td>write</td>
<td>WRITE</td>
</tr>
<tr>
<td>and</td>
<td>AND</td>
</tr>
<tr>
<td>or</td>
<td>OR</td>
</tr>
<tr>
<td>not</td>
<td>NOT</td>
</tr>
<tr>
<td>true</td>
<td>TRUE</td>
</tr>
<tr>
<td>false</td>
<td>FALSE</td>
</tr>
<tr>
<td>return</td>
<td>RETURN</td>
</tr>
<tr>
<td colspan="2" bgcolor="#EEEEEE"><center><i>Arithmetic Operators</i></center></td>
</tr>
<tr>
<td>-</td>
<td>SUB</td>
</tr>
<tr>
<td>+</td>
<td>ADD</td>
</tr>
<tr>
<td>*</td>
<td>MULT</td>
</tr>
<tr>
<td>/</td>
<td>DIV</td>
</tr>
<tr>
<td>%</td>
<td>MOD</td>
</tr>
<tr>
<td colspan="2" bgcolor="#EEEEEE"><center><i>Comparison Operators</i></center></td>
</tr>
<tr>
<td>==</td>
<td>EQ</td>
</tr>
<tr>
<td><></td>
<td>NEQ</td>
</tr>
<tr>
<td><</td>
<td>LT</td>
</tr>
<tr>
<td>></td>
<td>GT</td>
</tr>
<tr>
<td><=</td>
<td>LTE</td>
</tr>
<tr>
<td>>=</td>
<td>GTE</td>
</tr>
<tr>
<td colspan="2" bgcolor="#EEEEEE"><center><i>Identifiers and Numbers</i></center></td>
</tr>
<tr>
<td>identifier (e.g., "aardvark", "BIG_PENGUIN", "fLaMInGo_17", "ot73r")</td>
<td>IDENT XXXX <font size=-1>[where XXXX is the identifier itself]</font></td>
</tr>
<tr>
<td>number (e.g., "17", "101", "90210", "0", "8675309")</td>
<td>NUMBER XXXX <font size=-1>[where XXXX is the number itself]</font></td>
</tr>
<tr>
<td colspan="2" bgcolor="#EEEEEE"><center><i>Other Special Symbols</i></center></td>
</tr>
<tr>
<td>;</td>
<td>SEMICOLON</td>
</tr>
<tr>
<td>:</td>
<td>COLON</td>
</tr>
<tr>
<td>,</td>
<td>COMMA</td>
</tr>
<tr>
<td>(</td>
<td>L_PAREN</td>
</tr>
<tr>
<td>)</td>
<td>R_PAREN</td>
</tr>
<tr>
<td>[</td>
<td>L_SQUARE_BRACKET</td>
</tr>
<tr>
<td>]</td>
<td>R_SQUARE_BRACKET</td>
</tr>
<tr>
<td>:=</td>
<td>ASSIGN</td>
</tr>
</table>
<br>
<hr>
<a name="errors"></a>
<h3>Lexical Errors to Catch</h3>
<p>
Your lexical analyzer should catch two different types of lexical errors. If any such error is encountered
during parsing of a MINI-L program, your lexical analyzer should terminate immediately after reporting the
error message. The error message must include information about the line number and column position number within
the line of the token associated with the error. The details are below.
</p>
<p>
<u>Error Type 1: Unrecognized Symbol</u><br><br>
Your lexical analyzer should report an error and terminate if an unrecognized symbol is encountered that is
outside of a comment. For example, consider the following MINI-L function:
<pre>
01. function test;
02. beginparams
03. endparams
04. beginlocals
05. n : integer;
06. endlocals
07. beginbody
08. read n;
09. n := n + 1?
10. write n;
11. endbody
</pre>
In the above program, the "?" symbol at line 5 (which is outside of a comment) is not defined in the
MINI-L language. Thus, your lexical analyzer should output an "unrecognized symbol" error when it
encounters the "?" (along with line number and position number information of the problematic symbol).
For example:
<pre>
Error at line 9, column 14: unrecognized symbol "?"
</pre>
</p>
<br>
<p>
<u>Error Type 2: Invalid Identifier</u><br><br>
Your lexical analyzer should report an error and terminate if an invalid identifier is encountered.
This can occur if the identifier starts with a digit or an underscore, or if the identifier
ends with an underscore. For example, consider the following two MINI-L functions:
<pre>
01. function test1;
02. beginparams
03. endparams
04. beginlocals
05. 2n : integer;
06. endlocals
07. beginbody
08. endbody
</pre>
<pre>
01. function test2;
02. beginparams
03. endparams
04. beginlocals
05. n_ : integer;
06. endlocals
07. beginprogram
08. endprogram
</pre>
In both of the above functions, the identifier declared at line 5 is invalid. Thus, in both
of these cases, your lexical analyzer should output an "invalid identifier" error when it
encounters either the "2n" or the "n_". For example, in the first function above:
<pre>
Error at line 5, column 0: identifier "2n" must begin with a letter
</pre>
And in the second function above:
<pre>
Error at line 5 , column 0: identifier "n_" cannot end with an underscore
</pre>
</p>
<hr>
</body>
</html>