001 /* The following code was generated by JFlex 1.4 on 2018-09-03 16:10 */ 002 003 package AST; // The generated parser will belong to package AST 004 005 import AST.StateMachineParser.Terminals; // The terminals are implicitly defined in the parser 006 007 008 /** 009 * This class is a scanner generated by 010 * <a href="http://www.jflex.de/">JFlex</a> 1.4 011 * on 2018-09-03 16:10 from the specification file 012 * <tt>/home/csz-naf/examples/StateMachine/spec/StateMachineScanner.flex</tt> 013 */ 014 public final class StateMachineScanner extends beaver.Scanner { 015 016 /** This character denotes the end of file */ 017 public static final int YYEOF = -1; 018 019 /** initial size of the lookahead buffer */ 020 private static final int ZZ_BUFFERSIZE = 16384; 021 022 /** lexical states */ 023 public static final int YYINITIAL = 0; 024 025 /** 026 * Translates characters to character classes 027 */ 028 private static final char [] ZZ_CMAP = { 029 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 2, 0, 1, 3, 5, 5, 030 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 031 1, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 032 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 13, 12, 0, 0, 15, 0, 033 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 034 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 4, 035 0, 8, 4, 4, 4, 9, 4, 4, 4, 4, 4, 4, 4, 4, 11, 4, 036 4, 4, 10, 6, 7, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 5 037 }; 038 039 /** 040 * Translates DFA states to action switch labels. 041 */ 042 private static final int [] ZZ_ACTION = zzUnpackAction(); 043 044 private static final String ZZ_ACTION_PACKED_0 = 045 "\1\0\2\1\3\2\1\3\1\4\1\0\2\2\1\5"+ 046 "\4\2\1\6\1\7"; 047 048 private static int [] zzUnpackAction() { 049 int [] result = new int[18]; 050 int offset = 0; 051 offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); 052 return result; 053 } 054 055 private static int zzUnpackAction(String packed, int offset, int [] result) { 056 int i = 0; /* index in packed string */ 057 int j = offset; /* index in unpacked array */ 058 int l = packed.length(); 059 while (i < l) { 060 int count = packed.charAt(i++); 061 int value = packed.charAt(i++); 062 do result[j++] = value; while (--count > 0); 063 } 064 return j; 065 } 066 067 068 /** 069 * Translates a state to a row index in the transition table 070 */ 071 private static final int [] ZZ_ROWMAP = zzUnpackRowMap(); 072 073 private static final String ZZ_ROWMAP_PACKED_0 = 074 "\0\0\0\20\0\40\0\60\0\100\0\120\0\20\0\20"+ 075 "\0\140\0\160\0\200\0\20\0\220\0\240\0\260\0\300"+ 076 "\0\60\0\60"; 077 078 private static int [] zzUnpackRowMap() { 079 int [] result = new int[18]; 080 int offset = 0; 081 offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); 082 return result; 083 } 084 085 private static int zzUnpackRowMap(String packed, int offset, int [] result) { 086 int i = 0; /* index in packed string */ 087 int j = offset; /* index in unpacked array */ 088 int l = packed.length(); 089 while (i < l) { 090 int high = packed.charAt(i++) << 16; 091 result[j++] = high | packed.charAt(i++); 092 } 093 return j; 094 } 095 096 /** 097 * The transition table of the DFA 098 */ 099 private static final int [] ZZ_TRANS = zzUnpackTrans(); 100 101 private static final String ZZ_TRANS_PACKED_0 = 102 "\1\0\2\2\1\3\1\4\1\0\1\5\1\6\4\4"+ 103 "\1\7\1\10\1\11\23\0\1\2\21\0\10\4\10\0"+ 104 "\3\4\1\12\4\4\10\0\6\4\1\13\1\4\23\0"+ 105 "\1\14\4\0\4\4\1\15\3\4\10\0\4\4\1\16"+ 106 "\3\4\10\0\3\4\1\17\4\4\10\0\7\4\1\20"+ 107 "\10\0\5\4\1\21\2\4\10\0\2\4\1\22\5\4"+ 108 "\4\0"; 109 110 private static int [] zzUnpackTrans() { 111 int [] result = new int[208]; 112 int offset = 0; 113 offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result); 114 return result; 115 } 116 117 private static int zzUnpackTrans(String packed, int offset, int [] result) { 118 int i = 0; /* index in packed string */ 119 int j = offset; /* index in unpacked array */ 120 int l = packed.length(); 121 while (i < l) { 122 int count = packed.charAt(i++); 123 int value = packed.charAt(i++); 124 value--; 125 do result[j++] = value; while (--count > 0); 126 } 127 return j; 128 } 129 130 131 /* error codes */ 132 private static final int ZZ_UNKNOWN_ERROR = 0; 133 private static final int ZZ_NO_MATCH = 1; 134 private static final int ZZ_PUSHBACK_2BIG = 2; 135 136 /* error messages for the codes above */ 137 private static final String ZZ_ERROR_MSG[] = { 138 "Unkown internal scanner error", 139 "Error: could not match input", 140 "Error: pushback value was too large" 141 }; 142 143 /** 144 * ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code> 145 */ 146 private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute(); 147 148 private static final String ZZ_ATTRIBUTE_PACKED_0 = 149 "\1\0\1\11\4\1\2\11\1\0\2\1\1\11\6\1"; 150 151 private static int [] zzUnpackAttribute() { 152 int [] result = new int[18]; 153 int offset = 0; 154 offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); 155 return result; 156 } 157 158 private static int zzUnpackAttribute(String packed, int offset, int [] result) { 159 int i = 0; /* index in packed string */ 160 int j = offset; /* index in unpacked array */ 161 int l = packed.length(); 162 while (i < l) { 163 int count = packed.charAt(i++); 164 int value = packed.charAt(i++); 165 do result[j++] = value; while (--count > 0); 166 } 167 return j; 168 } 169 170 /** the input device */ 171 private java.io.Reader zzReader; 172 173 /** the current state of the DFA */ 174 private int zzState; 175 176 /** the current lexical state */ 177 private int zzLexicalState = YYINITIAL; 178 179 /** this buffer contains the current text to be matched and is 180 the source of the yytext() string */ 181 private char zzBuffer[] = new char[ZZ_BUFFERSIZE]; 182 183 /** the textposition at the last accepting state */ 184 private int zzMarkedPos; 185 186 /** the textposition at the last state to be included in yytext */ 187 private int zzPushbackPos; 188 189 /** the current text position in the buffer */ 190 private int zzCurrentPos; 191 192 /** startRead marks the beginning of the yytext() string in the buffer */ 193 private int zzStartRead; 194 195 /** endRead marks the last character in the buffer, that has been read 196 from input */ 197 private int zzEndRead; 198 199 /** number of newlines encountered up to the start of the matched text */ 200 private int yyline; 201 202 /** the number of characters up to the start of the matched text */ 203 private int yychar; 204 205 /** 206 * the number of characters from the last newline up to the start of the 207 * matched text 208 */ 209 private int yycolumn; 210 211 /** 212 * zzAtBOL == true <=> the scanner is currently at the beginning of a line 213 */ 214 private boolean zzAtBOL = true; 215 216 /** zzAtEOF == true <=> the scanner is at the EOF */ 217 private boolean zzAtEOF; 218 219 /* user code: */ 220 private beaver.Symbol sym(short id) { 221 return new beaver.Symbol(id, yyline + 1, yycolumn + 1, yylength(), yytext()); 222 } 223 224 225 /** 226 * Creates a new scanner 227 * There is also a java.io.InputStream version of this constructor. 228 * 229 * @param in the java.io.Reader to read input from. 230 */ 231 public StateMachineScanner(java.io.Reader in) { 232 this.zzReader = in; 233 } 234 235 /** 236 * Creates a new scanner. 237 * There is also java.io.Reader version of this constructor. 238 * 239 * @param in the java.io.Inputstream to read input from. 240 */ 241 public StateMachineScanner(java.io.InputStream in) { 242 this(new java.io.InputStreamReader(in)); 243 } 244 245 246 /** 247 * Refills the input buffer. 248 * 249 * @return <code>false</code>, iff there was new input. 250 * 251 * @exception java.io.IOException if any I/O-Error occurs 252 */ 253 private boolean zzRefill() throws java.io.IOException { 254 255 /* first: make room (if you can) */ 256 if (zzStartRead > 0) { 257 System.arraycopy(zzBuffer, zzStartRead, 258 zzBuffer, 0, 259 zzEndRead-zzStartRead); 260 261 /* translate stored positions */ 262 zzEndRead-= zzStartRead; 263 zzCurrentPos-= zzStartRead; 264 zzMarkedPos-= zzStartRead; 265 zzPushbackPos-= zzStartRead; 266 zzStartRead = 0; 267 } 268 269 /* is the buffer big enough? */ 270 if (zzCurrentPos >= zzBuffer.length) { 271 /* if not: blow it up */ 272 char newBuffer[] = new char[zzCurrentPos*2]; 273 System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length); 274 zzBuffer = newBuffer; 275 } 276 277 /* finally: fill the buffer with new input */ 278 int numRead = zzReader.read(zzBuffer, zzEndRead, 279 zzBuffer.length-zzEndRead); 280 281 if (numRead < 0) { 282 return true; 283 } 284 else { 285 zzEndRead+= numRead; 286 return false; 287 } 288 } 289 290 291 /** 292 * Closes the input stream. 293 */ 294 public final void yyclose() throws java.io.IOException { 295 zzAtEOF = true; /* indicate end of file */ 296 zzEndRead = zzStartRead; /* invalidate buffer */ 297 298 if (zzReader != null) 299 zzReader.close(); 300 } 301 302 303 /** 304 * Resets the scanner to read from a new input stream. 305 * Does not close the old reader. 306 * 307 * All internal variables are reset, the old input stream 308 * <b>cannot</b> be reused (internal buffer is discarded and lost). 309 * Lexical state is set to <tt>ZZ_INITIAL</tt>. 310 * 311 * @param reader the new input stream 312 */ 313 public final void yyreset(java.io.Reader reader) { 314 zzReader = reader; 315 zzAtBOL = true; 316 zzAtEOF = false; 317 zzEndRead = zzStartRead = 0; 318 zzCurrentPos = zzMarkedPos = zzPushbackPos = 0; 319 yyline = yychar = yycolumn = 0; 320 zzLexicalState = YYINITIAL; 321 } 322 323 324 /** 325 * Returns the current lexical state. 326 */ 327 public final int yystate() { 328 return zzLexicalState; 329 } 330 331 332 /** 333 * Enters a new lexical state 334 * 335 * @param newState the new lexical state 336 */ 337 public final void yybegin(int newState) { 338 zzLexicalState = newState; 339 } 340 341 342 /** 343 * Returns the text matched by the current regular expression. 344 */ 345 public final String yytext() { 346 return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead ); 347 } 348 349 350 /** 351 * Returns the character at position <tt>pos</tt> from the 352 * matched text. 353 * 354 * It is equivalent to yytext().charAt(pos), but faster 355 * 356 * @param pos the position of the character to fetch. 357 * A value from 0 to yylength()-1. 358 * 359 * @return the character at position pos 360 */ 361 public final char yycharat(int pos) { 362 return zzBuffer[zzStartRead+pos]; 363 } 364 365 366 /** 367 * Returns the length of the matched text region. 368 */ 369 public final int yylength() { 370 return zzMarkedPos-zzStartRead; 371 } 372 373 374 /** 375 * Reports an error that occured while scanning. 376 * 377 * In a wellformed scanner (no or only correct usage of 378 * yypushback(int) and a match-all fallback rule) this method 379 * will only be called with things that "Can't Possibly Happen". 380 * If this method is called, something is seriously wrong 381 * (e.g. a JFlex bug producing a faulty scanner etc.). 382 * 383 * Usual syntax/scanner level error handling should be done 384 * in error fallback rules. 385 * 386 * @param errorCode the code of the errormessage to display 387 */ 388 private void zzScanError(int errorCode) { 389 String message; 390 try { 391 message = ZZ_ERROR_MSG[errorCode]; 392 } 393 catch (ArrayIndexOutOfBoundsException e) { 394 message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR]; 395 } 396 397 throw new Error(message); 398 } 399 400 401 /** 402 * Pushes the specified amount of characters back into the input stream. 403 * 404 * They will be read again by then next call of the scanning method 405 * 406 * @param number the number of characters to be read again. 407 * This number must not be greater than yylength()! 408 */ 409 public void yypushback(int number) { 410 if ( number > yylength() ) 411 zzScanError(ZZ_PUSHBACK_2BIG); 412 413 zzMarkedPos -= number; 414 } 415 416 417 /** 418 * Resumes scanning until the next regular expression is matched, 419 * the end of input is encountered or an I/O-Error occurs. 420 * 421 * @return the next token 422 * @exception java.io.IOException if any I/O-Error occurs 423 */ 424 public beaver.Symbol nextToken() throws java.io.IOException, beaver.Scanner.Exception { 425 int zzInput; 426 int zzAction; 427 428 // cached fields: 429 int zzCurrentPosL; 430 int zzMarkedPosL; 431 int zzEndReadL = zzEndRead; 432 char [] zzBufferL = zzBuffer; 433 char [] zzCMapL = ZZ_CMAP; 434 435 int [] zzTransL = ZZ_TRANS; 436 int [] zzRowMapL = ZZ_ROWMAP; 437 int [] zzAttrL = ZZ_ATTRIBUTE; 438 439 while (true) { 440 zzMarkedPosL = zzMarkedPos; 441 442 boolean zzR = false; 443 for (zzCurrentPosL = zzStartRead; zzCurrentPosL < zzMarkedPosL; 444 zzCurrentPosL++) { 445 switch (zzBufferL[zzCurrentPosL]) { 446 case '\u000B': 447 case '\u000C': 448 case '\u0085': 449 case '\u2028': 450 case '\u2029': 451 yyline++; 452 yycolumn = 0; 453 zzR = false; 454 break; 455 case '\r': 456 yyline++; 457 yycolumn = 0; 458 zzR = true; 459 break; 460 case '\n': 461 if (zzR) 462 zzR = false; 463 else { 464 yyline++; 465 yycolumn = 0; 466 } 467 break; 468 default: 469 zzR = false; 470 yycolumn++; 471 } 472 } 473 474 if (zzR) { 475 // peek one character ahead if it is \n (if we have counted one line too much) 476 boolean zzPeek; 477 if (zzMarkedPosL < zzEndReadL) 478 zzPeek = zzBufferL[zzMarkedPosL] == '\n'; 479 else if (zzAtEOF) 480 zzPeek = false; 481 else { 482 boolean eof = zzRefill(); 483 zzMarkedPosL = zzMarkedPos; 484 zzBufferL = zzBuffer; 485 if (eof) 486 zzPeek = false; 487 else 488 zzPeek = zzBufferL[zzMarkedPosL] == '\n'; 489 } 490 if (zzPeek) yyline--; 491 } 492 zzAction = -1; 493 494 zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL; 495 496 zzState = zzLexicalState; 497 498 499 zzForAction: { 500 while (true) { 501 502 if (zzCurrentPosL < zzEndReadL) 503 zzInput = zzBufferL[zzCurrentPosL++]; 504 else if (zzAtEOF) { 505 zzInput = YYEOF; 506 break zzForAction; 507 } 508 else { 509 // store back cached positions 510 zzCurrentPos = zzCurrentPosL; 511 zzMarkedPos = zzMarkedPosL; 512 boolean eof = zzRefill(); 513 // get translated positions and possibly new buffer 514 zzCurrentPosL = zzCurrentPos; 515 zzMarkedPosL = zzMarkedPos; 516 zzBufferL = zzBuffer; 517 zzEndReadL = zzEndRead; 518 if (eof) { 519 zzInput = YYEOF; 520 break zzForAction; 521 } 522 else { 523 zzInput = zzBufferL[zzCurrentPosL++]; 524 } 525 } 526 int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ]; 527 if (zzNext == -1) break zzForAction; 528 zzState = zzNext; 529 530 int zzAttributes = zzAttrL[zzState]; 531 if ( (zzAttributes & 1) == 1 ) { 532 zzAction = zzState; 533 zzMarkedPosL = zzCurrentPosL; 534 if ( (zzAttributes & 8) == 8 ) break zzForAction; 535 } 536 537 } 538 } 539 540 // store back cached position 541 zzMarkedPos = zzMarkedPosL; 542 543 switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) { 544 case 7: 545 { return sym(Terminals.TRANS); 546 } 547 case 8: break; 548 case 6: 549 { return sym(Terminals.STATE); 550 } 551 case 9: break; 552 case 4: 553 { return sym(Terminals.COLON); 554 } 555 case 10: break; 556 case 2: 557 { return sym(Terminals.IDENTIFIER); 558 } 559 case 11: break; 560 case 5: 561 { return sym(Terminals.ARROW); 562 } 563 case 12: break; 564 case 3: 565 { return sym(Terminals.SEMI); 566 } 567 case 13: break; 568 case 1: 569 { 570 } 571 case 14: break; 572 default: 573 if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { 574 zzAtEOF = true; 575 { return sym(Terminals.EOF); } 576 } 577 else { 578 zzScanError(ZZ_NO_MATCH); 579 } 580 } 581 } 582 } 583 584 585 }