1 2 3 import ro.infoiasi.donald.compiler.cfg.*; 4 import ro.infoiasi.donald.compiler.parser.*; 5 6 12 public class TestLexer implements Lexer { 13 14 15 final public static int YYEOF = -1; 16 17 18 final private static int YY_BUFFERSIZE = 16384; 19 20 21 final public static int YYINITIAL = 0; 22 23 26 final private static char [] yycmap = { 27 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 2, 0, 3, 1, 5, 5, 28 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 29 3, 0, 0, 0, 4, 0, 0, 0, 8, 9, 7, 6, 0, 0, 0, 0, 30 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 31 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 32 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 4, 33 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 34 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 5 35 }; 36 37 40 final private static int yy_rowMap [] = { 41 0, 10, 20, 10, 30, 10, 10, 10, 10 42 }; 43 44 47 final private static String yy_packed0 = 48 "\1\2\1\3\2\4\1\5\1\2\1\6\1\7\1\10"+ 49 "\1\11\14\0\1\4\13\0\2\5\4\0"; 50 51 54 final private static int yytrans [] = yy_unpack(); 55 56 57 58 final private static int YY_UNKNOWN_ERROR = 0; 59 final private static int YY_ILLEGAL_STATE = 1; 60 final private static int YY_NO_MATCH = 2; 61 final private static int YY_PUSHBACK_2BIG = 3; 62 63 64 final private static String YY_ERROR_MSG[] = { 65 "Unkown internal scanner error", 66 "Internal error: unknown state", 67 "Error: could not match input", 68 "Error: pushback value was too large" 69 }; 70 71 74 private final static byte YY_ATTRIBUTE[] = { 75 0, 9, 1, 9, 1, 9, 9, 9, 9 76 }; 77 78 79 private java.io.Reader yy_reader; 80 81 82 private int yy_state; 83 84 85 private int yy_lexical_state = YYINITIAL; 86 87 89 private char yy_buffer[] = new char[YY_BUFFERSIZE]; 90 91 92 private int yy_markedPos; 93 94 95 private int yy_pushbackPos; 96 97 98 private int yy_currentPos; 99 100 101 private int yy_startRead; 102 103 105 private int yy_endRead; 106 107 108 private int yyline; 109 110 111 private int yychar; 112 113 117 private int yycolumn; 118 119 122 private boolean yy_atBOL = true; 123 124 125 private boolean yy_atEOF; 126 127 128 private boolean yy_eof_done; 129 130 131 private Terminals t; 132 public void setTerminals(Terminals t) { 133 this.t = t; 134 } 135 136 137 143 public TestLexer(java.io.Reader in) { 144 this.yy_reader = in; 145 } 146 147 153 public TestLexer(java.io.InputStream in) { 154 this(new java.io.InputStreamReader (in)); 155 } 156 157 162 private static int [] yy_unpack() { 163 int [] trans = new int[40]; 164 int offset = 0; 165 offset = yy_unpack(yy_packed0, offset, trans); 166 return trans; 167 } 168 169 175 private static int yy_unpack(String packed, int offset, int [] trans) { 176 int i = 0; 177 int j = offset; 178 int l = packed.length(); 179 while (i < l) { 180 int count = packed.charAt(i++); 181 int value = packed.charAt(i++); 182 value--; 183 do trans[j++] = value; while (--count > 0); 184 } 185 return j; 186 } 187 188 189 196 private boolean yy_refill() throws java.io.IOException { 197 198 199 if (yy_startRead > 0) { 200 System.arraycopy(yy_buffer, yy_startRead, 201 yy_buffer, 0, 202 yy_endRead-yy_startRead); 203 204 205 yy_endRead-= yy_startRead; 206 yy_currentPos-= yy_startRead; 207 yy_markedPos-= yy_startRead; 208 yy_pushbackPos-= yy_startRead; 209 yy_startRead = 0; 210 } 211 212 213 if (yy_currentPos >= yy_buffer.length) { 214 215 char newBuffer[] = new char[yy_currentPos*2]; 216 System.arraycopy(yy_buffer, 0, newBuffer, 0, yy_buffer.length); 217 yy_buffer = newBuffer; 218 } 219 220 221 int numRead = yy_reader.read(yy_buffer, yy_endRead, 222 yy_buffer.length-yy_endRead); 223 224 if (numRead < 0) { 225 return true; 226 } 227 else { 228 yy_endRead+= numRead; 229 return false; 230 } 231 } 232 233 234 237 final public void yyclose() throws java.io.IOException { 238 yy_atEOF = true; 239 yy_endRead = yy_startRead; 240 241 if (yy_reader != null) 242 yy_reader.close(); 243 } 244 245 246 256 final public void yyreset(java.io.Reader reader) throws java.io.IOException { 257 yyclose(); 258 yy_reader = reader; 259 yy_atBOL = true; 260 yy_atEOF = false; 261 yy_endRead = yy_startRead = 0; 262 yy_currentPos = yy_markedPos = yy_pushbackPos = 0; 263 yyline = yychar = yycolumn = 0; 264 yy_lexical_state = YYINITIAL; 265 } 266 267 268 271 final public int yystate() { 272 return yy_lexical_state; 273 } 274 275 276 281 final public void yybegin(int newState) { 282 yy_lexical_state = newState; 283 } 284 285 286 289 final public String yytext() { 290 return new String ( yy_buffer, yy_startRead, yy_markedPos-yy_startRead ); 291 } 292 293 294 305 final public char yycharat(int pos) { 306 return yy_buffer[yy_startRead+pos]; 307 } 308 309 310 313 final public int yylength() { 314 return yy_markedPos-yy_startRead; 315 } 316 317 318 332 private void yy_ScanError(int errorCode) { 333 String message; 334 try { 335 message = YY_ERROR_MSG[errorCode]; 336 } 337 catch (ArrayIndexOutOfBoundsException e) { 338 message = YY_ERROR_MSG[YY_UNKNOWN_ERROR]; 339 } 340 341 throw new Error (message); 342 } 343 344 345 353 private void yypushback(int number) { 354 if ( number > yylength() ) 355 yy_ScanError(YY_PUSHBACK_2BIG); 356 357 yy_markedPos -= number; 358 } 359 360 361 365 private void yy_do_eof() throws java.io.IOException { 366 if (!yy_eof_done) { 367 yy_eof_done = true; 368 yyclose(); 369 } 370 } 371 372 373 380 public Terminal nextToken() throws java.io.IOException { 381 int yy_input; 382 int yy_action; 383 384 int yy_currentPos_l; 386 int yy_startRead_l; 387 int yy_markedPos_l; 388 int yy_endRead_l = yy_endRead; 389 char [] yy_buffer_l = yy_buffer; 390 char [] yycmap_l = yycmap; 391 392 int [] yytrans_l = yytrans; 393 int [] yy_rowMap_l = yy_rowMap; 394 byte [] yy_attr_l = YY_ATTRIBUTE; 395 396 while (true) { 397 yy_markedPos_l = yy_markedPos; 398 399 boolean yy_r = false; 400 for (yy_currentPos_l = yy_startRead; yy_currentPos_l < yy_markedPos_l; 401 yy_currentPos_l++) { 402 switch (yy_buffer_l[yy_currentPos_l]) { 403 case '\u000B': 404 case '\u000C': 405 case '\u0085': 406 case '\u2028': 407 case '\u2029': 408 yyline++; 409 yycolumn = 0; 410 yy_r = false; 411 break; 412 case '\r': 413 yyline++; 414 yycolumn = 0; 415 yy_r = true; 416 break; 417 case '\n': 418 if (yy_r) 419 yy_r = false; 420 else { 421 yyline++; 422 yycolumn = 0; 423 } 424 break; 425 default: 426 yy_r = false; 427 yycolumn++; 428 } 429 } 430 431 if (yy_r) { 432 boolean yy_peek; 434 if (yy_markedPos_l < yy_endRead_l) 435 yy_peek = yy_buffer_l[yy_markedPos_l] == '\n'; 436 else if (yy_atEOF) 437 yy_peek = false; 438 else { 439 boolean eof = yy_refill(); 440 yy_markedPos_l = yy_markedPos; 441 yy_buffer_l = yy_buffer; 442 if (eof) 443 yy_peek = false; 444 else 445 yy_peek = yy_buffer_l[yy_markedPos_l] == '\n'; 446 } 447 if (yy_peek) yyline--; 448 } 449 yy_action = -1; 450 451 yy_startRead_l = yy_currentPos_l = yy_currentPos = 452 yy_startRead = yy_markedPos_l; 453 454 yy_state = yy_lexical_state; 455 456 457 yy_forAction: { 458 while (true) { 459 460 if (yy_currentPos_l < yy_endRead_l) 461 yy_input = yy_buffer_l[yy_currentPos_l++]; 462 else if (yy_atEOF) { 463 yy_input = YYEOF; 464 break yy_forAction; 465 } 466 else { 467 yy_currentPos = yy_currentPos_l; 469 yy_markedPos = yy_markedPos_l; 470 boolean eof = yy_refill(); 471 yy_currentPos_l = yy_currentPos; 473 yy_markedPos_l = yy_markedPos; 474 yy_buffer_l = yy_buffer; 475 yy_endRead_l = yy_endRead; 476 if (eof) { 477 yy_input = YYEOF; 478 break yy_forAction; 479 } 480 else { 481 yy_input = yy_buffer_l[yy_currentPos_l++]; 482 } 483 } 484 int yy_next = yytrans_l[ yy_rowMap_l[yy_state] + yycmap_l[yy_input] ]; 485 if (yy_next == -1) break yy_forAction; 486 yy_state = yy_next; 487 488 int yy_attributes = yy_attr_l[yy_state]; 489 if ( (yy_attributes & 1) == 1 ) { 490 yy_action = yy_state; 491 yy_markedPos_l = yy_currentPos_l; 492 if ( (yy_attributes & 8) == 8 ) break yy_forAction; 493 } 494 495 } 496 } 497 498 yy_markedPos = yy_markedPos_l; 500 501 switch (yy_action) { 502 503 case 8: 504 { return t.find("RIGHT"); } 505 case 10: break; 506 case 7: 507 { return t.find("LEFT"); } 508 case 11: break; 509 case 5: 510 { return t.find("PLUS"); } 511 case 12: break; 512 case 6: 513 { return t.find("MUL"); } 514 case 13: break; 515 case 2: 516 case 3: 517 { } 518 case 14: break; 519 case 1: 520 { throw new RuntimeException ("illegal character \""+yytext()+"\""); } 521 case 15: break; 522 case 4: 523 { return t.find("a"); } 524 case 16: break; 525 default: 526 if (yy_input == YYEOF && yy_startRead == yy_currentPos) { 527 yy_atEOF = true; 528 yy_do_eof(); 529 { return t.EOF; 530 } 531 } 532 else { 533 yy_ScanError(YY_NO_MATCH); 534 } 535 } 536 } 537 } 538 539 540 } 541
| Popular Tags
|