001// $ANTLR 2.7.5 (20050128): "../src/csheets/core/formula/compiler/NumberSignFormulaCompiler.g" -> "NumberSignFormulaParser.java"$ 002package csheets.core.formula.compiler; 003import antlr.TokenBuffer; 004import antlr.TokenStreamException; 005import antlr.TokenStreamIOException; 006import antlr.ANTLRException; 007import antlr.LLkParser; 008import antlr.Token; 009import antlr.TokenStream; 010import antlr.RecognitionException; 011import antlr.NoViableAltException; 012import antlr.MismatchedTokenException; 013import antlr.SemanticException; 014import antlr.ParserSharedInputState; 015import antlr.collections.impl.BitSet; 016import antlr.collections.AST; 017import java.util.Hashtable; 018import antlr.ASTFactory; 019import antlr.ASTPair; 020import antlr.collections.impl.ASTArray; 021/** 022 * A parser that generates expressions from lists of lexical tokens. 023 * @author Einar Pehrson 024 */ 025public class NumberSignFormulaParser extends antlr.LLkParser implements NumberSignFormulaParserTokenTypes 026 { 027 028protected NumberSignFormulaParser(TokenBuffer tokenBuf, int k) { 029 super(tokenBuf,k); 030 tokenNames = _tokenNames; 031 buildTokenTypeASTClassMap(); 032 astFactory = new ASTFactory(getTokenTypeToASTClassMap()); 033} 034 035public NumberSignFormulaParser(TokenBuffer tokenBuf) { 036 this(tokenBuf,4); 037} 038 039protected NumberSignFormulaParser(TokenStream lexer, int k) { 040 super(lexer,k); 041 tokenNames = _tokenNames; 042 buildTokenTypeASTClassMap(); 043 astFactory = new ASTFactory(getTokenTypeToASTClassMap()); 044} 045 046public NumberSignFormulaParser(TokenStream lexer) { 047 this(lexer,4); 048} 049 050public NumberSignFormulaParser(ParserSharedInputState state) { 051 super(state,4); 052 tokenNames = _tokenNames; 053 buildTokenTypeASTClassMap(); 054 astFactory = new ASTFactory(getTokenTypeToASTClassMap()); 055} 056 057/** 058 * The start rule for formula expressions. 059 */ 060 public final void expression() throws RecognitionException, TokenStreamException { 061 062 returnAST = null; 063 ASTPair currentAST = new ASTPair(); 064 AST expression_AST = null; 065 066 match(NUMBERSIGN); 067 { 068 if ((LA(1)==LBRA)) { 069 sequence(); 070 astFactory.addASTChild(currentAST, returnAST); 071 } 072 else if ((LA(1)==CELL_REF) && (LA(2)==ASSIGN)) { 073 assignment(); 074 astFactory.addASTChild(currentAST, returnAST); 075 } 076 else if ((_tokenSet_0.member(LA(1))) && (_tokenSet_1.member(LA(2)))) { 077 comparison(); 078 astFactory.addASTChild(currentAST, returnAST); 079 } 080 else { 081 throw new NoViableAltException(LT(1), getFilename()); 082 } 083 084 } 085 match(Token.EOF_TYPE); 086 expression_AST = (AST)currentAST.root; 087 returnAST = expression_AST; 088 } 089 090 public final void sequence() throws RecognitionException, TokenStreamException { 091 092 returnAST = null; 093 ASTPair currentAST = new ASTPair(); 094 AST sequence_AST = null; 095 096 match(LBRA); 097 { 098 if ((LA(1)==CELL_REF) && (LA(2)==ASSIGN)) { 099 assignment(); 100 astFactory.addASTChild(currentAST, returnAST); 101 } 102 else if ((_tokenSet_0.member(LA(1))) && (_tokenSet_2.member(LA(2)))) { 103 comparison(); 104 astFactory.addASTChild(currentAST, returnAST); 105 } 106 else { 107 throw new NoViableAltException(LT(1), getFilename()); 108 } 109 110 } 111 { 112 int _cnt7=0; 113 _loop7: 114 do { 115 if ((LA(1)==SEMI)) { 116 AST tmp4_AST = null; 117 tmp4_AST = astFactory.create(LT(1)); 118 astFactory.makeASTRoot(currentAST, tmp4_AST); 119 match(SEMI); 120 { 121 if ((LA(1)==CELL_REF) && (LA(2)==ASSIGN)) { 122 assignment(); 123 astFactory.addASTChild(currentAST, returnAST); 124 } 125 else if ((_tokenSet_0.member(LA(1))) && (_tokenSet_2.member(LA(2)))) { 126 comparison(); 127 astFactory.addASTChild(currentAST, returnAST); 128 } 129 else { 130 throw new NoViableAltException(LT(1), getFilename()); 131 } 132 133 } 134 } 135 else { 136 if ( _cnt7>=1 ) { break _loop7; } else {throw new NoViableAltException(LT(1), getFilename());} 137 } 138 139 _cnt7++; 140 } while (true); 141 } 142 match(RBRA); 143 sequence_AST = (AST)currentAST.root; 144 returnAST = sequence_AST; 145 } 146 147 public final void assignment() throws RecognitionException, TokenStreamException { 148 149 returnAST = null; 150 ASTPair currentAST = new ASTPair(); 151 AST assignment_AST = null; 152 153 AST tmp6_AST = null; 154 tmp6_AST = astFactory.create(LT(1)); 155 astFactory.addASTChild(currentAST, tmp6_AST); 156 match(CELL_REF); 157 AST tmp7_AST = null; 158 tmp7_AST = astFactory.create(LT(1)); 159 astFactory.makeASTRoot(currentAST, tmp7_AST); 160 match(ASSIGN); 161 comparison(); 162 astFactory.addASTChild(currentAST, returnAST); 163 assignment_AST = (AST)currentAST.root; 164 returnAST = assignment_AST; 165 } 166 167 public final void comparison() throws RecognitionException, TokenStreamException { 168 169 returnAST = null; 170 ASTPair currentAST = new ASTPair(); 171 AST comparison_AST = null; 172 173 concatenation(); 174 astFactory.addASTChild(currentAST, returnAST); 175 { 176 switch ( LA(1)) { 177 case EQ: 178 case NEQ: 179 case GT: 180 case LT: 181 case LTEQ: 182 case GTEQ: 183 { 184 { 185 switch ( LA(1)) { 186 case EQ: 187 { 188 AST tmp8_AST = null; 189 tmp8_AST = astFactory.create(LT(1)); 190 astFactory.makeASTRoot(currentAST, tmp8_AST); 191 match(EQ); 192 break; 193 } 194 case NEQ: 195 { 196 AST tmp9_AST = null; 197 tmp9_AST = astFactory.create(LT(1)); 198 astFactory.makeASTRoot(currentAST, tmp9_AST); 199 match(NEQ); 200 break; 201 } 202 case GT: 203 { 204 AST tmp10_AST = null; 205 tmp10_AST = astFactory.create(LT(1)); 206 astFactory.makeASTRoot(currentAST, tmp10_AST); 207 match(GT); 208 break; 209 } 210 case LT: 211 { 212 AST tmp11_AST = null; 213 tmp11_AST = astFactory.create(LT(1)); 214 astFactory.makeASTRoot(currentAST, tmp11_AST); 215 match(LT); 216 break; 217 } 218 case LTEQ: 219 { 220 AST tmp12_AST = null; 221 tmp12_AST = astFactory.create(LT(1)); 222 astFactory.makeASTRoot(currentAST, tmp12_AST); 223 match(LTEQ); 224 break; 225 } 226 case GTEQ: 227 { 228 AST tmp13_AST = null; 229 tmp13_AST = astFactory.create(LT(1)); 230 astFactory.makeASTRoot(currentAST, tmp13_AST); 231 match(GTEQ); 232 break; 233 } 234 default: 235 { 236 throw new NoViableAltException(LT(1), getFilename()); 237 } 238 } 239 } 240 concatenation(); 241 astFactory.addASTChild(currentAST, returnAST); 242 break; 243 } 244 case EOF: 245 case SEMI: 246 case RBRA: 247 case RPAR: 248 { 249 break; 250 } 251 default: 252 { 253 throw new NoViableAltException(LT(1), getFilename()); 254 } 255 } 256 } 257 comparison_AST = (AST)currentAST.root; 258 returnAST = comparison_AST; 259 } 260 261 public final void concatenation() throws RecognitionException, TokenStreamException { 262 263 returnAST = null; 264 ASTPair currentAST = new ASTPair(); 265 AST concatenation_AST = null; 266 267 arithmetic_lowest(); 268 astFactory.addASTChild(currentAST, returnAST); 269 { 270 _loop14: 271 do { 272 if ((LA(1)==AMP)) { 273 AST tmp14_AST = null; 274 tmp14_AST = astFactory.create(LT(1)); 275 astFactory.makeASTRoot(currentAST, tmp14_AST); 276 match(AMP); 277 arithmetic_lowest(); 278 astFactory.addASTChild(currentAST, returnAST); 279 } 280 else { 281 break _loop14; 282 } 283 284 } while (true); 285 } 286 concatenation_AST = (AST)currentAST.root; 287 returnAST = concatenation_AST; 288 } 289 290 public final void arithmetic_lowest() throws RecognitionException, TokenStreamException { 291 292 returnAST = null; 293 ASTPair currentAST = new ASTPair(); 294 AST arithmetic_lowest_AST = null; 295 296 arithmetic_low(); 297 astFactory.addASTChild(currentAST, returnAST); 298 { 299 _loop18: 300 do { 301 if ((LA(1)==PLUS||LA(1)==MINUS)) { 302 { 303 switch ( LA(1)) { 304 case PLUS: 305 { 306 AST tmp15_AST = null; 307 tmp15_AST = astFactory.create(LT(1)); 308 astFactory.makeASTRoot(currentAST, tmp15_AST); 309 match(PLUS); 310 break; 311 } 312 case MINUS: 313 { 314 AST tmp16_AST = null; 315 tmp16_AST = astFactory.create(LT(1)); 316 astFactory.makeASTRoot(currentAST, tmp16_AST); 317 match(MINUS); 318 break; 319 } 320 default: 321 { 322 throw new NoViableAltException(LT(1), getFilename()); 323 } 324 } 325 } 326 arithmetic_low(); 327 astFactory.addASTChild(currentAST, returnAST); 328 } 329 else { 330 break _loop18; 331 } 332 333 } while (true); 334 } 335 arithmetic_lowest_AST = (AST)currentAST.root; 336 returnAST = arithmetic_lowest_AST; 337 } 338 339 public final void arithmetic_low() throws RecognitionException, TokenStreamException { 340 341 returnAST = null; 342 ASTPair currentAST = new ASTPair(); 343 AST arithmetic_low_AST = null; 344 345 arithmetic_medium(); 346 astFactory.addASTChild(currentAST, returnAST); 347 { 348 _loop22: 349 do { 350 if ((LA(1)==MULTI||LA(1)==DIV)) { 351 { 352 switch ( LA(1)) { 353 case MULTI: 354 { 355 AST tmp17_AST = null; 356 tmp17_AST = astFactory.create(LT(1)); 357 astFactory.makeASTRoot(currentAST, tmp17_AST); 358 match(MULTI); 359 break; 360 } 361 case DIV: 362 { 363 AST tmp18_AST = null; 364 tmp18_AST = astFactory.create(LT(1)); 365 astFactory.makeASTRoot(currentAST, tmp18_AST); 366 match(DIV); 367 break; 368 } 369 default: 370 { 371 throw new NoViableAltException(LT(1), getFilename()); 372 } 373 } 374 } 375 arithmetic_medium(); 376 astFactory.addASTChild(currentAST, returnAST); 377 } 378 else { 379 break _loop22; 380 } 381 382 } while (true); 383 } 384 arithmetic_low_AST = (AST)currentAST.root; 385 returnAST = arithmetic_low_AST; 386 } 387 388 public final void arithmetic_medium() throws RecognitionException, TokenStreamException { 389 390 returnAST = null; 391 ASTPair currentAST = new ASTPair(); 392 AST arithmetic_medium_AST = null; 393 394 arithmetic_high(); 395 astFactory.addASTChild(currentAST, returnAST); 396 { 397 switch ( LA(1)) { 398 case POWER: 399 { 400 AST tmp19_AST = null; 401 tmp19_AST = astFactory.create(LT(1)); 402 astFactory.makeASTRoot(currentAST, tmp19_AST); 403 match(POWER); 404 arithmetic_high(); 405 astFactory.addASTChild(currentAST, returnAST); 406 break; 407 } 408 case EOF: 409 case SEMI: 410 case RBRA: 411 case EQ: 412 case NEQ: 413 case GT: 414 case LT: 415 case LTEQ: 416 case GTEQ: 417 case AMP: 418 case PLUS: 419 case MINUS: 420 case MULTI: 421 case DIV: 422 case RPAR: 423 { 424 break; 425 } 426 default: 427 { 428 throw new NoViableAltException(LT(1), getFilename()); 429 } 430 } 431 } 432 arithmetic_medium_AST = (AST)currentAST.root; 433 returnAST = arithmetic_medium_AST; 434 } 435 436 public final void arithmetic_high() throws RecognitionException, TokenStreamException { 437 438 returnAST = null; 439 ASTPair currentAST = new ASTPair(); 440 AST arithmetic_high_AST = null; 441 442 arithmetic_highest(); 443 astFactory.addASTChild(currentAST, returnAST); 444 { 445 switch ( LA(1)) { 446 case PERCENT: 447 { 448 AST tmp20_AST = null; 449 tmp20_AST = astFactory.create(LT(1)); 450 astFactory.makeASTRoot(currentAST, tmp20_AST); 451 match(PERCENT); 452 break; 453 } 454 case EOF: 455 case SEMI: 456 case RBRA: 457 case EQ: 458 case NEQ: 459 case GT: 460 case LT: 461 case LTEQ: 462 case GTEQ: 463 case AMP: 464 case PLUS: 465 case MINUS: 466 case MULTI: 467 case DIV: 468 case POWER: 469 case RPAR: 470 { 471 break; 472 } 473 default: 474 { 475 throw new NoViableAltException(LT(1), getFilename()); 476 } 477 } 478 } 479 arithmetic_high_AST = (AST)currentAST.root; 480 returnAST = arithmetic_high_AST; 481 } 482 483 public final void arithmetic_highest() throws RecognitionException, TokenStreamException { 484 485 returnAST = null; 486 ASTPair currentAST = new ASTPair(); 487 AST arithmetic_highest_AST = null; 488 489 { 490 switch ( LA(1)) { 491 case MINUS: 492 { 493 AST tmp21_AST = null; 494 tmp21_AST = astFactory.create(LT(1)); 495 astFactory.makeASTRoot(currentAST, tmp21_AST); 496 match(MINUS); 497 break; 498 } 499 case CELL_REF: 500 case LPAR: 501 case FUNCTION: 502 case NAME: 503 case NUMBER: 504 case STRING: 505 { 506 break; 507 } 508 default: 509 { 510 throw new NoViableAltException(LT(1), getFilename()); 511 } 512 } 513 } 514 atom(); 515 astFactory.addASTChild(currentAST, returnAST); 516 arithmetic_highest_AST = (AST)currentAST.root; 517 returnAST = arithmetic_highest_AST; 518 } 519 520 public final void atom() throws RecognitionException, TokenStreamException { 521 522 returnAST = null; 523 ASTPair currentAST = new ASTPair(); 524 AST atom_AST = null; 525 526 switch ( LA(1)) { 527 case FUNCTION: 528 { 529 function_call(); 530 astFactory.addASTChild(currentAST, returnAST); 531 atom_AST = (AST)currentAST.root; 532 break; 533 } 534 case CELL_REF: 535 case NAME: 536 { 537 reference(); 538 astFactory.addASTChild(currentAST, returnAST); 539 atom_AST = (AST)currentAST.root; 540 break; 541 } 542 case NUMBER: 543 case STRING: 544 { 545 literal(); 546 astFactory.addASTChild(currentAST, returnAST); 547 atom_AST = (AST)currentAST.root; 548 break; 549 } 550 case LPAR: 551 { 552 match(LPAR); 553 comparison(); 554 astFactory.addASTChild(currentAST, returnAST); 555 match(RPAR); 556 atom_AST = (AST)currentAST.root; 557 break; 558 } 559 default: 560 { 561 throw new NoViableAltException(LT(1), getFilename()); 562 } 563 } 564 returnAST = atom_AST; 565 } 566 567 public final void function_call() throws RecognitionException, TokenStreamException { 568 569 returnAST = null; 570 ASTPair currentAST = new ASTPair(); 571 AST function_call_AST = null; 572 573 AST tmp24_AST = null; 574 tmp24_AST = astFactory.create(LT(1)); 575 astFactory.makeASTRoot(currentAST, tmp24_AST); 576 match(FUNCTION); 577 { 578 switch ( LA(1)) { 579 case CELL_REF: 580 case MINUS: 581 case LPAR: 582 case FUNCTION: 583 case NAME: 584 case NUMBER: 585 case STRING: 586 { 587 { 588 if ((_tokenSet_0.member(LA(1))) && (_tokenSet_2.member(LA(2)))) { 589 comparison(); 590 astFactory.addASTChild(currentAST, returnAST); 591 } 592 else if ((LA(1)==CELL_REF) && (LA(2)==ASSIGN)) { 593 assignment(); 594 astFactory.addASTChild(currentAST, returnAST); 595 } 596 else { 597 throw new NoViableAltException(LT(1), getFilename()); 598 } 599 600 } 601 { 602 _loop35: 603 do { 604 if ((LA(1)==SEMI)) { 605 match(SEMI); 606 { 607 if ((_tokenSet_0.member(LA(1))) && (_tokenSet_2.member(LA(2)))) { 608 comparison(); 609 astFactory.addASTChild(currentAST, returnAST); 610 } 611 else if ((LA(1)==CELL_REF) && (LA(2)==ASSIGN)) { 612 assignment(); 613 astFactory.addASTChild(currentAST, returnAST); 614 } 615 else { 616 throw new NoViableAltException(LT(1), getFilename()); 617 } 618 619 } 620 } 621 else { 622 break _loop35; 623 } 624 625 } while (true); 626 } 627 break; 628 } 629 case RBRA: 630 case RPAR: 631 { 632 break; 633 } 634 default: 635 { 636 throw new NoViableAltException(LT(1), getFilename()); 637 } 638 } 639 } 640 { 641 switch ( LA(1)) { 642 case RPAR: 643 { 644 match(RPAR); 645 break; 646 } 647 case RBRA: 648 { 649 match(RBRA); 650 break; 651 } 652 default: 653 { 654 throw new NoViableAltException(LT(1), getFilename()); 655 } 656 } 657 } 658 function_call_AST = (AST)currentAST.root; 659 returnAST = function_call_AST; 660 } 661 662 public final void reference() throws RecognitionException, TokenStreamException { 663 664 returnAST = null; 665 ASTPair currentAST = new ASTPair(); 666 AST reference_AST = null; 667 668 switch ( LA(1)) { 669 case CELL_REF: 670 { 671 AST tmp28_AST = null; 672 tmp28_AST = astFactory.create(LT(1)); 673 astFactory.addASTChild(currentAST, tmp28_AST); 674 match(CELL_REF); 675 { 676 switch ( LA(1)) { 677 case COLON: 678 { 679 { 680 AST tmp29_AST = null; 681 tmp29_AST = astFactory.create(LT(1)); 682 astFactory.makeASTRoot(currentAST, tmp29_AST); 683 match(COLON); 684 } 685 AST tmp30_AST = null; 686 tmp30_AST = astFactory.create(LT(1)); 687 astFactory.addASTChild(currentAST, tmp30_AST); 688 match(CELL_REF); 689 break; 690 } 691 case EOF: 692 case SEMI: 693 case RBRA: 694 case EQ: 695 case NEQ: 696 case GT: 697 case LT: 698 case LTEQ: 699 case GTEQ: 700 case AMP: 701 case PLUS: 702 case MINUS: 703 case MULTI: 704 case DIV: 705 case POWER: 706 case PERCENT: 707 case RPAR: 708 { 709 break; 710 } 711 default: 712 { 713 throw new NoViableAltException(LT(1), getFilename()); 714 } 715 } 716 } 717 reference_AST = (AST)currentAST.root; 718 break; 719 } 720 case NAME: 721 { 722 AST tmp31_AST = null; 723 tmp31_AST = astFactory.create(LT(1)); 724 astFactory.addASTChild(currentAST, tmp31_AST); 725 match(NAME); 726 reference_AST = (AST)currentAST.root; 727 break; 728 } 729 default: 730 { 731 throw new NoViableAltException(LT(1), getFilename()); 732 } 733 } 734 returnAST = reference_AST; 735 } 736 737 public final void literal() throws RecognitionException, TokenStreamException { 738 739 returnAST = null; 740 ASTPair currentAST = new ASTPair(); 741 AST literal_AST = null; 742 743 switch ( LA(1)) { 744 case NUMBER: 745 { 746 AST tmp32_AST = null; 747 tmp32_AST = astFactory.create(LT(1)); 748 astFactory.addASTChild(currentAST, tmp32_AST); 749 match(NUMBER); 750 literal_AST = (AST)currentAST.root; 751 break; 752 } 753 case STRING: 754 { 755 AST tmp33_AST = null; 756 tmp33_AST = astFactory.create(LT(1)); 757 astFactory.addASTChild(currentAST, tmp33_AST); 758 match(STRING); 759 literal_AST = (AST)currentAST.root; 760 break; 761 } 762 default: 763 { 764 throw new NoViableAltException(LT(1), getFilename()); 765 } 766 } 767 returnAST = literal_AST; 768 } 769 770 771 public static final String[] _tokenNames = { 772 "<0>", 773 "EOF", 774 "<2>", 775 "NULL_TREE_LOOKAHEAD", 776 "NUMBERSIGN", 777 "LBRA", 778 "SEMI", 779 "RBRA", 780 "CELL_REF", 781 "ASSIGN", 782 "EQ", 783 "NEQ", 784 "GT", 785 "LT", 786 "LTEQ", 787 "GTEQ", 788 "AMP", 789 "PLUS", 790 "MINUS", 791 "MULTI", 792 "DIV", 793 "POWER", 794 "PERCENT", 795 "LPAR", 796 "RPAR", 797 "FUNCTION", 798 "COLON", 799 "NAME", 800 "NUMBER", 801 "STRING", 802 "LETTER", 803 "ALPHABETICAL", 804 "QUOT", 805 "DIGIT", 806 "ABS", 807 "EXCL", 808 "COMMA", 809 "WS" 810 }; 811 812 protected void buildTokenTypeASTClassMap() { 813 tokenTypeToASTClassMap=null; 814 }; 815 816 private static final long[] mk_tokenSet_0() { 817 long[] data = { 981729536L, 0L}; 818 return data; 819 } 820 public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0()); 821 private static final long[] mk_tokenSet_1() { 822 long[] data = { 1073741186L, 0L}; 823 return data; 824 } 825 public static final BitSet _tokenSet_1 = new BitSet(mk_tokenSet_1()); 826 private static final long[] mk_tokenSet_2() { 827 long[] data = { 1073741248L, 0L}; 828 return data; 829 } 830 public static final BitSet _tokenSet_2 = new BitSet(mk_tokenSet_2()); 831 832 }