Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/Parser.java @ 13761:7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Fri, 24 Jan 2014 18:16:24 -0800 |
parents | 7311354f5bf8 |
children | cad8bed1a1ac |
comparison
equal
deleted
inserted
replaced
13760:a12017c18d5d | 13761:7c418666c6c9 |
---|---|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 * or visit www.oracle.com if you need additional information or have any | 20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. | 21 * questions. |
22 */ | 22 */ |
23 | 23 |
24 // The content of this file is automatically generated. DO NOT EDIT. | 24 // The content of this file is automatically generated. DO NOT EDIT. |
25 | |
25 | 26 |
26 package com.oracle.truffle.sl.parser; | 27 package com.oracle.truffle.sl.parser; |
27 | 28 |
28 import java.util.*; | 29 import java.util.*; |
29 | 30 |
31 import com.oracle.truffle.api.*; | |
30 import com.oracle.truffle.sl.*; | 32 import com.oracle.truffle.sl.*; |
31 import com.oracle.truffle.sl.nodes.*; | 33 import com.oracle.truffle.sl.nodes.*; |
34 import com.oracle.truffle.sl.runtime.*; | |
32 | 35 |
33 // Checkstyle: stop | 36 // Checkstyle: stop |
34 // @formatter:off | 37 // @formatter:off |
35 public class Parser { | 38 public class Parser { |
36 public static final int _EOF = 0; | 39 public static final int _EOF = 0; |
37 public static final int _identifier = 1; | 40 public static final int _identifier = 1; |
38 public static final int _stringLiteral = 2; | 41 public static final int _stringLiteral = 2; |
39 public static final int _numericLiteral = 3; | 42 public static final int _numericLiteral = 3; |
40 public static final int maxT = 29; | 43 public static final int maxT = 30; |
41 | 44 |
42 static final boolean T = true; | 45 static final boolean T = true; |
43 static final boolean x = false; | 46 static final boolean x = false; |
44 static final int minErrDist = 2; | 47 static final int minErrDist = 2; |
45 | 48 |
49 | 52 |
50 public final Scanner scanner; | 53 public final Scanner scanner; |
51 public final Errors errors; | 54 public final Errors errors; |
52 private final SLNodeFactory factory; | 55 private final SLNodeFactory factory; |
53 | 56 |
54 public Parser(Scanner scanner, SLNodeFactory factory) { | 57 public Parser(SLContext context, Source source) { |
55 this.scanner = scanner; | 58 this.scanner = new Scanner(source.getInputStream()); |
56 this.factory = factory; | 59 this.factory = new SLNodeFactory(context, source, this); |
57 errors = new Errors(); | 60 errors = new Errors(); |
58 } | 61 } |
59 | 62 |
60 void SynErr(int n) { | 63 void SynErr(int n) { |
61 if (errDist >= minErrDist) | 64 if (errDist >= minErrDist) |
128 } | 131 } |
129 } | 132 } |
130 | 133 |
131 void Function() { | 134 void Function() { |
132 Expect(4); | 135 Expect(4); |
133 factory.startFunction(); | |
134 Expect(1); | 136 Expect(1); |
135 String name = t.val; | 137 String name = t.val; |
136 List<String> parameterNames = new ArrayList<>(); | 138 Expect(5); |
137 if (la.kind == 5) { | 139 List<String> parameters = new ArrayList<>(); |
138 Get(); | 140 if (la.kind == 1) { |
139 if (la.kind == 1) { | 141 Get(); |
140 Get(); | 142 parameters.add(t.val); |
141 parameterNames.add(t.val); | |
142 } | |
143 while (la.kind == 6) { | 143 while (la.kind == 6) { |
144 Get(); | 144 Get(); |
145 Expect(1); | 145 Expect(1); |
146 parameterNames.add(t.val); | 146 parameters.add(t.val); |
147 } | 147 } |
148 Expect(7); | 148 } |
149 } | 149 Expect(7); |
150 StatementNode body = Block(); | 150 factory.startFunction(name, parameters); |
151 factory.createFunction(body, name, parameterNames.toArray(new String[parameterNames.size()])); | 151 SLStatementNode body = Block(); |
152 } | 152 factory.finishFunction(body); |
153 | 153 } |
154 StatementNode Block() { | 154 |
155 StatementNode result; | 155 SLStatementNode Block() { |
156 List<StatementNode> statements = new ArrayList<>(); | 156 SLStatementNode result; |
157 factory.startBlock(); | |
158 List<SLStatementNode> statements = new ArrayList<>(); | |
157 Expect(8); | 159 Expect(8); |
158 while (StartOf(1)) { | 160 while (StartOf(1)) { |
159 StatementNode statement = Statement(); | 161 SLStatementNode statement = Statement(); |
160 statements.add(statement); | 162 statements.add(statement); |
161 } | 163 } |
162 Expect(9); | 164 Expect(9); |
163 result = factory.createBlock(statements); | 165 result = factory.finishBlock(statements); |
164 return result; | 166 return result; |
165 } | 167 } |
166 | 168 |
167 StatementNode Statement() { | 169 SLStatementNode Statement() { |
168 StatementNode result; | 170 SLStatementNode result; |
169 result = null; | 171 result = null; |
170 if (la.kind == 13) { | 172 switch (la.kind) { |
173 case 15: { | |
171 result = WhileStatement(); | 174 result = WhileStatement(); |
172 } else if (la.kind == 11) { | 175 break; |
176 } | |
177 case 10: { | |
178 Get(); | |
179 result = factory.createBreak(); | |
180 Expect(11); | |
181 break; | |
182 } | |
183 case 12: { | |
184 Get(); | |
185 result = factory.createContinue(); | |
186 Expect(11); | |
187 break; | |
188 } | |
189 case 13: { | |
173 result = IfStatement(); | 190 result = IfStatement(); |
174 } else if (la.kind == 14) { | 191 break; |
192 } | |
193 case 16: { | |
175 result = ReturnStatement(); | 194 result = ReturnStatement(); |
176 } else if (StartOf(2)) { | 195 break; |
196 } | |
197 case 1: case 2: case 3: case 5: { | |
177 result = Expression(); | 198 result = Expression(); |
178 Expect(10); | 199 Expect(11); |
179 } else SynErr(30); | 200 break; |
180 return result; | 201 } |
181 } | 202 default: SynErr(31); break; |
182 | 203 } |
183 StatementNode WhileStatement() { | 204 return result; |
184 StatementNode result; | 205 } |
206 | |
207 SLStatementNode WhileStatement() { | |
208 SLStatementNode result; | |
209 Expect(15); | |
210 Expect(5); | |
211 SLExpressionNode condition = Expression(); | |
212 Expect(7); | |
213 SLStatementNode body = Block(); | |
214 result = factory.createWhile(condition, body); | |
215 return result; | |
216 } | |
217 | |
218 SLStatementNode IfStatement() { | |
219 SLStatementNode result; | |
185 Expect(13); | 220 Expect(13); |
186 Expect(5); | 221 Expect(5); |
187 ConditionNode condition = Expression(); | 222 SLExpressionNode condition = Expression(); |
188 Expect(7); | 223 Expect(7); |
189 StatementNode body = Block(); | 224 SLStatementNode thenPart = Block(); |
190 result = factory.createWhile(condition, body); | 225 SLStatementNode elsePart = null; |
191 return result; | 226 if (la.kind == 14) { |
192 } | 227 Get(); |
193 | 228 elsePart = Block(); |
194 StatementNode IfStatement() { | 229 } |
195 StatementNode result; | 230 result = factory.createIf(condition, thenPart, elsePart); |
231 return result; | |
232 } | |
233 | |
234 SLStatementNode ReturnStatement() { | |
235 SLStatementNode result; | |
236 Expect(16); | |
237 SLExpressionNode value = Expression(); | |
196 Expect(11); | 238 Expect(11); |
197 Expect(5); | |
198 ConditionNode condition = Expression(); | |
199 Expect(7); | |
200 StatementNode thenNode = null; StatementNode elseNode = null; | |
201 thenNode = Block(); | |
202 if (la.kind == 12) { | |
203 Get(); | |
204 elseNode = Block(); | |
205 } | |
206 result = factory.createIf(condition, thenNode, elseNode); | |
207 return result; | |
208 } | |
209 | |
210 StatementNode ReturnStatement() { | |
211 StatementNode result; | |
212 Expect(14); | |
213 TypedNode value = Expression(); | |
214 Expect(10); | |
215 result = factory.createReturn(value); | 239 result = factory.createReturn(value); |
216 return result; | 240 return result; |
217 } | 241 } |
218 | 242 |
219 TypedNode Expression() { | 243 SLExpressionNode Expression() { |
220 TypedNode result; | 244 SLExpressionNode result; |
221 result = ValueExpression(); | 245 result = LogicTerm(); |
222 if (StartOf(3)) { | 246 while (la.kind == 17) { |
247 Get(); | |
248 String op = t.val; | |
249 SLExpressionNode right = LogicTerm(); | |
250 result = factory.createBinary(op, result, right); | |
251 } | |
252 return result; | |
253 } | |
254 | |
255 SLExpressionNode LogicTerm() { | |
256 SLExpressionNode result; | |
257 result = LogicFactor(); | |
258 while (la.kind == 18) { | |
259 Get(); | |
260 String op = t.val; | |
261 SLExpressionNode right = LogicFactor(); | |
262 result = factory.createBinary(op, result, right); | |
263 } | |
264 return result; | |
265 } | |
266 | |
267 SLExpressionNode LogicFactor() { | |
268 SLExpressionNode result; | |
269 result = Arithmetic(); | |
270 if (StartOf(2)) { | |
223 switch (la.kind) { | 271 switch (la.kind) { |
224 case 15: { | 272 case 19: { |
225 Get(); | 273 Get(); |
226 break; | 274 break; |
227 } | 275 } |
228 case 16: { | 276 case 20: { |
229 Get(); | 277 Get(); |
230 break; | 278 break; |
231 } | 279 } |
232 case 17: { | 280 case 21: { |
233 Get(); | 281 Get(); |
234 break; | 282 break; |
235 } | 283 } |
236 case 18: { | 284 case 22: { |
237 Get(); | 285 Get(); |
238 break; | 286 break; |
239 } | 287 } |
240 case 19: { | 288 case 23: { |
241 Get(); | 289 Get(); |
242 break; | 290 break; |
243 } | 291 } |
244 case 20: { | 292 case 24: { |
245 Get(); | 293 Get(); |
246 break; | 294 break; |
247 } | 295 } |
248 } | 296 } |
249 String op = t.val; | 297 String op = t.val; |
250 TypedNode right = ValueExpression(); | 298 SLExpressionNode right = Arithmetic(); |
251 result = factory.createBinary(op, result, right); | 299 result = factory.createBinary(op, result, right); |
252 } | 300 } |
253 return result; | 301 return result; |
254 } | 302 } |
255 | 303 |
256 TypedNode ValueExpression() { | 304 SLExpressionNode Arithmetic() { |
257 TypedNode result; | 305 SLExpressionNode result; |
258 result = Term(); | 306 result = Term(); |
259 while (la.kind == 21 || la.kind == 22) { | 307 while (la.kind == 25 || la.kind == 26) { |
260 if (la.kind == 21) { | 308 if (la.kind == 25) { |
261 Get(); | 309 Get(); |
262 } else { | 310 } else { |
263 Get(); | 311 Get(); |
264 } | 312 } |
265 String op = t.val; | 313 String op = t.val; |
266 TypedNode right = Term(); | 314 SLExpressionNode right = Term(); |
267 result = factory.createBinary(op, result, right); | 315 result = factory.createBinary(op, result, right); |
268 } | 316 } |
269 return result; | 317 return result; |
270 } | 318 } |
271 | 319 |
272 TypedNode Term() { | 320 SLExpressionNode Term() { |
273 TypedNode result; | 321 SLExpressionNode result; |
274 result = Factor(); | 322 result = Factor(); |
275 while (la.kind == 23 || la.kind == 24) { | 323 while (la.kind == 27 || la.kind == 28) { |
276 if (la.kind == 23) { | 324 if (la.kind == 27) { |
277 Get(); | 325 Get(); |
278 } else { | 326 } else { |
279 Get(); | 327 Get(); |
280 } | 328 } |
281 String op = t.val; | 329 String op = t.val; |
282 TypedNode right = Factor(); | 330 SLExpressionNode right = Factor(); |
283 result = factory.createBinary(op, result, right); | 331 result = factory.createBinary(op, result, right); |
284 } | 332 } |
285 return result; | 333 return result; |
286 } | 334 } |
287 | 335 |
288 TypedNode Factor() { | 336 SLExpressionNode Factor() { |
289 TypedNode result; | 337 SLExpressionNode result; |
290 result = null; | 338 result = null; |
291 if (la.kind == 1) { | 339 if (la.kind == 1) { |
292 result = VariableRefOrCall(); | 340 Get(); |
341 String name = t.val; | |
342 if (la.kind == 5) { | |
343 Get(); | |
344 List<SLExpressionNode> parameters = new ArrayList<>(); | |
345 SLExpressionNode parameter; | |
346 if (StartOf(3)) { | |
347 parameter = Expression(); | |
348 parameters.add(parameter); | |
349 while (la.kind == 6) { | |
350 Get(); | |
351 parameter = Expression(); | |
352 parameters.add(parameter); | |
353 } | |
354 } | |
355 result = factory.createCall(factory.createRead(name), parameters); | |
356 Expect(7); | |
357 } else if (la.kind == 29) { | |
358 Get(); | |
359 SLExpressionNode value = Expression(); | |
360 result = factory.createAssignment(name, value); | |
361 } else if (StartOf(4)) { | |
362 result = factory.createRead(name); | |
363 } else SynErr(32); | |
293 } else if (la.kind == 2) { | 364 } else if (la.kind == 2) { |
294 result = StringLiteral(); | 365 Get(); |
366 result = factory.createStringLiteral(t.val.substring(1, t.val.length() - 1)); | |
295 } else if (la.kind == 3) { | 367 } else if (la.kind == 3) { |
296 result = NumericLiteral(); | 368 Get(); |
297 } else if (la.kind == 25) { | 369 result = factory.createNumericLiteral(t.val); |
298 result = Ternary(); | |
299 } else if (la.kind == 5) { | 370 } else if (la.kind == 5) { |
300 Get(); | 371 Get(); |
301 result = Expression(); | 372 result = Expression(); |
302 Expect(7); | 373 Expect(7); |
303 } else SynErr(31); | 374 } else SynErr(33); |
304 return result; | |
305 } | |
306 | |
307 TypedNode VariableRefOrCall() { | |
308 TypedNode result; | |
309 result = VariableRef(); | |
310 if (la.kind == 5 || la.kind == 28) { | |
311 if (la.kind == 5) { | |
312 TypedNode[] parameters = Parameters(); | |
313 result = factory.createCall(result, parameters); | |
314 } else { | |
315 Get(); | |
316 TypedNode assignment = Expression(); | |
317 result = factory.createAssignment(result, assignment); | |
318 } | |
319 } | |
320 return result; | |
321 } | |
322 | |
323 TypedNode StringLiteral() { | |
324 TypedNode result; | |
325 Expect(2); | |
326 result = factory.createStringLiteral(t.val.substring(1, t.val.length() - 1)); | |
327 return result; | |
328 } | |
329 | |
330 TypedNode NumericLiteral() { | |
331 TypedNode result; | |
332 Expect(3); | |
333 result = factory.createNumericLiteral(t.val); | |
334 return result; | |
335 } | |
336 | |
337 TypedNode Ternary() { | |
338 TypedNode result; | |
339 TypedNode condition, thenPart, elsePart; | |
340 Expect(25); | |
341 condition = Expression(); | |
342 Expect(26); | |
343 thenPart = Expression(); | |
344 Expect(27); | |
345 elsePart = Expression(); | |
346 result = factory.createTernary(condition, thenPart, elsePart); | |
347 return result; | |
348 } | |
349 | |
350 TypedNode VariableRef() { | |
351 TypedNode result; | |
352 Expect(1); | |
353 result = factory.createLocal(t.val); | |
354 return result; | |
355 } | |
356 | |
357 TypedNode[] Parameters() { | |
358 TypedNode[] result; | |
359 Expect(5); | |
360 List<TypedNode> parameters = new ArrayList<>(); | |
361 if (StartOf(2)) { | |
362 TypedNode e1 = Expression(); | |
363 parameters.add(e1); | |
364 while (la.kind == 6) { | |
365 Get(); | |
366 TypedNode e2 = Expression(); | |
367 parameters.add(e2); | |
368 } | |
369 } | |
370 result = parameters.toArray(new TypedNode[parameters.size()]); | |
371 Expect(7); | |
372 return result; | 375 return result; |
373 } | 376 } |
374 | 377 |
375 | 378 |
376 | 379 |
382 Expect(0); | 385 Expect(0); |
383 | 386 |
384 } | 387 } |
385 | 388 |
386 private static final boolean[][] set = { | 389 private static final boolean[][] set = { |
387 {T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, | 390 {T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x}, |
388 {x,T,T,T, x,T,x,x, x,x,x,T, x,T,T,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x}, | 391 {x,T,T,T, x,T,x,x, x,x,T,x, T,T,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x}, |
389 {x,T,T,T, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x}, | 392 {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,T, T,x,x,x, x,x,x,x}, |
390 {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,T, T,x,x,x, x,x,x,x, x,x,x} | 393 {x,T,T,T, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x}, |
394 {x,x,x,x, x,x,T,T, x,x,x,T, x,x,x,x, x,T,T,T, T,T,T,T, T,T,T,T, T,x,x,x} | |
391 | 395 |
392 }; | 396 }; |
393 | 397 |
394 public String ParseErrors() { | 398 public static void parseSL(SLContext context, Source source) { |
395 java.io.PrintStream oldStream = System.out; | 399 Parser parser = new Parser(context, source); |
396 | 400 parser.Parse(); |
397 java.io.OutputStream out = new java.io.ByteArrayOutputStream(); | 401 if (parser.errors.errors.size() > 0) { |
398 java.io.PrintStream newStream = new java.io.PrintStream(out); | 402 StringBuilder msg = new StringBuilder("Error(s) parsing script:\n"); |
399 | 403 for (String error : parser.errors.errors) { |
400 errors.errorStream = newStream; | 404 msg.append(error).append("\n"); |
401 | 405 } |
402 Parse(); | 406 throw new SLException(msg.toString()); |
403 | 407 } |
404 String errorStream = out.toString(); | |
405 errors.errorStream = oldStream; | |
406 | |
407 return errorStream; | |
408 | |
409 } | 408 } |
410 } // end Parser | 409 } // end Parser |
411 | 410 |
412 class Errors { | 411 class Errors { |
413 | 412 |
414 public int count = 0; // number of errors detected | 413 protected final List<String> errors = new ArrayList<>(); |
415 public java.io.PrintStream errorStream = System.out; // error messages go to this stream | |
416 public String errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text | 414 public String errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text |
417 | 415 |
418 protected void printMsg(int line, int column, String msg) { | 416 protected void printMsg(int line, int column, String msg) { |
419 StringBuffer b = new StringBuffer(errMsgFormat); | 417 StringBuffer b = new StringBuffer(errMsgFormat); |
420 int pos = b.indexOf("{0}"); | 418 int pos = b.indexOf("{0}"); |
428 b.insert(pos, column); | 426 b.insert(pos, column); |
429 } | 427 } |
430 pos = b.indexOf("{2}"); | 428 pos = b.indexOf("{2}"); |
431 if (pos >= 0) | 429 if (pos >= 0) |
432 b.replace(pos, pos + 3, msg); | 430 b.replace(pos, pos + 3, msg); |
433 errorStream.println(b.toString()); | 431 errors.add(b.toString()); |
434 } | 432 } |
435 | 433 |
436 public void SynErr(int line, int col, int n) { | 434 public void SynErr(int line, int col, int n) { |
437 String s; | 435 String s; |
438 switch (n) { | 436 switch (n) { |
444 case 5: s = "\"(\" expected"; break; | 442 case 5: s = "\"(\" expected"; break; |
445 case 6: s = "\",\" expected"; break; | 443 case 6: s = "\",\" expected"; break; |
446 case 7: s = "\")\" expected"; break; | 444 case 7: s = "\")\" expected"; break; |
447 case 8: s = "\"{\" expected"; break; | 445 case 8: s = "\"{\" expected"; break; |
448 case 9: s = "\"}\" expected"; break; | 446 case 9: s = "\"}\" expected"; break; |
449 case 10: s = "\";\" expected"; break; | 447 case 10: s = "\"break\" expected"; break; |
450 case 11: s = "\"if\" expected"; break; | 448 case 11: s = "\";\" expected"; break; |
451 case 12: s = "\"else\" expected"; break; | 449 case 12: s = "\"continue\" expected"; break; |
452 case 13: s = "\"while\" expected"; break; | 450 case 13: s = "\"if\" expected"; break; |
453 case 14: s = "\"return\" expected"; break; | 451 case 14: s = "\"else\" expected"; break; |
454 case 15: s = "\"<\" expected"; break; | 452 case 15: s = "\"while\" expected"; break; |
455 case 16: s = "\">\" expected"; break; | 453 case 16: s = "\"return\" expected"; break; |
456 case 17: s = "\"<=\" expected"; break; | 454 case 17: s = "\"||\" expected"; break; |
457 case 18: s = "\">=\" expected"; break; | 455 case 18: s = "\"&&\" expected"; break; |
458 case 19: s = "\"==\" expected"; break; | 456 case 19: s = "\"<\" expected"; break; |
459 case 20: s = "\"!=\" expected"; break; | 457 case 20: s = "\">\" expected"; break; |
460 case 21: s = "\"+\" expected"; break; | 458 case 21: s = "\"<=\" expected"; break; |
461 case 22: s = "\"-\" expected"; break; | 459 case 22: s = "\">=\" expected"; break; |
462 case 23: s = "\"*\" expected"; break; | 460 case 23: s = "\"==\" expected"; break; |
463 case 24: s = "\"/\" expected"; break; | 461 case 24: s = "\"!=\" expected"; break; |
464 case 25: s = "\"#\" expected"; break; | 462 case 25: s = "\"+\" expected"; break; |
465 case 26: s = "\"?\" expected"; break; | 463 case 26: s = "\"-\" expected"; break; |
466 case 27: s = "\":\" expected"; break; | 464 case 27: s = "\"*\" expected"; break; |
467 case 28: s = "\"=\" expected"; break; | 465 case 28: s = "\"/\" expected"; break; |
468 case 29: s = "??? expected"; break; | 466 case 29: s = "\"=\" expected"; break; |
469 case 30: s = "invalid Statement"; break; | 467 case 30: s = "??? expected"; break; |
470 case 31: s = "invalid Factor"; break; | 468 case 31: s = "invalid Statement"; break; |
469 case 32: s = "invalid Factor"; break; | |
470 case 33: s = "invalid Factor"; break; | |
471 default: | 471 default: |
472 s = "error " + n; | 472 s = "error " + n; |
473 break; | 473 break; |
474 } | 474 } |
475 printMsg(line, col, s); | 475 printMsg(line, col, s); |
476 count++; | |
477 } | 476 } |
478 | 477 |
479 public void SemErr(int line, int col, String s) { | 478 public void SemErr(int line, int col, String s) { |
480 printMsg(line, col, s); | 479 printMsg(line, col, s); |
481 count++; | |
482 } | 480 } |
483 | 481 |
484 public void SemErr(String s) { | 482 public void SemErr(String s) { |
485 errorStream.println(s); | 483 errors.add(s); |
486 count++; | |
487 } | 484 } |
488 | 485 |
489 public void Warning(int line, int col, String s) { | 486 public void Warning(int line, int col, String s) { |
490 printMsg(line, col, s); | 487 printMsg(line, col, s); |
491 } | 488 } |
492 | 489 |
493 public void Warning(String s) { | 490 public void Warning(String s) { |
494 errorStream.println(s); | 491 errors.add(s); |
495 } | 492 } |
496 } // Errors | 493 } // Errors |
497 | 494 |
498 class FatalError extends RuntimeException { | 495 class FatalError extends RuntimeException { |
499 | 496 |