001 /* Generated By:JavaCC: Do not edit this line. GeneratedFormulaParserTokenManager.java */ 002 package org.jfree.formula.parser; 003 import java.math.BigDecimal; 004 import java.util.ArrayList; 005 import org.jfree.formula.lvalues.ContextLookup; 006 import org.jfree.formula.lvalues.FormulaFunction; 007 import org.jfree.formula.lvalues.LValue; 008 import org.jfree.formula.lvalues.PostfixTerm; 009 import org.jfree.formula.lvalues.PrefixTerm; 010 import org.jfree.formula.lvalues.StaticValue; 011 import org.jfree.formula.lvalues.Term; 012 import org.jfree.formula.lvalues.DefaultDataTable; 013 import org.jfree.formula.operators.InfixOperator; 014 import org.jfree.formula.operators.OperatorFactory; 015 import org.jfree.formula.operators.PostfixOperator; 016 import org.jfree.formula.operators.PrefixOperator; 017 import org.jfree.formula.typing.coretypes.NumberType; 018 import org.jfree.formula.typing.coretypes.TextType; 019 020 /** Token Manager. */ 021 public class GeneratedFormulaParserTokenManager implements GeneratedFormulaParserConstants 022 { 023 024 /** Debug output. */ 025 public java.io.PrintStream debugStream = System.out; 026 /** Set debug output. */ 027 public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } 028 private int jjStopAtPos(int pos, int kind) 029 { 030 jjmatchedKind = kind; 031 jjmatchedPos = pos; 032 return pos + 1; 033 } 034 private int jjMoveStringLiteralDfa0_0() 035 { 036 switch(curChar) 037 { 038 case 37: 039 jjmatchedKind = 39; 040 return jjMoveNfa_0(0, 0); 041 case 38: 042 jjmatchedKind = 38; 043 return jjMoveNfa_0(0, 0); 044 case 40: 045 jjmatchedKind = 19; 046 return jjMoveNfa_0(0, 0); 047 case 41: 048 jjmatchedKind = 20; 049 return jjMoveNfa_0(0, 0); 050 case 42: 051 jjmatchedKind = 29; 052 return jjMoveNfa_0(0, 0); 053 case 43: 054 jjmatchedKind = 27; 055 return jjMoveNfa_0(0, 0); 056 case 44: 057 jjmatchedKind = 13; 058 return jjMoveNfa_0(0, 0); 059 case 45: 060 jjmatchedKind = 28; 061 return jjMoveNfa_0(0, 0); 062 case 47: 063 jjmatchedKind = 30; 064 return jjMoveNfa_0(0, 0); 065 case 59: 066 jjmatchedKind = 18; 067 return jjMoveNfa_0(0, 0); 068 case 60: 069 jjmatchedKind = 36; 070 return jjMoveStringLiteralDfa1_0(0x600000000L); 071 case 61: 072 jjmatchedKind = 32; 073 return jjMoveNfa_0(0, 0); 074 case 62: 075 jjmatchedKind = 37; 076 return jjMoveStringLiteralDfa1_0(0x800000000L); 077 case 63: 078 jjmatchedKind = 23; 079 return jjMoveNfa_0(0, 0); 080 case 78: 081 return jjMoveStringLiteralDfa1_0(0x1000000000000L); 082 case 91: 083 jjmatchedKind = 21; 084 return jjMoveNfa_0(0, 0); 085 case 93: 086 jjmatchedKind = 22; 087 return jjMoveNfa_0(0, 0); 088 case 94: 089 jjmatchedKind = 31; 090 return jjMoveNfa_0(0, 0); 091 case 110: 092 return jjMoveStringLiteralDfa1_0(0x1000000000000L); 093 case 123: 094 jjmatchedKind = 24; 095 return jjMoveNfa_0(0, 0); 096 case 124: 097 jjmatchedKind = 26; 098 return jjMoveNfa_0(0, 0); 099 case 125: 100 jjmatchedKind = 25; 101 return jjMoveNfa_0(0, 0); 102 default : 103 return jjMoveNfa_0(0, 0); 104 } 105 } 106 private int jjMoveStringLiteralDfa1_0(long active0) 107 { 108 try { curChar = input_stream.readChar(); } 109 catch(java.io.IOException e) { 110 return jjMoveNfa_0(0, 0); 111 } 112 switch(curChar) 113 { 114 case 61: 115 if ((active0 & 0x400000000L) != 0L) 116 { 117 jjmatchedKind = 34; 118 jjmatchedPos = 1; 119 } 120 else if ((active0 & 0x800000000L) != 0L) 121 { 122 jjmatchedKind = 35; 123 jjmatchedPos = 1; 124 } 125 break; 126 case 62: 127 if ((active0 & 0x200000000L) != 0L) 128 { 129 jjmatchedKind = 33; 130 jjmatchedPos = 1; 131 } 132 break; 133 case 85: 134 return jjMoveStringLiteralDfa2_0(active0, 0x1000000000000L); 135 case 117: 136 return jjMoveStringLiteralDfa2_0(active0, 0x1000000000000L); 137 default : 138 break; 139 } 140 return jjMoveNfa_0(0, 1); 141 } 142 private int jjMoveStringLiteralDfa2_0(long old0, long active0) 143 { 144 if (((active0 &= old0)) == 0L) 145 return jjMoveNfa_0(0, 1); 146 try { curChar = input_stream.readChar(); } 147 catch(java.io.IOException e) { 148 return jjMoveNfa_0(0, 1); 149 } 150 switch(curChar) 151 { 152 case 76: 153 return jjMoveStringLiteralDfa3_0(active0, 0x1000000000000L); 154 case 108: 155 return jjMoveStringLiteralDfa3_0(active0, 0x1000000000000L); 156 default : 157 break; 158 } 159 return jjMoveNfa_0(0, 2); 160 } 161 private int jjMoveStringLiteralDfa3_0(long old0, long active0) 162 { 163 if (((active0 &= old0)) == 0L) 164 return jjMoveNfa_0(0, 2); 165 try { curChar = input_stream.readChar(); } 166 catch(java.io.IOException e) { 167 return jjMoveNfa_0(0, 2); 168 } 169 switch(curChar) 170 { 171 case 76: 172 if ((active0 & 0x1000000000000L) != 0L) 173 { 174 jjmatchedKind = 48; 175 jjmatchedPos = 3; 176 } 177 break; 178 case 108: 179 if ((active0 & 0x1000000000000L) != 0L) 180 { 181 jjmatchedKind = 48; 182 jjmatchedPos = 3; 183 } 184 break; 185 default : 186 break; 187 } 188 return jjMoveNfa_0(0, 3); 189 } 190 static final long[] jjbitVec0 = { 191 0xfffffffffffffffeL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL 192 }; 193 static final long[] jjbitVec2 = { 194 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL 195 }; 196 private int jjMoveNfa_0(int startState, int curPos) 197 { 198 int strKind = jjmatchedKind; 199 int strPos = jjmatchedPos; 200 int seenUpto; 201 input_stream.backup(seenUpto = curPos + 1); 202 try { curChar = input_stream.readChar(); } 203 catch(java.io.IOException e) { throw new Error("Internal Error"); } 204 curPos = 0; 205 int startsAt = 0; 206 jjnewStateCnt = 45; 207 int i = 1; 208 jjstateSet[0] = startState; 209 int kind = 0x7fffffff; 210 for (;;) 211 { 212 if (++jjround == 0x7fffffff) 213 ReInitRounds(); 214 if (curChar < 64) 215 { 216 long l = 1L << curChar; 217 do 218 { 219 switch(jjstateSet[--i]) 220 { 221 case 0: 222 if ((0x1ffffffffL & l) != 0L) 223 { 224 if (kind > 1) 225 kind = 1; 226 } 227 else if ((0x3fe000000000000L & l) != 0L) 228 { 229 if (kind > 8) 230 kind = 8; 231 jjCheckNAddStates(0, 5); 232 } 233 else if (curChar == 48) 234 { 235 if (kind > 8) 236 kind = 8; 237 jjCheckNAddStates(6, 8); 238 } 239 else if (curChar == 46) 240 jjCheckNAddStates(9, 12); 241 else if (curChar == 34) 242 jjCheckNAddStates(13, 16); 243 else if (curChar == 36) 244 { 245 if (kind > 40) 246 kind = 40; 247 jjCheckNAddTwoStates(8, 9); 248 } 249 else if (curChar == 45) 250 jjstateSet[jjnewStateCnt++] = 1; 251 break; 252 case 1: 253 if (curChar == 45) 254 jjCheckNAddStates(17, 19); 255 break; 256 case 2: 257 if ((0xffffffffffffdbffL & l) != 0L) 258 jjCheckNAddStates(17, 19); 259 break; 260 case 3: 261 if ((0x2400L & l) != 0L && kind > 2) 262 kind = 2; 263 break; 264 case 4: 265 if (curChar == 10 && kind > 2) 266 kind = 2; 267 break; 268 case 5: 269 if (curChar == 13) 270 jjstateSet[jjnewStateCnt++] = 4; 271 break; 272 case 6: 273 if (curChar == 45) 274 jjstateSet[jjnewStateCnt++] = 1; 275 break; 276 case 7: 277 if (curChar != 36) 278 break; 279 if (kind > 40) 280 kind = 40; 281 jjCheckNAddTwoStates(8, 9); 282 break; 283 case 8: 284 if ((0x3ff001000000000L & l) == 0L) 285 break; 286 if (kind > 40) 287 kind = 40; 288 jjCheckNAddTwoStates(8, 9); 289 break; 290 case 9: 291 if (curChar != 46) 292 break; 293 if (kind > 40) 294 kind = 40; 295 jjCheckNAdd(10); 296 break; 297 case 10: 298 if ((0x3ff001000000000L & l) == 0L) 299 break; 300 if (kind > 40) 301 kind = 40; 302 jjCheckNAdd(10); 303 break; 304 case 13: 305 if (curChar == 34) 306 jjCheckNAddStates(20, 22); 307 break; 308 case 14: 309 jjCheckNAddStates(20, 22); 310 break; 311 case 16: 312 case 17: 313 case 20: 314 if (curChar == 34) 315 jjCheckNAddStates(13, 16); 316 break; 317 case 18: 318 if (curChar == 34) 319 jjstateSet[jjnewStateCnt++] = 17; 320 break; 321 case 21: 322 if ((0xfffffffbffffffffL & l) != 0L) 323 jjCheckNAddStates(13, 16); 324 break; 325 case 22: 326 if (curChar == 34 && kind > 42) 327 kind = 42; 328 break; 329 case 23: 330 if (curChar == 46) 331 jjCheckNAddStates(9, 12); 332 break; 333 case 24: 334 if (curChar == 48) 335 jjCheckNAdd(25); 336 break; 337 case 26: 338 if ((0x280000000000L & l) != 0L) 339 jjCheckNAddTwoStates(27, 28); 340 break; 341 case 27: 342 if (curChar == 48 && kind > 43) 343 kind = 43; 344 break; 345 case 28: 346 if ((0x3fe000000000000L & l) == 0L) 347 break; 348 if (kind > 43) 349 kind = 43; 350 jjCheckNAdd(29); 351 break; 352 case 29: 353 if ((0x3ff000000000000L & l) == 0L) 354 break; 355 if (kind > 43) 356 kind = 43; 357 jjCheckNAdd(29); 358 break; 359 case 30: 360 if ((0x3fe000000000000L & l) != 0L) 361 jjCheckNAddTwoStates(31, 25); 362 break; 363 case 31: 364 if ((0x3ff000000000000L & l) != 0L) 365 jjCheckNAddTwoStates(31, 25); 366 break; 367 case 32: 368 if ((0x3fe000000000000L & l) == 0L) 369 break; 370 if (kind > 43) 371 kind = 43; 372 jjCheckNAdd(33); 373 break; 374 case 33: 375 if ((0x3ff000000000000L & l) == 0L) 376 break; 377 if (kind > 43) 378 kind = 43; 379 jjCheckNAdd(33); 380 break; 381 case 34: 382 if (curChar != 48) 383 break; 384 if (kind > 8) 385 kind = 8; 386 jjCheckNAddStates(6, 8); 387 break; 388 case 35: 389 if (curChar == 46) 390 jjCheckNAddTwoStates(24, 36); 391 break; 392 case 36: 393 if ((0x3fe000000000000L & l) != 0L) 394 jjCheckNAddTwoStates(37, 25); 395 break; 396 case 37: 397 if ((0x3ff000000000000L & l) != 0L) 398 jjCheckNAddTwoStates(37, 25); 399 break; 400 case 38: 401 if (curChar == 46) 402 jjCheckNAddTwoStates(27, 39); 403 break; 404 case 39: 405 if ((0x3fe000000000000L & l) == 0L) 406 break; 407 if (kind > 43) 408 kind = 43; 409 jjCheckNAdd(40); 410 break; 411 case 40: 412 if ((0x3ff000000000000L & l) == 0L) 413 break; 414 if (kind > 43) 415 kind = 43; 416 jjCheckNAdd(40); 417 break; 418 case 41: 419 if ((0x3fe000000000000L & l) == 0L) 420 break; 421 if (kind > 8) 422 kind = 8; 423 jjCheckNAddStates(0, 5); 424 break; 425 case 42: 426 if ((0x3ff000000000000L & l) == 0L) 427 break; 428 if (kind > 8) 429 kind = 8; 430 jjCheckNAdd(42); 431 break; 432 case 43: 433 if ((0x3ff000000000000L & l) != 0L) 434 jjCheckNAddStates(23, 25); 435 break; 436 case 44: 437 if ((0x3ff000000000000L & l) == 0L) 438 break; 439 if (kind > 43) 440 kind = 43; 441 jjCheckNAddTwoStates(44, 38); 442 break; 443 default : break; 444 } 445 } while(i != startsAt); 446 } 447 else if (curChar < 128) 448 { 449 long l = 1L << (curChar & 077); 450 do 451 { 452 switch(jjstateSet[--i]) 453 { 454 case 0: 455 if ((0x7fffffe87fffffeL & l) != 0L) 456 { 457 if (kind > 40) 458 kind = 40; 459 jjCheckNAddTwoStates(8, 9); 460 } 461 else if (curChar == 91) 462 jjCheckNAddStates(20, 22); 463 break; 464 case 2: 465 jjAddStates(17, 19); 466 break; 467 case 7: 468 case 8: 469 if ((0x7fffffe87fffffeL & l) == 0L) 470 break; 471 if (kind > 40) 472 kind = 40; 473 jjCheckNAddTwoStates(8, 9); 474 break; 475 case 10: 476 if ((0x7fffffe87fffffeL & l) == 0L) 477 break; 478 if (kind > 40) 479 kind = 40; 480 jjstateSet[jjnewStateCnt++] = 10; 481 break; 482 case 11: 483 if (curChar == 91) 484 jjCheckNAddStates(20, 22); 485 break; 486 case 12: 487 if (curChar == 92) 488 jjstateSet[jjnewStateCnt++] = 13; 489 break; 490 case 13: 491 if ((0x7fffffe37fffffeL & l) != 0L) 492 jjCheckNAddStates(20, 22); 493 break; 494 case 14: 495 if ((0xffffffffdfffffffL & l) != 0L) 496 jjCheckNAddStates(20, 22); 497 break; 498 case 15: 499 if (curChar == 93 && kind > 41) 500 kind = 41; 501 break; 502 case 19: 503 if (curChar == 92) 504 jjstateSet[jjnewStateCnt++] = 20; 505 break; 506 case 20: 507 if ((0x7fffffe17fffffeL & l) != 0L) 508 jjCheckNAddStates(13, 16); 509 break; 510 case 21: 511 jjCheckNAddStates(13, 16); 512 break; 513 case 25: 514 if ((0x2000000020L & l) != 0L) 515 jjAddStates(26, 28); 516 break; 517 default : break; 518 } 519 } while(i != startsAt); 520 } 521 else 522 { 523 int hiByte = (int)(curChar >> 8); 524 int i1 = hiByte >> 6; 525 long l1 = 1L << (hiByte & 077); 526 int i2 = (curChar & 0xff) >> 6; 527 long l2 = 1L << (curChar & 077); 528 do 529 { 530 switch(jjstateSet[--i]) 531 { 532 case 2: 533 if (jjCanMove_0(hiByte, i1, i2, l1, l2)) 534 jjAddStates(17, 19); 535 break; 536 case 14: 537 if (jjCanMove_0(hiByte, i1, i2, l1, l2)) 538 jjAddStates(20, 22); 539 break; 540 case 21: 541 if (jjCanMove_0(hiByte, i1, i2, l1, l2)) 542 jjAddStates(13, 16); 543 break; 544 default : break; 545 } 546 } while(i != startsAt); 547 } 548 if (kind != 0x7fffffff) 549 { 550 jjmatchedKind = kind; 551 jjmatchedPos = curPos; 552 kind = 0x7fffffff; 553 } 554 ++curPos; 555 if ((i = jjnewStateCnt) == (startsAt = 45 - (jjnewStateCnt = startsAt))) 556 break; 557 try { curChar = input_stream.readChar(); } 558 catch(java.io.IOException e) { break; } 559 } 560 if (jjmatchedPos > strPos) 561 return curPos; 562 563 int toRet = Math.max(curPos, seenUpto); 564 565 if (curPos < toRet) 566 for (i = toRet - Math.min(curPos, seenUpto); i-- > 0; ) 567 try { curChar = input_stream.readChar(); } 568 catch(java.io.IOException e) { throw new Error("Internal Error : Please send a bug report."); } 569 570 if (jjmatchedPos < strPos) 571 { 572 jjmatchedKind = strKind; 573 jjmatchedPos = strPos; 574 } 575 else if (jjmatchedPos == strPos && jjmatchedKind > strKind) 576 jjmatchedKind = strKind; 577 578 return toRet; 579 } 580 static final int[] jjnextStates = { 581 42, 43, 35, 25, 44, 38, 35, 25, 38, 24, 30, 27, 32, 18, 19, 21, 582 22, 2, 3, 5, 12, 14, 15, 43, 35, 25, 26, 27, 28, 583 }; 584 private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2) 585 { 586 switch(hiByte) 587 { 588 case 0: 589 return ((jjbitVec2[i2] & l2) != 0L); 590 default : 591 if ((jjbitVec0[i1] & l1) != 0L) 592 return true; 593 return false; 594 } 595 } 596 597 /** Token literal values. */ 598 public static final String[] jjstrLiteralImages = { 599 "", null, null, null, null, null, null, null, null, null, null, null, null, 600 "\54", null, null, null, null, "\73", "\50", "\51", "\133", "\135", "\77", "\173", 601 "\175", "\174", "\53", "\55", "\52", "\57", "\136", "\75", "\74\76", "\74\75", 602 "\76\75", "\74", "\76", "\46", "\45", null, null, null, null, null, null, null, null, 603 null, }; 604 605 /** Lexer state names. */ 606 public static final String[] lexStateNames = { 607 "DEFAULT", 608 }; 609 static final long[] jjtoToken = { 610 0x10ffffffc2101L, 611 }; 612 static final long[] jjtoSkip = { 613 0x6L, 614 }; 615 protected JavaCharStream input_stream; 616 private final int[] jjrounds = new int[45]; 617 private final int[] jjstateSet = new int[90]; 618 protected char curChar; 619 /** Constructor. */ 620 public GeneratedFormulaParserTokenManager(JavaCharStream stream){ 621 if (JavaCharStream.staticFlag) 622 throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); 623 input_stream = stream; 624 } 625 626 /** Constructor. */ 627 public GeneratedFormulaParserTokenManager(JavaCharStream stream, int lexState){ 628 this(stream); 629 SwitchTo(lexState); 630 } 631 632 /** Reinitialise parser. */ 633 public void ReInit(JavaCharStream stream) 634 { 635 jjmatchedPos = jjnewStateCnt = 0; 636 curLexState = defaultLexState; 637 input_stream = stream; 638 ReInitRounds(); 639 } 640 private void ReInitRounds() 641 { 642 int i; 643 jjround = 0x80000001; 644 for (i = 45; i-- > 0;) 645 jjrounds[i] = 0x80000000; 646 } 647 648 /** Reinitialise parser. */ 649 public void ReInit(JavaCharStream stream, int lexState) 650 { 651 ReInit(stream); 652 SwitchTo(lexState); 653 } 654 655 /** Switch to specified lex state. */ 656 public void SwitchTo(int lexState) 657 { 658 if (lexState >= 1 || lexState < 0) 659 throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE); 660 else 661 curLexState = lexState; 662 } 663 664 protected Token jjFillToken() 665 { 666 final Token t; 667 final String curTokenImage; 668 final int beginLine; 669 final int endLine; 670 final int beginColumn; 671 final int endColumn; 672 String im = jjstrLiteralImages[jjmatchedKind]; 673 curTokenImage = (im == null) ? input_stream.GetImage() : im; 674 beginLine = input_stream.getBeginLine(); 675 beginColumn = input_stream.getBeginColumn(); 676 endLine = input_stream.getEndLine(); 677 endColumn = input_stream.getEndColumn(); 678 t = Token.newToken(jjmatchedKind, curTokenImage); 679 680 t.beginLine = beginLine; 681 t.endLine = endLine; 682 t.beginColumn = beginColumn; 683 t.endColumn = endColumn; 684 685 return t; 686 } 687 688 int curLexState = 0; 689 int defaultLexState = 0; 690 int jjnewStateCnt; 691 int jjround; 692 int jjmatchedPos; 693 int jjmatchedKind; 694 695 /** Get the next Token. */ 696 public Token getNextToken() 697 { 698 Token matchedToken; 699 int curPos = 0; 700 701 EOFLoop : 702 for (;;) 703 { 704 try 705 { 706 curChar = input_stream.BeginToken(); 707 } 708 catch(java.io.IOException e) 709 { 710 jjmatchedKind = 0; 711 matchedToken = jjFillToken(); 712 return matchedToken; 713 } 714 715 jjmatchedKind = 0x7fffffff; 716 jjmatchedPos = 0; 717 curPos = jjMoveStringLiteralDfa0_0(); 718 if (jjmatchedKind != 0x7fffffff) 719 { 720 if (jjmatchedPos + 1 < curPos) 721 input_stream.backup(curPos - jjmatchedPos - 1); 722 if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) 723 { 724 matchedToken = jjFillToken(); 725 return matchedToken; 726 } 727 else 728 { 729 continue EOFLoop; 730 } 731 } 732 int error_line = input_stream.getEndLine(); 733 int error_column = input_stream.getEndColumn(); 734 String error_after = null; 735 boolean EOFSeen = false; 736 try { input_stream.readChar(); input_stream.backup(1); } 737 catch (java.io.IOException e1) { 738 EOFSeen = true; 739 error_after = curPos <= 1 ? "" : input_stream.GetImage(); 740 if (curChar == '\n' || curChar == '\r') { 741 error_line++; 742 error_column = 0; 743 } 744 else 745 error_column++; 746 } 747 if (!EOFSeen) { 748 input_stream.backup(1); 749 error_after = curPos <= 1 ? "" : input_stream.GetImage(); 750 } 751 throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR); 752 } 753 } 754 755 private void jjCheckNAdd(int state) 756 { 757 if (jjrounds[state] != jjround) 758 { 759 jjstateSet[jjnewStateCnt++] = state; 760 jjrounds[state] = jjround; 761 } 762 } 763 private void jjAddStates(int start, int end) 764 { 765 do { 766 jjstateSet[jjnewStateCnt++] = jjnextStates[start]; 767 } while (start++ != end); 768 } 769 private void jjCheckNAddTwoStates(int state1, int state2) 770 { 771 jjCheckNAdd(state1); 772 jjCheckNAdd(state2); 773 } 774 775 private void jjCheckNAddStates(int start, int end) 776 { 777 do { 778 jjCheckNAdd(jjnextStates[start]); 779 } while (start++ != end); 780 } 781 782 }