00001 package edu.ksu.cis.bandera.specification.parser;
00002
00003
00004
00005 import edu.ksu.cis.bandera.specification.lexer.*;
00006 import edu.ksu.cis.bandera.specification.node.*;
00007 import edu.ksu.cis.bandera.specification.analysis.*;
00008 import java.util.*;
00009
00010 import java.io.DataInputStream;
00011 import java.io.BufferedInputStream;
00012 import java.io.IOException;
00013
00014 public class Parser
00015 {
00016 public final Analysis ignoredTokens = new AnalysisAdapter();
00017
00018 protected Node node;
00019
00020 private final Lexer lexer;
00021 private final ListIterator stack = new LinkedList().listIterator();
00022 private int last_shift;
00023 private int last_pos;
00024 private int last_line;
00025 private Token last_token;
00026 private final TokenIndex converter = new TokenIndex();
00027 private final int[] action = new int[2];
00028
00029 private final static int SHIFT = 0;
00030 private final static int REDUCE = 1;
00031 private final static int ACCEPT = 2;
00032 private final static int ERROR = 3;
00033
00034 private static int[][][] actionTable;
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 private static int[][][] gotoTable;
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 private static String[] errorMessages;
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240 private static int[] errors;
00241
00242
00243
00244 public Parser(Lexer lexer)
00245 {
00246 this.lexer = lexer;
00247
00248 if(actionTable == null)
00249 {
00250 try
00251 {
00252 DataInputStream s = new DataInputStream(
00253 new BufferedInputStream(
00254 Parser.class.getResourceAsStream("parser.dat")));
00255
00256
00257 int length = s.readInt();
00258 actionTable = new int[length][][];
00259 for(int i = 0; i < actionTable.length; i++)
00260 {
00261 length = s.readInt();
00262 actionTable[i] = new int[length][3];
00263 for(int j = 0; j < actionTable[i].length; j++)
00264 {
00265 for(int k = 0; k < 3; k++)
00266 {
00267 actionTable[i][j][k] = s.readInt();
00268 }
00269 }
00270 }
00271
00272
00273 length = s.readInt();
00274 gotoTable = new int[length][][];
00275 for(int i = 0; i < gotoTable.length; i++)
00276 {
00277 length = s.readInt();
00278 gotoTable[i] = new int[length][2];
00279 for(int j = 0; j < gotoTable[i].length; j++)
00280 {
00281 for(int k = 0; k < 2; k++)
00282 {
00283 gotoTable[i][j][k] = s.readInt();
00284 }
00285 }
00286 }
00287
00288
00289 length = s.readInt();
00290 errorMessages = new String[length];
00291 for(int i = 0; i < errorMessages.length; i++)
00292 {
00293 length = s.readInt();
00294 StringBuffer buffer = new StringBuffer();
00295
00296 for(int j = 0; j < length; j++)
00297 {
00298 buffer.append(s.readChar());
00299 }
00300 errorMessages[i] = buffer.toString();
00301 }
00302
00303
00304 length = s.readInt();
00305 errors = new int[length];
00306 for(int i = 0; i < errors.length; i++)
00307 {
00308 errors[i] = s.readInt();
00309 }
00310
00311 s.close();
00312 }
00313 catch(Exception e)
00314 {
00315 throw new RuntimeException("The file \"parser.dat\" is either missing or corrupted.");
00316 }
00317 }
00318 }
00319 protected void filter() throws ParserException, LexerException, IOException
00320 {
00321 }
00322 private int goTo(int index)
00323 {
00324 int state = state();
00325 int low = 1;
00326 int high = gotoTable[index].length - 1;
00327 int value = gotoTable[index][0][1];
00328
00329 while(low <= high)
00330 {
00331 int middle = (low + high) / 2;
00332
00333 if(state < gotoTable[index][middle][0])
00334 {
00335 high = middle - 1;
00336 }
00337 else if(state > gotoTable[index][middle][0])
00338 {
00339 low = middle + 1;
00340 }
00341 else
00342 {
00343 value = gotoTable[index][middle][1];
00344 break;
00345 }
00346 }
00347
00348 return value;
00349 }
00350 private int index(Switchable token)
00351 {
00352 converter.index = -1;
00353 token.apply(converter);
00354 return converter.index;
00355 }
00356 Node new0()
00357 {
00358 XPDef node2 = null;
00359 XPImport node1 = null;
00360 APropertiesUnit node = new APropertiesUnit(node1, node2);
00361 return node;
00362 }
00363 Node new1()
00364 {
00365 XPDef node2 = null;
00366 XPImport node1 = (XPImport) pop();
00367 APropertiesUnit node = new APropertiesUnit(node1, node2);
00368 return node;
00369 }
00370 Node new10()
00371 {
00372 TDoubleQuote node3 = (TDoubleQuote) pop();
00373 XPFormatWord node2 = (XPFormatWord) pop();
00374 TDoubleQuote node1 = (TDoubleQuote) pop();
00375 AFormat node = new AFormat(node1, node2, node3);
00376 return node;
00377 }
00378 Node new11()
00379 {
00380 PFormatWord node2 = (PFormatWord) pop();
00381 XPFormatWord node1 = (XPFormatWord) pop();
00382 X1PFormatWord node = new X1PFormatWord(node1, node2);
00383 return node;
00384 }
00385 Node new12()
00386 {
00387 PFormatWord node1 = (PFormatWord) pop();
00388 X2PFormatWord node = new X2PFormatWord(node1);
00389 return node;
00390 }
00391 Node new13()
00392 {
00393 TRBrace node3 = (TRBrace) pop();
00394 TId node2 = (TId) pop();
00395 TLBrace node1 = (TLBrace) pop();
00396 AHoleFormatWord node = new AHoleFormatWord(node1, node2, node3);
00397 return node;
00398 }
00399 Node new14()
00400 {
00401 TId node1 = (TId) pop();
00402 AIdFormatWord node = new AIdFormatWord(node1);
00403 return node;
00404 }
00405 Node new15()
00406 {
00407 TComma node1 = (TComma) pop();
00408 ACommaFormatWord node = new ACommaFormatWord(node1);
00409 return node;
00410 }
00411 Node new16()
00412 {
00413 TNumber node1 = (TNumber) pop();
00414 ANumberFormatWord node = new ANumberFormatWord(node1);
00415 return node;
00416 }
00417 Node new17()
00418 {
00419 TDot node1 = (TDot) pop();
00420 ADotFormatWord node = new ADotFormatWord(node1);
00421 return node;
00422 }
00423 Node new18()
00424 {
00425 TSemicolon node3 = (TSemicolon) pop();
00426 PImportNames node2 = (PImportNames) pop();
00427 TImport node1 = (TImport) pop();
00428 ATypeImport node = new ATypeImport(node1, node2, node3);
00429 return node;
00430 }
00431 Node new19()
00432 {
00433 TSemicolon node4 = (TSemicolon) pop();
00434 PImportNames node3 = (PImportNames) pop();
00435 TAssertion node2 = (TAssertion) pop();
00436 TImport node1 = (TImport) pop();
00437 AAssertionImport node = new AAssertionImport(node1, node2, node3, node4);
00438 return node;
00439 }
00440 Node new2()
00441 {
00442 PImport node2 = (PImport) pop();
00443 XPImport node1 = (XPImport) pop();
00444 X1PImport node = new X1PImport(node1, node2);
00445 return node;
00446 }
00447 Node new20()
00448 {
00449 TSemicolon node4 = (TSemicolon) pop();
00450 PImportNames node3 = (PImportNames) pop();
00451 TPredicate node2 = (TPredicate) pop();
00452 TImport node1 = (TImport) pop();
00453 APredicateImport node = new APredicateImport(node1, node2, node3, node4);
00454 return node;
00455 }
00456 Node new21()
00457 {
00458 PImportName node1 = (PImportName) pop();
00459 ANameImportNames node = new ANameImportNames(node1);
00460 return node;
00461 }
00462 Node new22()
00463 {
00464 PImportName node3 = (PImportName) pop();
00465 TComma node2 = (TComma) pop();
00466 PImportNames node1 = (PImportNames) pop();
00467 ANamesImportNames node = new ANamesImportNames(node1, node2, node3);
00468 return node;
00469 }
00470 Node new23()
00471 {
00472 TStar node3 = (TStar) pop();
00473 TDot node2 = (TDot) pop();
00474 PName node1 = (PName) pop();
00475 AOnDemandImportName node = new AOnDemandImportName(node1, node2, node3);
00476 return node;
00477 }
00478 Node new24()
00479 {
00480 PName node1 = (PName) pop();
00481 ASpecificImportName node = new ASpecificImportName(node1);
00482 return node;
00483 }
00484 Node new25()
00485 {
00486 TId node1 = (TId) pop();
00487 ASimpleName node = new ASimpleName(node1);
00488 return node;
00489 }
00490 Node new26()
00491 {
00492 TId node3 = (TId) pop();
00493 TDot node2 = (TDot) pop();
00494 PName node1 = (PName) pop();
00495 AQualifiedName node = new AQualifiedName(node1, node2, node3);
00496 return node;
00497 }
00498 Node new27()
00499 {
00500 PAssert node1 = (PAssert) pop();
00501 AAssertDef node = new AAssertDef(node1);
00502 return node;
00503 }
00504 Node new28()
00505 {
00506 PTl node1 = (PTl) pop();
00507 ATlDef node = new ATlDef(node1);
00508 return node;
00509 }
00510 Node new29()
00511 {
00512 TSemicolon node9 = (TSemicolon) pop();
00513 TRBrace node8 = (TRBrace) pop();
00514 PNames node7 = (PNames) pop();
00515 TLBrace node6 = (TLBrace) pop();
00516 TAssertions node5 = (TAssertions) pop();
00517 TEnable node4 = (TEnable) pop();
00518 TColon node3 = (TColon) pop();
00519 TId node2 = (TId) pop();
00520 TDocumentationComment node1 = null;
00521 AAssert node = new AAssert(node1, node2, node3, node4, node5, node6, node7, node8, node9);
00522 return node;
00523 }
00524 Node new3()
00525 {
00526 PImport node1 = (PImport) pop();
00527 X2PImport node = new X2PImport(node1);
00528 return node;
00529 }
00530 Node new30()
00531 {
00532 TSemicolon node9 = (TSemicolon) pop();
00533 TRBrace node8 = (TRBrace) pop();
00534 PNames node7 = (PNames) pop();
00535 TLBrace node6 = (TLBrace) pop();
00536 TAssertions node5 = (TAssertions) pop();
00537 TEnable node4 = (TEnable) pop();
00538 TColon node3 = (TColon) pop();
00539 TId node2 = (TId) pop();
00540 TDocumentationComment node1 = (TDocumentationComment) pop();
00541 AAssert node = new AAssert(node1, node2, node3, node4, node5, node6, node7, node8, node9);
00542 return node;
00543 }
00544 Node new31()
00545 {
00546 PName node1 = (PName) pop();
00547 ANameNames node = new ANameNames(node1);
00548 return node;
00549 }
00550 Node new32()
00551 {
00552 PName node3 = (PName) pop();
00553 TComma node2 = (TComma) pop();
00554 PNames node1 = (PNames) pop();
00555 ANamesNames node = new ANamesNames(node1, node2, node3);
00556 return node;
00557 }
00558 Node new33()
00559 {
00560 TSemicolon node6 = (TSemicolon) pop();
00561 XPWord node5 = (XPWord) pop();
00562 XPQtl node4 = null;
00563 TColon node3 = (TColon) pop();
00564 TId node2 = (TId) pop();
00565 TDocumentationComment node1 = null;
00566 ATl node = new ATl(node1, node2, node3, node4, node5, node6);
00567 return node;
00568 }
00569 Node new34()
00570 {
00571 PWord node2 = (PWord) pop();
00572 XPWord node1 = (XPWord) pop();
00573 X1PWord node = new X1PWord(node1, node2);
00574 return node;
00575 }
00576 Node new35()
00577 {
00578 PWord node1 = (PWord) pop();
00579 X2PWord node = new X2PWord(node1);
00580 return node;
00581 }
00582 Node new36()
00583 {
00584 TSemicolon node6 = (TSemicolon) pop();
00585 XPWord node5 = (XPWord) pop();
00586 XPQtl node4 = null;
00587 TColon node3 = (TColon) pop();
00588 TId node2 = (TId) pop();
00589 TDocumentationComment node1 = (TDocumentationComment) pop();
00590 ATl node = new ATl(node1, node2, node3, node4, node5, node6);
00591 return node;
00592 }
00593 Node new37()
00594 {
00595 TSemicolon node6 = (TSemicolon) pop();
00596 XPWord node5 = (XPWord) pop();
00597 XPQtl node4 = (XPQtl) pop();
00598 TColon node3 = (TColon) pop();
00599 TId node2 = (TId) pop();
00600 TDocumentationComment node1 = null;
00601 ATl node = new ATl(node1, node2, node3, node4, node5, node6);
00602 return node;
00603 }
00604 Node new38()
00605 {
00606 PQtl node2 = (PQtl) pop();
00607 XPQtl node1 = (XPQtl) pop();
00608 X1PQtl node = new X1PQtl(node1, node2);
00609 return node;
00610 }
00611 Node new39()
00612 {
00613 PQtl node1 = (PQtl) pop();
00614 X2PQtl node = new X2PQtl(node1);
00615 return node;
00616 }
00617 Node new4()
00618 {
00619 XPDef node2 = (XPDef) pop();
00620 XPImport node1 = null;
00621 APropertiesUnit node = new APropertiesUnit(node1, node2);
00622 return node;
00623 }
00624 Node new40()
00625 {
00626 TSemicolon node6 = (TSemicolon) pop();
00627 XPWord node5 = (XPWord) pop();
00628 XPQtl node4 = (XPQtl) pop();
00629 TColon node3 = (TColon) pop();
00630 TId node2 = (TId) pop();
00631 TDocumentationComment node1 = (TDocumentationComment) pop();
00632 ATl node = new ATl(node1, node2, node3, node4, node5, node6);
00633 return node;
00634 }
00635 Node new41()
00636 {
00637 TDot node7 = (TDot) pop();
00638 TRBracket node6 = (TRBracket) pop();
00639 PTypeExp node5 = (PTypeExp) pop();
00640 PQtlBinding node4 = (PQtlBinding) pop();
00641 PIds node3 = (PIds) pop();
00642 TLBracket node2 = (TLBracket) pop();
00643 TForall node1 = (TForall) pop();
00644 AQtl node = new AQtl(node1, node2, node3, node4, node5, node6, node7);
00645 return node;
00646 }
00647 Node new42()
00648 {
00649 TColon node1 = (TColon) pop();
00650 AExactQtlBinding node = new AExactQtlBinding(node1);
00651 return node;
00652 }
00653 Node new43()
00654 {
00655 TInstance node1 = (TInstance) pop();
00656 AInstanceQtlBinding node = new AInstanceQtlBinding(node1);
00657 return node;
00658 }
00659 Node new44()
00660 {
00661 PPrimaryTypeExp node1 = (PPrimaryTypeExp) pop();
00662 APrimaryTypeExp node = new APrimaryTypeExp(node1);
00663 return node;
00664 }
00665 Node new45()
00666 {
00667 PTypeExp node3 = (PTypeExp) pop();
00668 PTypeOp node2 = (PTypeOp) pop();
00669 PPrimaryTypeExp node1 = (PPrimaryTypeExp) pop();
00670 AOpTypeExp node = new AOpTypeExp(node1, node2, node3);
00671 return node;
00672 }
00673 Node new46()
00674 {
00675 PName node1 = (PName) pop();
00676 ANamePrimaryTypeExp node = new ANamePrimaryTypeExp(node1);
00677 return node;
00678 }
00679 Node new47()
00680 {
00681 TRParen node3 = (TRParen) pop();
00682 PTypeExp node2 = (PTypeExp) pop();
00683 TLParen node1 = (TLParen) pop();
00684 AParenPrimaryTypeExp node = new AParenPrimaryTypeExp(node1, node2, node3);
00685 return node;
00686 }
00687 Node new48()
00688 {
00689 TMinus node1 = (TMinus) pop();
00690 AFilterTypeOp node = new AFilterTypeOp(node1);
00691 return node;
00692 }
00693 Node new49()
00694 {
00695 TPlus node1 = (TPlus) pop();
00696 AUnionTypeOp node = new AUnionTypeOp(node1);
00697 return node;
00698 }
00699 Node new5()
00700 {
00701 PDef node2 = (PDef) pop();
00702 XPDef node1 = (XPDef) pop();
00703 X1PDef node = new X1PDef(node1, node2);
00704 return node;
00705 }
00706 Node new50()
00707 {
00708 TId node1 = (TId) pop();
00709 AIdIds node = new AIdIds(node1);
00710 return node;
00711 }
00712 Node new51()
00713 {
00714 TId node3 = (TId) pop();
00715 TComma node2 = (TComma) pop();
00716 PIds node1 = (PIds) pop();
00717 AIdsIds node = new AIdsIds(node1, node2, node3);
00718 return node;
00719 }
00720 Node new52()
00721 {
00722 TRBrace node3 = (TRBrace) pop();
00723 PExp node2 = (PExp) pop();
00724 TLBrace node1 = (TLBrace) pop();
00725 AExpWord node = new AExpWord(node1, node2, node3);
00726 return node;
00727 }
00728 Node new53()
00729 {
00730 TId node1 = (TId) pop();
00731 AIdWord node = new AIdWord(node1);
00732 return node;
00733 }
00734 Node new54()
00735 {
00736 TComma node1 = (TComma) pop();
00737 ACommaWord node = new ACommaWord(node1);
00738 return node;
00739 }
00740 Node new55()
00741 {
00742 TNumber node1 = (TNumber) pop();
00743 ANumberWord node = new ANumberWord(node1);
00744 return node;
00745 }
00746 Node new56()
00747 {
00748 TDot node1 = (TDot) pop();
00749 ADotWord node = new ADotWord(node1);
00750 return node;
00751 }
00752 Node new57()
00753 {
00754 PImplicationExp node1 = (PImplicationExp) pop();
00755 AImplicationExp node = new AImplicationExp(node1);
00756 return node;
00757 }
00758 Node new58()
00759 {
00760 TId node1 = (TId) pop();
00761 AIdArgs node = new AIdArgs(node1);
00762 return node;
00763 }
00764 Node new59()
00765 {
00766 TId node3 = (TId) pop();
00767 TComma node2 = (TComma) pop();
00768 PArgs node1 = (PArgs) pop();
00769 AArgsArgs node = new AArgsArgs(node1, node2, node3);
00770 return node;
00771 }
00772 Node new6()
00773 {
00774 PDef node1 = (PDef) pop();
00775 X2PDef node = new X2PDef(node1);
00776 return node;
00777 }
00778 Node new60()
00779 {
00780 POrExp node1 = (POrExp) pop();
00781 AOrImplicationExp node = new AOrImplicationExp(node1);
00782 return node;
00783 }
00784 Node new61()
00785 {
00786 POrExp node3 = (POrExp) pop();
00787 TImply node2 = (TImply) pop();
00788 PImplicationExp node1 = (PImplicationExp) pop();
00789 AImplyImplicationExp node = new AImplyImplicationExp(node1, node2, node3);
00790 return node;
00791 }
00792 Node new62()
00793 {
00794 PAndExp node1 = (PAndExp) pop();
00795 AAndOrExp node = new AAndOrExp(node1);
00796 return node;
00797 }
00798 Node new63()
00799 {
00800 PAndExp node3 = (PAndExp) pop();
00801 TOr node2 = (TOr) pop();
00802 POrExp node1 = (POrExp) pop();
00803 AOrOrExp node = new AOrOrExp(node1, node2, node3);
00804 return node;
00805 }
00806 Node new64()
00807 {
00808 PUnaryExp node1 = (PUnaryExp) pop();
00809 AUnaryAndExp node = new AUnaryAndExp(node1);
00810 return node;
00811 }
00812 Node new65()
00813 {
00814 PUnaryExp node3 = (PUnaryExp) pop();
00815 TAnd node2 = (TAnd) pop();
00816 PAndExp node1 = (PAndExp) pop();
00817 AAndAndExp node = new AAndAndExp(node1, node2, node3);
00818 return node;
00819 }
00820 Node new66()
00821 {
00822 PPrimaryExp node1 = (PPrimaryExp) pop();
00823 APrimaryUnaryExp node = new APrimaryUnaryExp(node1);
00824 return node;
00825 }
00826 Node new67()
00827 {
00828 PPrimaryExp node2 = (PPrimaryExp) pop();
00829 TNot node1 = (TNot) pop();
00830 AComplementUnaryExp node = new AComplementUnaryExp(node1, node2);
00831 return node;
00832 }
00833 Node new68()
00834 {
00835 TRParen node4 = (TRParen) pop();
00836 PArgs node3 = null;
00837 TLParen node2 = (TLParen) pop();
00838 PName node1 = (PName) pop();
00839 APredicatePrimaryExp node = new APredicatePrimaryExp(node1, node2, node3, node4);
00840 return node;
00841 }
00842 Node new69()
00843 {
00844 TRParen node4 = (TRParen) pop();
00845 PArgs node3 = (PArgs) pop();
00846 TLParen node2 = (TLParen) pop();
00847 PName node1 = (PName) pop();
00848 APredicatePrimaryExp node = new APredicatePrimaryExp(node1, node2, node3, node4);
00849 return node;
00850 }
00851 Node new7()
00852 {
00853 XPDef node2 = (XPDef) pop();
00854 XPImport node1 = (XPImport) pop();
00855 APropertiesUnit node = new APropertiesUnit(node1, node2);
00856 return node;
00857 }
00858 Node new70()
00859 {
00860 TRParen node3 = (TRParen) pop();
00861 PExp node2 = (PExp) pop();
00862 TLParen node1 = (TLParen) pop();
00863 AParenPrimaryExp node = new AParenPrimaryExp(node1, node2, node3);
00864 return node;
00865 }
00866 Node new71()
00867 {
00868 TAnd node1 = (TAnd) pop();
00869 AAndBinOp node = new AAndBinOp(node1);
00870 return node;
00871 }
00872 Node new72()
00873 {
00874 TOr node1 = (TOr) pop();
00875 AOrBinOp node = new AOrBinOp(node1);
00876 return node;
00877 }
00878 Node new73()
00879 {
00880 TImply node1 = (TImply) pop();
00881 AImplyBinOp node = new AImplyBinOp(node1);
00882 return node;
00883 }
00884 Node new8()
00885 {
00886 PFormat node1 = (PFormat) pop();
00887 AFormatUnit node = new AFormatUnit(node1);
00888 return node;
00889 }
00890 Node new9()
00891 {
00892 TDoubleQuote node3 = (TDoubleQuote) pop();
00893 XPFormatWord node2 = null;
00894 TDoubleQuote node1 = (TDoubleQuote) pop();
00895 AFormat node = new AFormat(node1, node2, node3);
00896 return node;
00897 }
00898 public Start parse() throws ParserException, LexerException, IOException
00899 {
00900 push(0, null, false);
00901
00902 List ign = null;
00903 while(true)
00904 {
00905 while(index(lexer.peek()) == -1)
00906 {
00907 if(ign == null)
00908 {
00909 ign = new TypedLinkedList(NodeCast.instance);
00910 }
00911
00912 ign.add(lexer.next());
00913 }
00914
00915 if(ign != null)
00916 {
00917 ignoredTokens.setIn(lexer.peek(), ign);
00918 ign = null;
00919 }
00920
00921 last_pos = lexer.peek().getPos();
00922 last_line = lexer.peek().getLine();
00923 last_token = lexer.peek();
00924
00925 int index = index(lexer.peek());
00926 action[0] = actionTable[state()][0][1];
00927 action[1] = actionTable[state()][0][2];
00928
00929 int low = 1;
00930 int high = actionTable[state()].length - 1;
00931
00932 while(low <= high)
00933 {
00934 int middle = (low + high) / 2;
00935
00936 if(index < actionTable[state()][middle][0])
00937 {
00938 high = middle - 1;
00939 }
00940 else if(index > actionTable[state()][middle][0])
00941 {
00942 low = middle + 1;
00943 }
00944 else
00945 {
00946 action[0] = actionTable[state()][middle][1];
00947 action[1] = actionTable[state()][middle][2];
00948 break;
00949 }
00950 }
00951
00952 switch(action[0])
00953 {
00954 case SHIFT:
00955 push(action[1], lexer.next(), true);
00956 last_shift = action[1];
00957 break;
00958 case REDUCE:
00959 switch(action[1])
00960 {
00961 case 0: { Node node = new0(); push(goTo(0), node, true); } break;
00962 case 1: { Node node = new1(); push(goTo(0), node, true); } break;
00963 case 2: { Node node = new2(); push(goTo(26), node, false); } break;
00964 case 3: { Node node = new3(); push(goTo(26), node, false); } break;
00965 case 4: { Node node = new4(); push(goTo(0), node, true); } break;
00966 case 5: { Node node = new5(); push(goTo(27), node, false); } break;
00967 case 6: { Node node = new6(); push(goTo(27), node, false); } break;
00968 case 7: { Node node = new7(); push(goTo(0), node, true); } break;
00969 case 8: { Node node = new8(); push(goTo(0), node, true); } break;
00970 case 9: { Node node = new9(); push(goTo(1), node, true); } break;
00971 case 10: { Node node = new10(); push(goTo(1), node, true); } break;
00972 case 11: { Node node = new11(); push(goTo(28), node, false); } break;
00973 case 12: { Node node = new12(); push(goTo(28), node, false); } break;
00974 case 13: { Node node = new13(); push(goTo(2), node, true); } break;
00975 case 14: { Node node = new14(); push(goTo(2), node, true); } break;
00976 case 15: { Node node = new15(); push(goTo(2), node, true); } break;
00977 case 16: { Node node = new16(); push(goTo(2), node, true); } break;
00978 case 17: { Node node = new17(); push(goTo(2), node, true); } break;
00979 case 18: { Node node = new18(); push(goTo(3), node, true); } break;
00980 case 19: { Node node = new19(); push(goTo(3), node, true); } break;
00981 case 20: { Node node = new20(); push(goTo(3), node, true); } break;
00982 case 21: { Node node = new21(); push(goTo(4), node, true); } break;
00983 case 22: { Node node = new22(); push(goTo(4), node, true); } break;
00984 case 23: { Node node = new23(); push(goTo(5), node, true); } break;
00985 case 24: { Node node = new24(); push(goTo(5), node, true); } break;
00986 case 25: { Node node = new25(); push(goTo(6), node, true); } break;
00987 case 26: { Node node = new26(); push(goTo(6), node, true); } break;
00988 case 27: { Node node = new27(); push(goTo(7), node, true); } break;
00989 case 28: { Node node = new28(); push(goTo(7), node, true); } break;
00990 case 29: { Node node = new29(); push(goTo(8), node, true); } break;
00991 case 30: { Node node = new30(); push(goTo(8), node, true); } break;
00992 case 31: { Node node = new31(); push(goTo(9), node, true); } break;
00993 case 32: { Node node = new32(); push(goTo(9), node, true); } break;
00994 case 33: { Node node = new33(); push(goTo(10), node, true); } break;
00995 case 34: { Node node = new34(); push(goTo(29), node, false); } break;
00996 case 35: { Node node = new35(); push(goTo(29), node, false); } break;
00997 case 36: { Node node = new36(); push(goTo(10), node, true); } break;
00998 case 37: { Node node = new37(); push(goTo(10), node, true); } break;
00999 case 38: { Node node = new38(); push(goTo(30), node, false); } break;
01000 case 39: { Node node = new39(); push(goTo(30), node, false); } break;
01001 case 40: { Node node = new40(); push(goTo(10), node, true); } break;
01002 case 41: { Node node = new41(); push(goTo(11), node, true); } break;
01003 case 42: { Node node = new42(); push(goTo(12), node, true); } break;
01004 case 43: { Node node = new43(); push(goTo(12), node, true); } break;
01005 case 44: { Node node = new44(); push(goTo(13), node, true); } break;
01006 case 45: { Node node = new45(); push(goTo(13), node, true); } break;
01007 case 46: { Node node = new46(); push(goTo(14), node, true); } break;
01008 case 47: { Node node = new47(); push(goTo(14), node, true); } break;
01009 case 48: { Node node = new48(); push(goTo(15), node, true); } break;
01010 case 49: { Node node = new49(); push(goTo(15), node, true); } break;
01011 case 50: { Node node = new50(); push(goTo(16), node, true); } break;
01012 case 51: { Node node = new51(); push(goTo(16), node, true); } break;
01013 case 52: { Node node = new52(); push(goTo(17), node, true); } break;
01014 case 53: { Node node = new53(); push(goTo(17), node, true); } break;
01015 case 54: { Node node = new54(); push(goTo(17), node, true); } break;
01016 case 55: { Node node = new55(); push(goTo(17), node, true); } break;
01017 case 56: { Node node = new56(); push(goTo(17), node, true); } break;
01018 case 57: { Node node = new57(); push(goTo(18), node, true); } break;
01019 case 58: { Node node = new58(); push(goTo(19), node, true); } break;
01020 case 59: { Node node = new59(); push(goTo(19), node, true); } break;
01021 case 60: { Node node = new60(); push(goTo(20), node, true); } break;
01022 case 61: { Node node = new61(); push(goTo(20), node, true); } break;
01023 case 62: { Node node = new62(); push(goTo(21), node, true); } break;
01024 case 63: { Node node = new63(); push(goTo(21), node, true); } break;
01025 case 64: { Node node = new64(); push(goTo(22), node, true); } break;
01026 case 65: { Node node = new65(); push(goTo(22), node, true); } break;
01027 case 66: { Node node = new66(); push(goTo(23), node, true); } break;
01028 case 67: { Node node = new67(); push(goTo(23), node, true); } break;
01029 case 68: { Node node = new68(); push(goTo(24), node, true); } break;
01030 case 69: { Node node = new69(); push(goTo(24), node, true); } break;
01031 case 70: { Node node = new70(); push(goTo(24), node, true); } break;
01032 case 71: { Node node = new71(); push(goTo(25), node, true); } break;
01033 case 72: { Node node = new72(); push(goTo(25), node, true); } break;
01034 case 73: { Node node = new73(); push(goTo(25), node, true); } break;
01035 }
01036 break;
01037 case ACCEPT:
01038 {
01039 EOF node2 = (EOF) lexer.next();
01040 PUnit node1 = (PUnit) pop();
01041 Start node = new Start(node1, node2);
01042 return node;
01043 }
01044 case ERROR:
01045 throw new ParserException(last_token,
01046 "[" + last_line + "," + last_pos + "] " +
01047 errorMessages[errors[action[1]]]);
01048 }
01049 }
01050 }
01051 private Node pop()
01052 {
01053 return (Node) ((State) stack.previous()).node;
01054 }
01055 private void push(int state, Node node, boolean filter) throws ParserException, LexerException, IOException
01056 {
01057 this.node = node;
01058
01059 if(filter)
01060 {
01061 filter();
01062 }
01063
01064 if(!stack.hasNext())
01065 {
01066 stack.add(new State(state, this.node));
01067 return;
01068 }
01069
01070 State s = (State) stack.next();
01071 s.state = state;
01072 s.node = this.node;
01073 }
01074 private int state()
01075 {
01076 State s = (State) stack.previous();
01077 stack.next();
01078 return s.state;
01079 }
01080 }