1 2 package com.micronova.util.cc.json; 3 import java.io.*; 4 import java.util.*; 5 import com.micronova.util.*; 6 7 public class ParserTokenManager implements ParserConstants 8 { 9 public java.io.PrintStream debugStream = System.out; 10 public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } 11 private final int jjStopStringLiteralDfa_0(int pos, long active0) 12 { 13 switch (pos) 14 { 15 case 0: 16 if ((active0 & 0x1c00L) != 0L) 17 { 18 jjmatchedKind = 16; 19 return 17; 20 } 21 return -1; 22 case 1: 23 if ((active0 & 0x1c00L) != 0L) 24 { 25 jjmatchedKind = 16; 26 jjmatchedPos = 1; 27 return 17; 28 } 29 return -1; 30 case 2: 31 if ((active0 & 0x1c00L) != 0L) 32 { 33 jjmatchedKind = 16; 34 jjmatchedPos = 2; 35 return 17; 36 } 37 return -1; 38 case 3: 39 if ((active0 & 0x800L) != 0L) 40 { 41 jjmatchedKind = 16; 42 jjmatchedPos = 3; 43 return 17; 44 } 45 if ((active0 & 0x1400L) != 0L) 46 return 17; 47 return -1; 48 default : 49 return -1; 50 } 51 } 52 private final int jjStartNfa_0(int pos, long active0) 53 { 54 return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1); 55 } 56 private final int jjStopAtPos(int pos, int kind) 57 { 58 jjmatchedKind = kind; 59 jjmatchedPos = pos; 60 return pos + 1; 61 } 62 private final int jjStartNfaWithStates_0(int pos, int kind, int state) 63 { 64 jjmatchedKind = kind; 65 jjmatchedPos = pos; 66 try { curChar = input_stream.readChar(); } 67 catch(java.io.IOException e) { return pos + 1; } 68 return jjMoveNfa_0(state, pos + 1); 69 } 70 private final int jjMoveStringLiteralDfa0_0() 71 { 72 switch(curChar) 73 { 74 case 102: 75 return jjMoveStringLiteralDfa1_0(0x800L); 76 case 110: 77 return jjMoveStringLiteralDfa1_0(0x1000L); 78 case 116: 79 return jjMoveStringLiteralDfa1_0(0x400L); 80 default : 81 return jjMoveNfa_0(1, 0); 82 } 83 } 84 private final int jjMoveStringLiteralDfa1_0(long active0) 85 { 86 try { curChar = input_stream.readChar(); } 87 catch(java.io.IOException e) { 88 jjStopStringLiteralDfa_0(0, active0); 89 return 1; 90 } 91 switch(curChar) 92 { 93 case 97: 94 return jjMoveStringLiteralDfa2_0(active0, 0x800L); 95 case 114: 96 return jjMoveStringLiteralDfa2_0(active0, 0x400L); 97 case 117: 98 return jjMoveStringLiteralDfa2_0(active0, 0x1000L); 99 default : 100 break; 101 } 102 return jjStartNfa_0(0, active0); 103 } 104 private final int jjMoveStringLiteralDfa2_0(long old0, long active0) 105 { 106 if (((active0 &= old0)) == 0L) 107 return jjStartNfa_0(0, old0); 108 try { curChar = input_stream.readChar(); } 109 catch(java.io.IOException e) { 110 jjStopStringLiteralDfa_0(1, active0); 111 return 2; 112 } 113 switch(curChar) 114 { 115 case 108: 116 return jjMoveStringLiteralDfa3_0(active0, 0x1800L); 117 case 117: 118 return jjMoveStringLiteralDfa3_0(active0, 0x400L); 119 default : 120 break; 121 } 122 return jjStartNfa_0(1, active0); 123 } 124 private final int jjMoveStringLiteralDfa3_0(long old0, long active0) 125 { 126 if (((active0 &= old0)) == 0L) 127 return jjStartNfa_0(1, old0); 128 try { curChar = input_stream.readChar(); } 129 catch(java.io.IOException e) { 130 jjStopStringLiteralDfa_0(2, active0); 131 return 3; 132 } 133 switch(curChar) 134 { 135 case 101: 136 if ((active0 & 0x400L) != 0L) 137 return jjStartNfaWithStates_0(3, 10, 17); 138 break; 139 case 108: 140 if ((active0 & 0x1000L) != 0L) 141 return jjStartNfaWithStates_0(3, 12, 17); 142 break; 143 case 115: 144 return jjMoveStringLiteralDfa4_0(active0, 0x800L); 145 default : 146 break; 147 } 148 return jjStartNfa_0(2, active0); 149 } 150 private final int jjMoveStringLiteralDfa4_0(long old0, long active0) 151 { 152 if (((active0 &= old0)) == 0L) 153 return jjStartNfa_0(2, old0); 154 try { curChar = input_stream.readChar(); } 155 catch(java.io.IOException e) { 156 jjStopStringLiteralDfa_0(3, active0); 157 return 4; 158 } 159 switch(curChar) 160 { 161 case 101: 162 if ((active0 & 0x800L) != 0L) 163 return jjStartNfaWithStates_0(4, 11, 17); 164 break; 165 default : 166 break; 167 } 168 return jjStartNfa_0(3, active0); 169 } 170 private final void jjCheckNAdd(int state) 171 { 172 if (jjrounds[state] != jjround) 173 { 174 jjstateSet[jjnewStateCnt++] = state; 175 jjrounds[state] = jjround; 176 } 177 } 178 private final void jjAddStates(int start, int end) 179 { 180 do { 181 jjstateSet[jjnewStateCnt++] = jjnextStates[start]; 182 } while (start++ != end); 183 } 184 private final void jjCheckNAddTwoStates(int state1, int state2) 185 { 186 jjCheckNAdd(state1); 187 jjCheckNAdd(state2); 188 } 189 private final void jjCheckNAddStates(int start, int end) 190 { 191 do { 192 jjCheckNAdd(jjnextStates[start]); 193 } while (start++ != end); 194 } 195 private final void jjCheckNAddStates(int start) 196 { 197 jjCheckNAdd(jjnextStates[start]); 198 jjCheckNAdd(jjnextStates[start + 1]); 199 } 200 static final long[] jjbitVec0 = { 201 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL 202 }; 203 private final int jjMoveNfa_0(int startState, int curPos) 204 { 205 int[] nextStates; 206 int startsAt = 0; 207 jjnewStateCnt = 32; 208 int i = 1; 209 jjstateSet[0] = startState; 210 int j, kind = 0x7fffffff; 211 for (;;) 212 { 213 if (++jjround == 0x7fffffff) 214 ReInitRounds(); 215 if (curChar < 64) 216 { 217 long l = 1L << curChar; 218 MatchLoop: do 219 { 220 switch(jjstateSet[--i]) 221 { 222 case 1: 223 if ((0xfbffef7affffd9ffL & l) != 0L) 224 { 225 if (kind > 16) 226 kind = 16; 227 jjCheckNAdd(17); 228 } 229 else if ((0x100002600L & l) != 0L) 230 { 231 if (kind > 1) 232 kind = 1; 233 jjCheckNAdd(0); 234 } 235 else if (curChar == 39) 236 jjCheckNAddStates(0, 2); 237 else if (curChar == 34) 238 jjCheckNAddStates(3, 5); 239 else if (curChar == 58) 240 { 241 if (kind > 7) 242 kind = 7; 243 } 244 else if (curChar == 44) 245 { 246 if (kind > 6) 247 kind = 6; 248 } 249 if ((0x3ff000000000000L & l) != 0L) 250 { 251 if (kind > 13) 252 kind = 13; 253 jjCheckNAddStates(6, 12); 254 } 255 else if ((0x280000000000L & l) != 0L) 256 jjCheckNAddStates(13, 18); 257 else if (curChar == 46) 258 jjCheckNAddTwoStates(22, 29); 259 break; 260 case 0: 261 if ((0x100002600L & l) == 0L) 262 break; 263 if (kind > 1) 264 kind = 1; 265 jjCheckNAdd(0); 266 break; 267 case 5: 268 if (curChar == 44 && kind > 6) 269 kind = 6; 270 break; 271 case 6: 272 if (curChar == 58 && kind > 7) 273 kind = 7; 274 break; 275 case 7: 276 case 9: 277 if (curChar == 34) 278 jjCheckNAddStates(3, 5); 279 break; 280 case 8: 281 if ((0xfffffffbffffffffL & l) != 0L) 282 jjCheckNAddStates(3, 5); 283 break; 284 case 11: 285 if (curChar == 34 && kind > 8) 286 kind = 8; 287 break; 288 case 12: 289 case 14: 290 if (curChar == 39) 291 jjCheckNAddStates(0, 2); 292 break; 293 case 13: 294 if ((0xffffff7fffffffffL & l) != 0L) 295 jjCheckNAddStates(0, 2); 296 break; 297 case 16: 298 if (curChar == 39 && kind > 9) 299 kind = 9; 300 break; 301 case 17: 302 if ((0xfbffef7affffd9ffL & l) == 0L) 303 break; 304 if (kind > 16) 305 kind = 16; 306 jjCheckNAdd(17); 307 break; 308 case 18: 309 if ((0x280000000000L & l) != 0L) 310 jjCheckNAddStates(13, 18); 311 break; 312 case 19: 313 if ((0x3ff000000000000L & l) == 0L) 314 break; 315 if (kind > 13) 316 kind = 13; 317 jjCheckNAdd(19); 318 break; 319 case 20: 320 if ((0x3ff000000000000L & l) != 0L) 321 jjCheckNAddTwoStates(20, 21); 322 break; 323 case 21: 324 if (curChar == 46) 325 jjCheckNAdd(22); 326 break; 327 case 22: 328 if ((0x3ff000000000000L & l) == 0L) 329 break; 330 if (kind > 14) 331 kind = 14; 332 jjCheckNAdd(22); 333 break; 334 case 23: 335 if ((0x3ff000000000000L & l) != 0L) 336 jjCheckNAddTwoStates(23, 24); 337 break; 338 case 25: 339 if ((0x280000000000L & l) != 0L) 340 jjCheckNAdd(26); 341 break; 342 case 26: 343 if ((0x3ff000000000000L & l) == 0L) 344 break; 345 if (kind > 15) 346 kind = 15; 347 jjCheckNAdd(26); 348 break; 349 case 27: 350 if ((0x3ff000000000000L & l) != 0L) 351 jjCheckNAddTwoStates(27, 28); 352 break; 353 case 28: 354 if (curChar == 46) 355 jjCheckNAdd(29); 356 break; 357 case 29: 358 if ((0x3ff000000000000L & l) != 0L) 359 jjCheckNAddTwoStates(29, 24); 360 break; 361 case 30: 362 if ((0x3ff000000000000L & l) == 0L) 363 break; 364 if (kind > 13) 365 kind = 13; 366 jjCheckNAddStates(6, 12); 367 break; 368 case 31: 369 if (curChar == 46) 370 jjCheckNAddTwoStates(22, 29); 371 break; 372 default : break; 373 } 374 } while(i != startsAt); 375 } 376 else if (curChar < 128) 377 { 378 long l = 1L << (curChar & 077); 379 MatchLoop: do 380 { 381 switch(jjstateSet[--i]) 382 { 383 case 1: 384 if ((0xd7ffffffd7ffffffL & l) != 0L) 385 { 386 if (kind > 16) 387 kind = 16; 388 jjCheckNAdd(17); 389 } 390 else if (curChar == 93) 391 { 392 if (kind > 5) 393 kind = 5; 394 } 395 else if (curChar == 91) 396 { 397 if (kind > 4) 398 kind = 4; 399 } 400 else if (curChar == 125) 401 { 402 if (kind > 3) 403 kind = 3; 404 } 405 else if (curChar == 123) 406 { 407 if (kind > 2) 408 kind = 2; 409 } 410 break; 411 case 2: 412 if (curChar == 125 && kind > 3) 413 kind = 3; 414 break; 415 case 3: 416 if (curChar == 91 && kind > 4) 417 kind = 4; 418 break; 419 case 4: 420 if (curChar == 93 && kind > 5) 421 kind = 5; 422 break; 423 case 8: 424 jjAddStates(3, 5); 425 break; 426 case 10: 427 if (curChar == 92) 428 jjstateSet[jjnewStateCnt++] = 9; 429 break; 430 case 13: 431 jjAddStates(0, 2); 432 break; 433 case 15: 434 if (curChar == 92) 435 jjstateSet[jjnewStateCnt++] = 14; 436 break; 437 case 17: 438 if ((0xd7ffffffd7ffffffL & l) == 0L) 439 break; 440 if (kind > 16) 441 kind = 16; 442 jjCheckNAdd(17); 443 break; 444 case 24: 445 if ((0x2000000020L & l) != 0L) 446 jjAddStates(19, 20); 447 break; 448 default : break; 449 } 450 } while(i != startsAt); 451 } 452 else 453 { 454 int i2 = (curChar & 0xff) >> 6; 455 long l2 = 1L << (curChar & 077); 456 MatchLoop: do 457 { 458 switch(jjstateSet[--i]) 459 { 460 case 1: 461 case 17: 462 if ((jjbitVec0[i2] & l2) == 0L) 463 break; 464 if (kind > 16) 465 kind = 16; 466 jjCheckNAdd(17); 467 break; 468 case 8: 469 if ((jjbitVec0[i2] & l2) != 0L) 470 jjAddStates(3, 5); 471 break; 472 case 13: 473 if ((jjbitVec0[i2] & l2) != 0L) 474 jjAddStates(0, 2); 475 break; 476 default : break; 477 } 478 } while(i != startsAt); 479 } 480 if (kind != 0x7fffffff) 481 { 482 jjmatchedKind = kind; 483 jjmatchedPos = curPos; 484 kind = 0x7fffffff; 485 } 486 ++curPos; 487 if ((i = jjnewStateCnt) == (startsAt = 32 - (jjnewStateCnt = startsAt))) 488 return curPos; 489 try { curChar = input_stream.readChar(); } 490 catch(java.io.IOException e) { return curPos; } 491 } 492 } 493 static final int[] jjnextStates = { 494 13, 15, 16, 8, 10, 11, 19, 20, 21, 23, 27, 28, 24, 19, 20, 21, 495 23, 27, 28, 25, 26, 496 }; 497 public static final String [] jjstrLiteralImages = { 498 "", null, null, null, null, null, null, null, null, null, "\164\162\165\145", 499 "\146\141\154\163\145", "\156\165\154\154", null, null, null, null, }; 500 public static final String [] lexStateNames = { 501 "DEFAULT", 502 }; 503 static final long[] jjtoToken = { 504 0x1fffdL, 505 }; 506 static final long[] jjtoSkip = { 507 0x2L, 508 }; 509 protected SimpleCharStream input_stream; 510 private final int[] jjrounds = new int[32]; 511 private final int[] jjstateSet = new int[64]; 512 protected char curChar; 513 public ParserTokenManager(SimpleCharStream stream){ 514 if (SimpleCharStream.staticFlag) 515 throw new Error ("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); 516 input_stream = stream; 517 } 518 public ParserTokenManager(SimpleCharStream stream, int lexState){ 519 this(stream); 520 SwitchTo(lexState); 521 } 522 public void ReInit(SimpleCharStream stream) 523 { 524 jjmatchedPos = jjnewStateCnt = 0; 525 curLexState = defaultLexState; 526 input_stream = stream; 527 ReInitRounds(); 528 } 529 private final void ReInitRounds() 530 { 531 int i; 532 jjround = 0x80000001; 533 for (i = 32; i-- > 0;) 534 jjrounds[i] = 0x80000000; 535 } 536 public void ReInit(SimpleCharStream stream, int lexState) 537 { 538 ReInit(stream); 539 SwitchTo(lexState); 540 } 541 public void SwitchTo(int lexState) 542 { 543 if (lexState >= 1 || lexState < 0) 544 throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE); 545 else 546 curLexState = lexState; 547 } 548 549 protected Token jjFillToken() 550 { 551 Token t = Token.newToken(jjmatchedKind); 552 t.kind = jjmatchedKind; 553 String im = jjstrLiteralImages[jjmatchedKind]; 554 t.image = (im == null) ? input_stream.GetImage() : im; 555 t.beginLine = input_stream.getBeginLine(); 556 t.beginColumn = input_stream.getBeginColumn(); 557 t.endLine = input_stream.getEndLine(); 558 t.endColumn = input_stream.getEndColumn(); 559 return t; 560 } 561 562 int curLexState = 0; 563 int defaultLexState = 0; 564 int jjnewStateCnt; 565 int jjround; 566 int jjmatchedPos; 567 int jjmatchedKind; 568 569 public Token getNextToken() 570 { 571 int kind; 572 Token specialToken = null; 573 Token matchedToken; 574 int curPos = 0; 575 576 EOFLoop : 577 for (;;) 578 { 579 try 580 { 581 curChar = input_stream.BeginToken(); 582 } 583 catch(java.io.IOException e) 584 { 585 jjmatchedKind = 0; 586 matchedToken = jjFillToken(); 587 return matchedToken; 588 } 589 590 jjmatchedKind = 0x7fffffff; 591 jjmatchedPos = 0; 592 curPos = jjMoveStringLiteralDfa0_0(); 593 if (jjmatchedKind != 0x7fffffff) 594 { 595 if (jjmatchedPos + 1 < curPos) 596 input_stream.backup(curPos - jjmatchedPos - 1); 597 if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) 598 { 599 matchedToken = jjFillToken(); 600 return matchedToken; 601 } 602 else 603 { 604 continue EOFLoop; 605 } 606 } 607 int error_line = input_stream.getEndLine(); 608 int error_column = input_stream.getEndColumn(); 609 String error_after = null; 610 boolean EOFSeen = false; 611 try { input_stream.readChar(); input_stream.backup(1); } 612 catch (java.io.IOException e1) { 613 EOFSeen = true; 614 error_after = curPos <= 1 ? "" : input_stream.GetImage(); 615 if (curChar == '\n' || curChar == '\r') { 616 error_line++; 617 error_column = 0; 618 } 619 else 620 error_column++; 621 } 622 if (!EOFSeen) { 623 input_stream.backup(1); 624 error_after = curPos <= 1 ? "" : input_stream.GetImage(); 625 } 626 throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR); 627 } 628 } 629 630 } 631 | Popular Tags |