001 /* Generated By:JavaCC: Do not edit this line. BnfParserTokenManager.java */ 002 package net.hydromatic.clapham.parser.bnf; 003 import java.util.*; 004 import net.hydromatic.clapham.parser.*; 005 006 public class BnfParserTokenManager implements BnfParserConstants 007 { 008 public java.io.PrintStream debugStream = System.out; 009 public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } 010 private final int jjStopStringLiteralDfa_0(int pos, long active0) 011 { 012 switch (pos) 013 { 014 case 0: 015 if ((active0 & 0x800L) != 0L) 016 return 8; 017 return -1; 018 default : 019 return -1; 020 } 021 } 022 private final int jjStartNfa_0(int pos, long active0) 023 { 024 return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1); 025 } 026 private final int jjStopAtPos(int pos, int kind) 027 { 028 jjmatchedKind = kind; 029 jjmatchedPos = pos; 030 return pos + 1; 031 } 032 private final int jjStartNfaWithStates_0(int pos, int kind, int state) 033 { 034 jjmatchedKind = kind; 035 jjmatchedPos = pos; 036 try { curChar = input_stream.readChar(); } 037 catch(java.io.IOException e) { return pos + 1; } 038 return jjMoveNfa_0(state, pos + 1); 039 } 040 private final int jjMoveStringLiteralDfa0_0() 041 { 042 switch(curChar) 043 { 044 case 34: 045 return jjStartNfaWithStates_0(0, 11, 8); 046 case 40: 047 return jjStopAtPos(0, 4); 048 case 41: 049 return jjStopAtPos(0, 5); 050 case 42: 051 return jjStopAtPos(0, 8); 052 case 43: 053 return jjStopAtPos(0, 7); 054 case 47: 055 return jjMoveStringLiteralDfa1_0(0x180000L); 056 case 58: 057 return jjMoveStringLiteralDfa1_0(0x200L); 058 case 63: 059 return jjStopAtPos(0, 6); 060 case 124: 061 return jjStopAtPos(0, 10); 062 default : 063 return jjMoveNfa_0(0, 0); 064 } 065 } 066 private final int jjMoveStringLiteralDfa1_0(long active0) 067 { 068 try { curChar = input_stream.readChar(); } 069 catch(java.io.IOException e) { 070 jjStopStringLiteralDfa_0(0, active0); 071 return 1; 072 } 073 switch(curChar) 074 { 075 case 42: 076 if ((active0 & 0x100000L) != 0L) 077 return jjStopAtPos(1, 20); 078 break; 079 case 47: 080 if ((active0 & 0x80000L) != 0L) 081 return jjStopAtPos(1, 19); 082 break; 083 case 58: 084 return jjMoveStringLiteralDfa2_0(active0, 0x200L); 085 default : 086 break; 087 } 088 return jjStartNfa_0(0, active0); 089 } 090 private final int jjMoveStringLiteralDfa2_0(long old0, long active0) 091 { 092 if (((active0 &= old0)) == 0L) 093 return jjStartNfa_0(0, old0); 094 try { curChar = input_stream.readChar(); } 095 catch(java.io.IOException e) { 096 jjStopStringLiteralDfa_0(1, active0); 097 return 2; 098 } 099 switch(curChar) 100 { 101 case 61: 102 if ((active0 & 0x200L) != 0L) 103 return jjStopAtPos(2, 9); 104 break; 105 default : 106 break; 107 } 108 return jjStartNfa_0(1, active0); 109 } 110 private final void jjCheckNAdd(int state) 111 { 112 if (jjrounds[state] != jjround) 113 { 114 jjstateSet[jjnewStateCnt++] = state; 115 jjrounds[state] = jjround; 116 } 117 } 118 private final void jjAddStates(int start, int end) 119 { 120 do { 121 jjstateSet[jjnewStateCnt++] = jjnextStates[start]; 122 } while (start++ != end); 123 } 124 private final void jjCheckNAddTwoStates(int state1, int state2) 125 { 126 jjCheckNAdd(state1); 127 jjCheckNAdd(state2); 128 } 129 private final void jjCheckNAddStates(int start, int end) 130 { 131 do { 132 jjCheckNAdd(jjnextStates[start]); 133 } while (start++ != end); 134 } 135 private final void jjCheckNAddStates(int start) 136 { 137 jjCheckNAdd(jjnextStates[start]); 138 jjCheckNAdd(jjnextStates[start + 1]); 139 } 140 static final long[] jjbitVec0 = { 141 0x1ff00000fffffffeL, 0xffffffffffffc000L, 0xffffffffL, 0x600000000000000L 142 }; 143 static final long[] jjbitVec2 = { 144 0x0L, 0x0L, 0x0L, 0xff7fffffff7fffffL 145 }; 146 static final long[] jjbitVec3 = { 147 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL 148 }; 149 static final long[] jjbitVec4 = { 150 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffL, 0x0L 151 }; 152 static final long[] jjbitVec5 = { 153 0xffffffffffffffffL, 0xffffffffffffffffL, 0x0L, 0x0L 154 }; 155 static final long[] jjbitVec6 = { 156 0x3fffffffffffL, 0x0L, 0x0L, 0x0L 157 }; 158 static final long[] jjbitVec7 = { 159 0xfffffffffffffffeL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL 160 }; 161 static final long[] jjbitVec8 = { 162 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL 163 }; 164 private final int jjMoveNfa_0(int startState, int curPos) 165 { 166 int[] nextStates; 167 int startsAt = 0; 168 jjnewStateCnt = 8; 169 int i = 1; 170 jjstateSet[0] = startState; 171 int j, kind = 0x7fffffff; 172 for (;;) 173 { 174 if (++jjround == 0x7fffffff) 175 ReInitRounds(); 176 if (curChar < 64) 177 { 178 long l = 1L << curChar; 179 MatchLoop: do 180 { 181 switch(jjstateSet[--i]) 182 { 183 case 0: 184 if (curChar == 34) 185 jjCheckNAddTwoStates(6, 7); 186 else if (curChar == 60) 187 jjCheckNAdd(3); 188 else if (curChar == 36) 189 { 190 if (kind > 1) 191 kind = 1; 192 jjCheckNAdd(1); 193 } 194 break; 195 case 8: 196 if ((0xfffffffbffffffffL & l) != 0L) 197 jjCheckNAddTwoStates(6, 7); 198 else if (curChar == 34) 199 { 200 if (kind > 13) 201 kind = 13; 202 jjstateSet[jjnewStateCnt++] = 5; 203 } 204 break; 205 case 1: 206 if ((0x3ff001000000000L & l) == 0L) 207 break; 208 if (kind > 1) 209 kind = 1; 210 jjCheckNAdd(1); 211 break; 212 case 2: 213 if (curChar == 60) 214 jjCheckNAdd(3); 215 break; 216 case 3: 217 if ((0x3ff001000000000L & l) != 0L) 218 jjCheckNAddTwoStates(3, 4); 219 break; 220 case 4: 221 if (curChar == 62 && kind > 12) 222 kind = 12; 223 break; 224 case 5: 225 if (curChar == 34) 226 jjCheckNAddTwoStates(6, 7); 227 break; 228 case 6: 229 if ((0xfffffffbffffffffL & l) != 0L) 230 jjCheckNAddTwoStates(6, 7); 231 break; 232 case 7: 233 if (curChar != 34) 234 break; 235 if (kind > 13) 236 kind = 13; 237 jjstateSet[jjnewStateCnt++] = 5; 238 break; 239 default : break; 240 } 241 } while(i != startsAt); 242 } 243 else if (curChar < 128) 244 { 245 long l = 1L << (curChar & 077); 246 MatchLoop: do 247 { 248 switch(jjstateSet[--i]) 249 { 250 case 0: 251 case 1: 252 if ((0x7fffffe87fffffeL & l) == 0L) 253 break; 254 if (kind > 1) 255 kind = 1; 256 jjCheckNAdd(1); 257 break; 258 case 8: 259 case 6: 260 jjCheckNAddTwoStates(6, 7); 261 break; 262 case 3: 263 if ((0x7fffffe87fffffeL & l) != 0L) 264 jjAddStates(0, 1); 265 break; 266 default : break; 267 } 268 } while(i != startsAt); 269 } 270 else 271 { 272 int hiByte = (int)(curChar >> 8); 273 int i1 = hiByte >> 6; 274 long l1 = 1L << (hiByte & 077); 275 int i2 = (curChar & 0xff) >> 6; 276 long l2 = 1L << (curChar & 077); 277 MatchLoop: do 278 { 279 switch(jjstateSet[--i]) 280 { 281 case 0: 282 case 1: 283 if (!jjCanMove_0(hiByte, i1, i2, l1, l2)) 284 break; 285 if (kind > 1) 286 kind = 1; 287 jjCheckNAdd(1); 288 break; 289 case 8: 290 case 6: 291 if (jjCanMove_1(hiByte, i1, i2, l1, l2)) 292 jjCheckNAddTwoStates(6, 7); 293 break; 294 case 3: 295 if (jjCanMove_0(hiByte, i1, i2, l1, l2)) 296 jjAddStates(0, 1); 297 break; 298 default : break; 299 } 300 } while(i != startsAt); 301 } 302 if (kind != 0x7fffffff) 303 { 304 jjmatchedKind = kind; 305 jjmatchedPos = curPos; 306 kind = 0x7fffffff; 307 } 308 ++curPos; 309 if ((i = jjnewStateCnt) == (startsAt = 8 - (jjnewStateCnt = startsAt))) 310 return curPos; 311 try { curChar = input_stream.readChar(); } 312 catch(java.io.IOException e) { return curPos; } 313 } 314 } 315 private final int jjMoveStringLiteralDfa0_2() 316 { 317 switch(curChar) 318 { 319 case 42: 320 return jjMoveStringLiteralDfa1_2(0x400000L); 321 default : 322 return 1; 323 } 324 } 325 private final int jjMoveStringLiteralDfa1_2(long active0) 326 { 327 try { curChar = input_stream.readChar(); } 328 catch(java.io.IOException e) { 329 return 1; 330 } 331 switch(curChar) 332 { 333 case 47: 334 if ((active0 & 0x400000L) != 0L) 335 return jjStopAtPos(1, 22); 336 break; 337 default : 338 return 2; 339 } 340 return 2; 341 } 342 private final int jjMoveStringLiteralDfa0_1() 343 { 344 return jjMoveNfa_1(0, 0); 345 } 346 private final int jjMoveNfa_1(int startState, int curPos) 347 { 348 int[] nextStates; 349 int startsAt = 0; 350 jjnewStateCnt = 3; 351 int i = 1; 352 jjstateSet[0] = startState; 353 int j, kind = 0x7fffffff; 354 for (;;) 355 { 356 if (++jjround == 0x7fffffff) 357 ReInitRounds(); 358 if (curChar < 64) 359 { 360 long l = 1L << curChar; 361 MatchLoop: do 362 { 363 switch(jjstateSet[--i]) 364 { 365 case 0: 366 if ((0x2400L & l) != 0L) 367 { 368 if (kind > 21) 369 kind = 21; 370 } 371 if (curChar == 13) 372 jjstateSet[jjnewStateCnt++] = 1; 373 break; 374 case 1: 375 if (curChar == 10 && kind > 21) 376 kind = 21; 377 break; 378 case 2: 379 if (curChar == 13) 380 jjstateSet[jjnewStateCnt++] = 1; 381 break; 382 default : break; 383 } 384 } while(i != startsAt); 385 } 386 else if (curChar < 128) 387 { 388 long l = 1L << (curChar & 077); 389 MatchLoop: do 390 { 391 switch(jjstateSet[--i]) 392 { 393 default : break; 394 } 395 } while(i != startsAt); 396 } 397 else 398 { 399 int hiByte = (int)(curChar >> 8); 400 int i1 = hiByte >> 6; 401 long l1 = 1L << (hiByte & 077); 402 int i2 = (curChar & 0xff) >> 6; 403 long l2 = 1L << (curChar & 077); 404 MatchLoop: do 405 { 406 switch(jjstateSet[--i]) 407 { 408 default : break; 409 } 410 } while(i != startsAt); 411 } 412 if (kind != 0x7fffffff) 413 { 414 jjmatchedKind = kind; 415 jjmatchedPos = curPos; 416 kind = 0x7fffffff; 417 } 418 ++curPos; 419 if ((i = jjnewStateCnt) == (startsAt = 3 - (jjnewStateCnt = startsAt))) 420 return curPos; 421 try { curChar = input_stream.readChar(); } 422 catch(java.io.IOException e) { return curPos; } 423 } 424 } 425 static final int[] jjnextStates = { 426 3, 4, 427 }; 428 private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2) 429 { 430 switch(hiByte) 431 { 432 case 0: 433 return ((jjbitVec2[i2] & l2) != 0L); 434 case 48: 435 return ((jjbitVec3[i2] & l2) != 0L); 436 case 49: 437 return ((jjbitVec4[i2] & l2) != 0L); 438 case 51: 439 return ((jjbitVec5[i2] & l2) != 0L); 440 case 61: 441 return ((jjbitVec6[i2] & l2) != 0L); 442 default : 443 if ((jjbitVec0[i1] & l1) != 0L) 444 return true; 445 return false; 446 } 447 } 448 private static final boolean jjCanMove_1(int hiByte, int i1, int i2, long l1, long l2) 449 { 450 switch(hiByte) 451 { 452 case 0: 453 return ((jjbitVec8[i2] & l2) != 0L); 454 default : 455 if ((jjbitVec7[i1] & l1) != 0L) 456 return true; 457 return false; 458 } 459 } 460 public static final String[] jjstrLiteralImages = { 461 "", null, null, null, "\50", "\51", "\77", "\53", "\52", "\72\72\75", "\174", 462 "\42", null, null, null, null, null, null, null, null, null, null, null, null, }; 463 public static final String[] lexStateNames = { 464 "DEFAULT", 465 "IN_SINGLE_LINE_COMMENT", 466 "IN_MULTI_LINE_COMMENT", 467 }; 468 public static final int[] jjnewLexState = { 469 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 0, 0, -1, 470 }; 471 static final long[] jjtoToken = { 472 0x3ff3L, 473 }; 474 static final long[] jjtoSkip = { 475 0x67c000L, 476 }; 477 static final long[] jjtoSpecial = { 478 0x600000L, 479 }; 480 static final long[] jjtoMore = { 481 0x980000L, 482 }; 483 protected SimpleCharStream input_stream; 484 private final int[] jjrounds = new int[8]; 485 private final int[] jjstateSet = new int[16]; 486 StringBuffer image; 487 int jjimageLen; 488 int lengthOfMatch; 489 protected char curChar; 490 public BnfParserTokenManager(SimpleCharStream stream){ 491 if (SimpleCharStream.staticFlag) 492 throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); 493 input_stream = stream; 494 } 495 public BnfParserTokenManager(SimpleCharStream stream, int lexState){ 496 this(stream); 497 SwitchTo(lexState); 498 } 499 public void ReInit(SimpleCharStream stream) 500 { 501 jjmatchedPos = jjnewStateCnt = 0; 502 curLexState = defaultLexState; 503 input_stream = stream; 504 ReInitRounds(); 505 } 506 private final void ReInitRounds() 507 { 508 int i; 509 jjround = 0x80000001; 510 for (i = 8; i-- > 0;) 511 jjrounds[i] = 0x80000000; 512 } 513 public void ReInit(SimpleCharStream stream, int lexState) 514 { 515 ReInit(stream); 516 SwitchTo(lexState); 517 } 518 public void SwitchTo(int lexState) 519 { 520 if (lexState >= 3 || lexState < 0) 521 throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE); 522 else 523 curLexState = lexState; 524 } 525 526 protected Token jjFillToken() 527 { 528 Token t = Token.newToken(jjmatchedKind); 529 t.kind = jjmatchedKind; 530 String im = jjstrLiteralImages[jjmatchedKind]; 531 t.image = (im == null) ? input_stream.GetImage() : im; 532 t.beginLine = input_stream.getBeginLine(); 533 t.beginColumn = input_stream.getBeginColumn(); 534 t.endLine = input_stream.getEndLine(); 535 t.endColumn = input_stream.getEndColumn(); 536 return t; 537 } 538 539 int curLexState = 0; 540 int defaultLexState = 0; 541 int jjnewStateCnt; 542 int jjround; 543 int jjmatchedPos; 544 int jjmatchedKind; 545 546 public Token getNextToken() 547 { 548 int kind; 549 Token specialToken = null; 550 Token matchedToken; 551 int curPos = 0; 552 553 EOFLoop : 554 for (;;) 555 { 556 try 557 { 558 curChar = input_stream.BeginToken(); 559 } 560 catch(java.io.IOException e) 561 { 562 jjmatchedKind = 0; 563 matchedToken = jjFillToken(); 564 matchedToken.specialToken = specialToken; 565 return matchedToken; 566 } 567 image = null; 568 jjimageLen = 0; 569 570 for (;;) 571 { 572 switch(curLexState) 573 { 574 case 0: 575 try { input_stream.backup(0); 576 while (curChar <= 32 && (0x100003600L & (1L << curChar)) != 0L) 577 curChar = input_stream.BeginToken(); 578 } 579 catch (java.io.IOException e1) { continue EOFLoop; } 580 jjmatchedKind = 0x7fffffff; 581 jjmatchedPos = 0; 582 curPos = jjMoveStringLiteralDfa0_0(); 583 break; 584 case 1: 585 jjmatchedKind = 0x7fffffff; 586 jjmatchedPos = 0; 587 curPos = jjMoveStringLiteralDfa0_1(); 588 if (jjmatchedPos == 0 && jjmatchedKind > 23) 589 { 590 jjmatchedKind = 23; 591 } 592 break; 593 case 2: 594 jjmatchedKind = 0x7fffffff; 595 jjmatchedPos = 0; 596 curPos = jjMoveStringLiteralDfa0_2(); 597 if (jjmatchedPos == 0 && jjmatchedKind > 23) 598 { 599 jjmatchedKind = 23; 600 } 601 break; 602 } 603 if (jjmatchedKind != 0x7fffffff) 604 { 605 if (jjmatchedPos + 1 < curPos) 606 input_stream.backup(curPos - jjmatchedPos - 1); 607 if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) 608 { 609 matchedToken = jjFillToken(); 610 matchedToken.specialToken = specialToken; 611 if (jjnewLexState[jjmatchedKind] != -1) 612 curLexState = jjnewLexState[jjmatchedKind]; 613 return matchedToken; 614 } 615 else if ((jjtoSkip[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) 616 { 617 if ((jjtoSpecial[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) 618 { 619 matchedToken = jjFillToken(); 620 if (specialToken == null) 621 specialToken = matchedToken; 622 else 623 { 624 matchedToken.specialToken = specialToken; 625 specialToken = (specialToken.next = matchedToken); 626 } 627 SkipLexicalActions(matchedToken); 628 } 629 else 630 SkipLexicalActions(null); 631 if (jjnewLexState[jjmatchedKind] != -1) 632 curLexState = jjnewLexState[jjmatchedKind]; 633 continue EOFLoop; 634 } 635 jjimageLen += jjmatchedPos + 1; 636 if (jjnewLexState[jjmatchedKind] != -1) 637 curLexState = jjnewLexState[jjmatchedKind]; 638 curPos = 0; 639 jjmatchedKind = 0x7fffffff; 640 try { 641 curChar = input_stream.readChar(); 642 continue; 643 } 644 catch (java.io.IOException e1) { } 645 } 646 int error_line = input_stream.getEndLine(); 647 int error_column = input_stream.getEndColumn(); 648 String error_after = null; 649 boolean EOFSeen = false; 650 try { input_stream.readChar(); input_stream.backup(1); } 651 catch (java.io.IOException e1) { 652 EOFSeen = true; 653 error_after = curPos <= 1 ? "" : input_stream.GetImage(); 654 if (curChar == '\n' || curChar == '\r') { 655 error_line++; 656 error_column = 0; 657 } 658 else 659 error_column++; 660 } 661 if (!EOFSeen) { 662 input_stream.backup(1); 663 error_after = curPos <= 1 ? "" : input_stream.GetImage(); 664 } 665 throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR); 666 } 667 } 668 } 669 670 void SkipLexicalActions(Token matchedToken) 671 { 672 switch(jjmatchedKind) 673 { 674 default : 675 break; 676 } 677 } 678 }