0001: // $ANTLR 2.7.7 (2006-01-29): "buildnfa.g" -> "TreeToNFAConverter.java"$
0002:
0003: /*
0004: [The "BSD licence"]
0005: Copyright (c) 2005-2006 Terence Parr
0006: All rights reserved.
0007:
0008: Redistribution and use in source and binary forms, with or without
0009: modification, are permitted provided that the following conditions
0010: are met:
0011: 1. Redistributions of source code must retain the above copyright
0012: notice, this list of conditions and the following disclaimer.
0013: 2. Redistributions in binary form must reproduce the above copyright
0014: notice, this list of conditions and the following disclaimer in the
0015: documentation and/or other materials provided with the distribution.
0016: 3. The name of the author may not be used to endorse or promote products
0017: derived from this software without specific prior written permission.
0018:
0019: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0020: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0021: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0022: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0023: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0024: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0025: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0026: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0027: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0028: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0029: */
0030: package org.antlr.tool;
0031:
0032: import java.util.*;
0033: import org.antlr.analysis.*;
0034: import org.antlr.misc.*;
0035:
0036: import antlr.TreeParser;
0037: import antlr.Token;
0038: import antlr.collections.AST;
0039: import antlr.RecognitionException;
0040: import antlr.ANTLRException;
0041: import antlr.NoViableAltException;
0042: import antlr.MismatchedTokenException;
0043: import antlr.SemanticException;
0044: import antlr.collections.impl.BitSet;
0045: import antlr.ASTPair;
0046: import antlr.collections.impl.ASTArray;
0047:
0048: /** Build an NFA from a tree representing an ANTLR grammar. */
0049: public class TreeToNFAConverter extends antlr.TreeParser implements
0050: TreeToNFAConverterTokenTypes {
0051:
0052: /** Factory used to create nodes and submachines */
0053: protected NFAFactory factory = null;
0054:
0055: /** Which NFA object are we filling in? */
0056: protected NFA nfa = null;
0057:
0058: /** Which grammar are we converting an NFA for? */
0059: protected Grammar grammar = null;
0060:
0061: protected String currentRuleName = null;
0062:
0063: protected int outerAltNum = 0;
0064: protected int blockLevel = 0;
0065:
0066: public TreeToNFAConverter(Grammar g, NFA nfa, NFAFactory factory) {
0067: this ();
0068: this .grammar = g;
0069: this .nfa = nfa;
0070: this .factory = factory;
0071: }
0072:
0073: protected void init() {
0074: // define all the rule begin/end NFAStates to solve forward reference issues
0075: Collection rules = grammar.getRules();
0076: for (Iterator itr = rules.iterator(); itr.hasNext();) {
0077: Rule r = (Rule) itr.next();
0078: String ruleName = r.name;
0079: NFAState ruleBeginState = factory.newState();
0080: ruleBeginState
0081: .setDescription("rule " + ruleName + " start");
0082: ruleBeginState.setEnclosingRuleName(ruleName);
0083: grammar.setRuleStartState(ruleName, ruleBeginState);
0084: NFAState ruleEndState = factory.newState();
0085: ruleEndState.setDescription("rule " + ruleName + " end");
0086: ruleEndState.setAcceptState(true);
0087: ruleEndState.setEnclosingRuleName(ruleName);
0088: grammar.setRuleStopState(ruleName, ruleEndState);
0089: }
0090: }
0091:
0092: protected void addFollowTransition(String ruleName,
0093: NFAState following) {
0094: //System.out.println("adding follow link to rule "+ruleName);
0095: // find last link in FOLLOW chain emanating from rule
0096: NFAState end = grammar.getRuleStopState(ruleName);
0097: while (end.transition(1) != null) {
0098: end = (NFAState) end.transition(1).target;
0099: }
0100: if (end.transition(0) != null) {
0101: // already points to a following node
0102: // gotta add another node to keep edges to a max of 2
0103: NFAState n = factory.newState();
0104: Transition e = new Transition(Label.EPSILON, n);
0105: end.addTransition(e);
0106: end = n;
0107: }
0108: Transition followEdge = new Transition(Label.EPSILON, following);
0109: end.addTransition(followEdge);
0110: }
0111:
0112: protected void finish() {
0113: List rules = new LinkedList();
0114: rules.addAll(grammar.getRules());
0115: int numEntryPoints = factory.build_EOFStates(rules);
0116: if (numEntryPoints == 0) {
0117: ErrorManager.grammarWarning(
0118: ErrorManager.MSG_NO_GRAMMAR_START_RULE, grammar,
0119: null, grammar.name);
0120: }
0121: }
0122:
0123: public void reportError(RecognitionException ex) {
0124: Token token = null;
0125: if (ex instanceof MismatchedTokenException) {
0126: token = ((MismatchedTokenException) ex).token;
0127: } else if (ex instanceof NoViableAltException) {
0128: token = ((NoViableAltException) ex).token;
0129: }
0130: ErrorManager.syntaxError(ErrorManager.MSG_SYNTAX_ERROR,
0131: grammar, token, "buildnfa: " + ex.toString(), ex);
0132: }
0133:
0134: public TreeToNFAConverter() {
0135: tokenNames = _tokenNames;
0136: }
0137:
0138: public final void grammar(AST _t) throws RecognitionException {
0139:
0140: GrammarAST grammar_AST_in = (_t == ASTNULL) ? null
0141: : (GrammarAST) _t;
0142:
0143: try { // for error handling
0144: init();
0145: {
0146: if (_t == null)
0147: _t = ASTNULL;
0148: switch (_t.getType()) {
0149: case LEXER_GRAMMAR: {
0150: AST __t3 = _t;
0151: GrammarAST tmp1_AST_in = (GrammarAST) _t;
0152: match(_t, LEXER_GRAMMAR);
0153: _t = _t.getFirstChild();
0154: grammarSpec(_t);
0155: _t = _retTree;
0156: _t = __t3;
0157: _t = _t.getNextSibling();
0158: break;
0159: }
0160: case PARSER_GRAMMAR: {
0161: AST __t4 = _t;
0162: GrammarAST tmp2_AST_in = (GrammarAST) _t;
0163: match(_t, PARSER_GRAMMAR);
0164: _t = _t.getFirstChild();
0165: grammarSpec(_t);
0166: _t = _retTree;
0167: _t = __t4;
0168: _t = _t.getNextSibling();
0169: break;
0170: }
0171: case TREE_GRAMMAR: {
0172: AST __t5 = _t;
0173: GrammarAST tmp3_AST_in = (GrammarAST) _t;
0174: match(_t, TREE_GRAMMAR);
0175: _t = _t.getFirstChild();
0176: grammarSpec(_t);
0177: _t = _retTree;
0178: _t = __t5;
0179: _t = _t.getNextSibling();
0180: break;
0181: }
0182: case COMBINED_GRAMMAR: {
0183: AST __t6 = _t;
0184: GrammarAST tmp4_AST_in = (GrammarAST) _t;
0185: match(_t, COMBINED_GRAMMAR);
0186: _t = _t.getFirstChild();
0187: grammarSpec(_t);
0188: _t = _retTree;
0189: _t = __t6;
0190: _t = _t.getNextSibling();
0191: break;
0192: }
0193: default: {
0194: throw new NoViableAltException(_t);
0195: }
0196: }
0197: }
0198: finish();
0199: } catch (RecognitionException ex) {
0200: reportError(ex);
0201: if (_t != null) {
0202: _t = _t.getNextSibling();
0203: }
0204: }
0205: _retTree = _t;
0206: }
0207:
0208: public final void grammarSpec(AST _t) throws RecognitionException {
0209:
0210: GrammarAST grammarSpec_AST_in = (_t == ASTNULL) ? null
0211: : (GrammarAST) _t;
0212: GrammarAST cmt = null;
0213:
0214: try { // for error handling
0215: GrammarAST tmp5_AST_in = (GrammarAST) _t;
0216: match(_t, ID);
0217: _t = _t.getNextSibling();
0218: {
0219: if (_t == null)
0220: _t = ASTNULL;
0221: switch (_t.getType()) {
0222: case DOC_COMMENT: {
0223: cmt = (GrammarAST) _t;
0224: match(_t, DOC_COMMENT);
0225: _t = _t.getNextSibling();
0226: break;
0227: }
0228: case OPTIONS:
0229: case TOKENS:
0230: case RULE:
0231: case SCOPE:
0232: case AMPERSAND: {
0233: break;
0234: }
0235: default: {
0236: throw new NoViableAltException(_t);
0237: }
0238: }
0239: }
0240: {
0241: if (_t == null)
0242: _t = ASTNULL;
0243: switch (_t.getType()) {
0244: case OPTIONS: {
0245: AST __t12 = _t;
0246: GrammarAST tmp6_AST_in = (GrammarAST) _t;
0247: match(_t, OPTIONS);
0248: _t = _t.getFirstChild();
0249: GrammarAST tmp7_AST_in = (GrammarAST) _t;
0250: if (_t == null)
0251: throw new MismatchedTokenException();
0252: _t = _t.getNextSibling();
0253: _t = __t12;
0254: _t = _t.getNextSibling();
0255: break;
0256: }
0257: case TOKENS:
0258: case RULE:
0259: case SCOPE:
0260: case AMPERSAND: {
0261: break;
0262: }
0263: default: {
0264: throw new NoViableAltException(_t);
0265: }
0266: }
0267: }
0268: {
0269: if (_t == null)
0270: _t = ASTNULL;
0271: switch (_t.getType()) {
0272: case TOKENS: {
0273: AST __t14 = _t;
0274: GrammarAST tmp8_AST_in = (GrammarAST) _t;
0275: match(_t, TOKENS);
0276: _t = _t.getFirstChild();
0277: GrammarAST tmp9_AST_in = (GrammarAST) _t;
0278: if (_t == null)
0279: throw new MismatchedTokenException();
0280: _t = _t.getNextSibling();
0281: _t = __t14;
0282: _t = _t.getNextSibling();
0283: break;
0284: }
0285: case RULE:
0286: case SCOPE:
0287: case AMPERSAND: {
0288: break;
0289: }
0290: default: {
0291: throw new NoViableAltException(_t);
0292: }
0293: }
0294: }
0295: {
0296: _loop16: do {
0297: if (_t == null)
0298: _t = ASTNULL;
0299: if ((_t.getType() == SCOPE)) {
0300: attrScope(_t);
0301: _t = _retTree;
0302: } else {
0303: break _loop16;
0304: }
0305:
0306: } while (true);
0307: }
0308: {
0309: _loop18: do {
0310: if (_t == null)
0311: _t = ASTNULL;
0312: if ((_t.getType() == AMPERSAND)) {
0313: GrammarAST tmp10_AST_in = (GrammarAST) _t;
0314: match(_t, AMPERSAND);
0315: _t = _t.getNextSibling();
0316: } else {
0317: break _loop18;
0318: }
0319:
0320: } while (true);
0321: }
0322: rules(_t);
0323: _t = _retTree;
0324: } catch (RecognitionException ex) {
0325: reportError(ex);
0326: if (_t != null) {
0327: _t = _t.getNextSibling();
0328: }
0329: }
0330: _retTree = _t;
0331: }
0332:
0333: public final void attrScope(AST _t) throws RecognitionException {
0334:
0335: GrammarAST attrScope_AST_in = (_t == ASTNULL) ? null
0336: : (GrammarAST) _t;
0337:
0338: try { // for error handling
0339: AST __t8 = _t;
0340: GrammarAST tmp11_AST_in = (GrammarAST) _t;
0341: match(_t, SCOPE);
0342: _t = _t.getFirstChild();
0343: GrammarAST tmp12_AST_in = (GrammarAST) _t;
0344: match(_t, ID);
0345: _t = _t.getNextSibling();
0346: GrammarAST tmp13_AST_in = (GrammarAST) _t;
0347: match(_t, ACTION);
0348: _t = _t.getNextSibling();
0349: _t = __t8;
0350: _t = _t.getNextSibling();
0351: } catch (RecognitionException ex) {
0352: reportError(ex);
0353: if (_t != null) {
0354: _t = _t.getNextSibling();
0355: }
0356: }
0357: _retTree = _t;
0358: }
0359:
0360: public final void rules(AST _t) throws RecognitionException {
0361:
0362: GrammarAST rules_AST_in = (_t == ASTNULL) ? null
0363: : (GrammarAST) _t;
0364:
0365: try { // for error handling
0366: {
0367: int _cnt21 = 0;
0368: _loop21: do {
0369: if (_t == null)
0370: _t = ASTNULL;
0371: if ((_t.getType() == RULE)) {
0372: rule(_t);
0373: _t = _retTree;
0374: } else {
0375: if (_cnt21 >= 1) {
0376: break _loop21;
0377: } else {
0378: throw new NoViableAltException(_t);
0379: }
0380: }
0381:
0382: _cnt21++;
0383: } while (true);
0384: }
0385: } catch (RecognitionException ex) {
0386: reportError(ex);
0387: if (_t != null) {
0388: _t = _t.getNextSibling();
0389: }
0390: }
0391: _retTree = _t;
0392: }
0393:
0394: public final void rule(AST _t) throws RecognitionException {
0395:
0396: GrammarAST rule_AST_in = (_t == ASTNULL) ? null
0397: : (GrammarAST) _t;
0398: GrammarAST id = null;
0399:
0400: StateCluster g = null;
0401: StateCluster b = null;
0402: String r = null;
0403:
0404: try { // for error handling
0405: AST __t23 = _t;
0406: GrammarAST tmp14_AST_in = (GrammarAST) _t;
0407: match(_t, RULE);
0408: _t = _t.getFirstChild();
0409: id = (GrammarAST) _t;
0410: match(_t, ID);
0411: _t = _t.getNextSibling();
0412: r = id.getText();
0413: currentRuleName = r;
0414: factory.currentRuleName = r;
0415: {
0416: if (_t == null)
0417: _t = ASTNULL;
0418: switch (_t.getType()) {
0419: case FRAGMENT:
0420: case LITERAL_protected:
0421: case LITERAL_public:
0422: case LITERAL_private: {
0423: modifier(_t);
0424: _t = _retTree;
0425: break;
0426: }
0427: case ARG: {
0428: break;
0429: }
0430: default: {
0431: throw new NoViableAltException(_t);
0432: }
0433: }
0434: }
0435: {
0436: GrammarAST tmp15_AST_in = (GrammarAST) _t;
0437: match(_t, ARG);
0438: _t = _t.getNextSibling();
0439: {
0440: if (_t == null)
0441: _t = ASTNULL;
0442: switch (_t.getType()) {
0443: case ARG_ACTION: {
0444: GrammarAST tmp16_AST_in = (GrammarAST) _t;
0445: match(_t, ARG_ACTION);
0446: _t = _t.getNextSibling();
0447: break;
0448: }
0449: case RET: {
0450: break;
0451: }
0452: default: {
0453: throw new NoViableAltException(_t);
0454: }
0455: }
0456: }
0457: }
0458: {
0459: GrammarAST tmp17_AST_in = (GrammarAST) _t;
0460: match(_t, RET);
0461: _t = _t.getNextSibling();
0462: {
0463: if (_t == null)
0464: _t = ASTNULL;
0465: switch (_t.getType()) {
0466: case ARG_ACTION: {
0467: GrammarAST tmp18_AST_in = (GrammarAST) _t;
0468: match(_t, ARG_ACTION);
0469: _t = _t.getNextSibling();
0470: break;
0471: }
0472: case OPTIONS:
0473: case BLOCK:
0474: case SCOPE:
0475: case AMPERSAND: {
0476: break;
0477: }
0478: default: {
0479: throw new NoViableAltException(_t);
0480: }
0481: }
0482: }
0483: }
0484: {
0485: if (_t == null)
0486: _t = ASTNULL;
0487: switch (_t.getType()) {
0488: case OPTIONS: {
0489: GrammarAST tmp19_AST_in = (GrammarAST) _t;
0490: match(_t, OPTIONS);
0491: _t = _t.getNextSibling();
0492: break;
0493: }
0494: case BLOCK:
0495: case SCOPE:
0496: case AMPERSAND: {
0497: break;
0498: }
0499: default: {
0500: throw new NoViableAltException(_t);
0501: }
0502: }
0503: }
0504: {
0505: if (_t == null)
0506: _t = ASTNULL;
0507: switch (_t.getType()) {
0508: case SCOPE: {
0509: ruleScopeSpec(_t);
0510: _t = _retTree;
0511: break;
0512: }
0513: case BLOCK:
0514: case AMPERSAND: {
0515: break;
0516: }
0517: default: {
0518: throw new NoViableAltException(_t);
0519: }
0520: }
0521: }
0522: {
0523: _loop32: do {
0524: if (_t == null)
0525: _t = ASTNULL;
0526: if ((_t.getType() == AMPERSAND)) {
0527: GrammarAST tmp20_AST_in = (GrammarAST) _t;
0528: match(_t, AMPERSAND);
0529: _t = _t.getNextSibling();
0530: } else {
0531: break _loop32;
0532: }
0533:
0534: } while (true);
0535: }
0536: GrammarAST blk = (GrammarAST) _t;
0537: b = block(_t);
0538: _t = _retTree;
0539: {
0540: if (_t == null)
0541: _t = ASTNULL;
0542: switch (_t.getType()) {
0543: case LITERAL_catch:
0544: case LITERAL_finally: {
0545: exceptionGroup(_t);
0546: _t = _retTree;
0547: break;
0548: }
0549: case EOR: {
0550: break;
0551: }
0552: default: {
0553: throw new NoViableAltException(_t);
0554: }
0555: }
0556: }
0557: GrammarAST tmp21_AST_in = (GrammarAST) _t;
0558: match(_t, EOR);
0559: _t = _t.getNextSibling();
0560:
0561: if (blk.setValue != null) {
0562: // if block comes back as a set not BLOCK, make it
0563: // a single ALT block
0564: b = factory.build_AlternativeBlockFromSet(b);
0565: }
0566: if (Character.isLowerCase(r.charAt(0))
0567: || grammar.type == Grammar.LEXER) {
0568: // attach start node to block for this rule
0569: NFAState start = grammar.getRuleStartState(r);
0570: start.setAssociatedASTNode(id);
0571: start.addTransition(new Transition(Label.EPSILON,
0572: b.left));
0573:
0574: // track decision if > 1 alts
0575: if (grammar.getNumberOfAltsForDecisionNFA(b.left) > 1) {
0576: b.left.setDescription(grammar.grammarTreeToString(
0577: rule_AST_in, false));
0578: b.left.setDecisionASTNode(blk);
0579: int d = grammar.assignDecisionNumber(b.left);
0580: grammar.setDecisionNFA(d, b.left);
0581: grammar.setDecisionBlockAST(d, blk);
0582: }
0583:
0584: // hook to end of rule node
0585: NFAState end = grammar.getRuleStopState(r);
0586: b.right
0587: .addTransition(new Transition(Label.EPSILON,
0588: end));
0589: }
0590:
0591: _t = __t23;
0592: _t = _t.getNextSibling();
0593: } catch (RecognitionException ex) {
0594: reportError(ex);
0595: if (_t != null) {
0596: _t = _t.getNextSibling();
0597: }
0598: }
0599: _retTree = _t;
0600: }
0601:
0602: public final void modifier(AST _t) throws RecognitionException {
0603:
0604: GrammarAST modifier_AST_in = (_t == ASTNULL) ? null
0605: : (GrammarAST) _t;
0606:
0607: try { // for error handling
0608: if (_t == null)
0609: _t = ASTNULL;
0610: switch (_t.getType()) {
0611: case LITERAL_protected: {
0612: GrammarAST tmp22_AST_in = (GrammarAST) _t;
0613: match(_t, LITERAL_protected);
0614: _t = _t.getNextSibling();
0615: break;
0616: }
0617: case LITERAL_public: {
0618: GrammarAST tmp23_AST_in = (GrammarAST) _t;
0619: match(_t, LITERAL_public);
0620: _t = _t.getNextSibling();
0621: break;
0622: }
0623: case LITERAL_private: {
0624: GrammarAST tmp24_AST_in = (GrammarAST) _t;
0625: match(_t, LITERAL_private);
0626: _t = _t.getNextSibling();
0627: break;
0628: }
0629: case FRAGMENT: {
0630: GrammarAST tmp25_AST_in = (GrammarAST) _t;
0631: match(_t, FRAGMENT);
0632: _t = _t.getNextSibling();
0633: break;
0634: }
0635: default: {
0636: throw new NoViableAltException(_t);
0637: }
0638: }
0639: } catch (RecognitionException ex) {
0640: reportError(ex);
0641: if (_t != null) {
0642: _t = _t.getNextSibling();
0643: }
0644: }
0645: _retTree = _t;
0646: }
0647:
0648: public final void ruleScopeSpec(AST _t) throws RecognitionException {
0649:
0650: GrammarAST ruleScopeSpec_AST_in = (_t == ASTNULL) ? null
0651: : (GrammarAST) _t;
0652:
0653: try { // for error handling
0654: AST __t36 = _t;
0655: GrammarAST tmp26_AST_in = (GrammarAST) _t;
0656: match(_t, SCOPE);
0657: _t = _t.getFirstChild();
0658: {
0659: if (_t == null)
0660: _t = ASTNULL;
0661: switch (_t.getType()) {
0662: case ACTION: {
0663: GrammarAST tmp27_AST_in = (GrammarAST) _t;
0664: match(_t, ACTION);
0665: _t = _t.getNextSibling();
0666: break;
0667: }
0668: case 3:
0669: case ID: {
0670: break;
0671: }
0672: default: {
0673: throw new NoViableAltException(_t);
0674: }
0675: }
0676: }
0677: {
0678: _loop39: do {
0679: if (_t == null)
0680: _t = ASTNULL;
0681: if ((_t.getType() == ID)) {
0682: GrammarAST tmp28_AST_in = (GrammarAST) _t;
0683: match(_t, ID);
0684: _t = _t.getNextSibling();
0685: } else {
0686: break _loop39;
0687: }
0688:
0689: } while (true);
0690: }
0691: _t = __t36;
0692: _t = _t.getNextSibling();
0693: } catch (RecognitionException ex) {
0694: reportError(ex);
0695: if (_t != null) {
0696: _t = _t.getNextSibling();
0697: }
0698: }
0699: _retTree = _t;
0700: }
0701:
0702: public final StateCluster block(AST _t) throws RecognitionException {
0703: StateCluster g = null;
0704:
0705: GrammarAST block_AST_in = (_t == ASTNULL) ? null
0706: : (GrammarAST) _t;
0707:
0708: StateCluster a = null;
0709: List alts = new LinkedList();
0710: this .blockLevel++;
0711: if (this .blockLevel == 1) {
0712: this .outerAltNum = 1;
0713: }
0714:
0715: try { // for error handling
0716: if (_t == null)
0717: _t = ASTNULL;
0718: if (((_t.getType() == BLOCK))
0719: && (grammar.isValidSet(this , block_AST_in) && !currentRuleName
0720: .equals(Grammar.ARTIFICIAL_TOKENS_RULENAME))) {
0721: g = set(_t);
0722: _t = _retTree;
0723: this .blockLevel--;
0724: } else if ((_t.getType() == BLOCK)) {
0725: AST __t41 = _t;
0726: GrammarAST tmp29_AST_in = (GrammarAST) _t;
0727: match(_t, BLOCK);
0728: _t = _t.getFirstChild();
0729: {
0730: if (_t == null)
0731: _t = ASTNULL;
0732: switch (_t.getType()) {
0733: case OPTIONS: {
0734: GrammarAST tmp30_AST_in = (GrammarAST) _t;
0735: match(_t, OPTIONS);
0736: _t = _t.getNextSibling();
0737: break;
0738: }
0739: case ALT: {
0740: break;
0741: }
0742: default: {
0743: throw new NoViableAltException(_t);
0744: }
0745: }
0746: }
0747: {
0748: int _cnt44 = 0;
0749: _loop44: do {
0750: if (_t == null)
0751: _t = ASTNULL;
0752: if ((_t.getType() == ALT)) {
0753: a = alternative(_t);
0754: _t = _retTree;
0755: rewrite(_t);
0756: _t = _retTree;
0757:
0758: alts.add(a);
0759: if (this .blockLevel == 1) {
0760: this .outerAltNum++;
0761: }
0762:
0763: } else {
0764: if (_cnt44 >= 1) {
0765: break _loop44;
0766: } else {
0767: throw new NoViableAltException(_t);
0768: }
0769: }
0770:
0771: _cnt44++;
0772: } while (true);
0773: }
0774: GrammarAST tmp31_AST_in = (GrammarAST) _t;
0775: match(_t, EOB);
0776: _t = _t.getNextSibling();
0777: _t = __t41;
0778: _t = _t.getNextSibling();
0779: g = factory.build_AlternativeBlock(alts);
0780: this .blockLevel--;
0781: } else {
0782: throw new NoViableAltException(_t);
0783: }
0784:
0785: } catch (RecognitionException ex) {
0786: reportError(ex);
0787: if (_t != null) {
0788: _t = _t.getNextSibling();
0789: }
0790: }
0791: _retTree = _t;
0792: return g;
0793: }
0794:
0795: public final void exceptionGroup(AST _t)
0796: throws RecognitionException {
0797:
0798: GrammarAST exceptionGroup_AST_in = (_t == ASTNULL) ? null
0799: : (GrammarAST) _t;
0800:
0801: try { // for error handling
0802: if (_t == null)
0803: _t = ASTNULL;
0804: switch (_t.getType()) {
0805: case LITERAL_catch: {
0806: {
0807: int _cnt51 = 0;
0808: _loop51: do {
0809: if (_t == null)
0810: _t = ASTNULL;
0811: if ((_t.getType() == LITERAL_catch)) {
0812: exceptionHandler(_t);
0813: _t = _retTree;
0814: } else {
0815: if (_cnt51 >= 1) {
0816: break _loop51;
0817: } else {
0818: throw new NoViableAltException(_t);
0819: }
0820: }
0821:
0822: _cnt51++;
0823: } while (true);
0824: }
0825: {
0826: if (_t == null)
0827: _t = ASTNULL;
0828: switch (_t.getType()) {
0829: case LITERAL_finally: {
0830: finallyClause(_t);
0831: _t = _retTree;
0832: break;
0833: }
0834: case EOR: {
0835: break;
0836: }
0837: default: {
0838: throw new NoViableAltException(_t);
0839: }
0840: }
0841: }
0842: break;
0843: }
0844: case LITERAL_finally: {
0845: finallyClause(_t);
0846: _t = _retTree;
0847: break;
0848: }
0849: default: {
0850: throw new NoViableAltException(_t);
0851: }
0852: }
0853: } catch (RecognitionException ex) {
0854: reportError(ex);
0855: if (_t != null) {
0856: _t = _t.getNextSibling();
0857: }
0858: }
0859: _retTree = _t;
0860: }
0861:
0862: public final StateCluster set(AST _t) throws RecognitionException {
0863: StateCluster g = null;
0864:
0865: GrammarAST set_AST_in = (_t == ASTNULL) ? null
0866: : (GrammarAST) _t;
0867: GrammarAST b = null;
0868:
0869: IntSet elements = new IntervalSet();
0870: set_AST_in.setSetValue(elements); // track set for use by code gen
0871:
0872: try { // for error handling
0873: AST __t99 = _t;
0874: b = _t == ASTNULL ? null : (GrammarAST) _t;
0875: match(_t, BLOCK);
0876: _t = _t.getFirstChild();
0877: {
0878: int _cnt103 = 0;
0879: _loop103: do {
0880: if (_t == null)
0881: _t = ASTNULL;
0882: if ((_t.getType() == ALT)) {
0883: AST __t101 = _t;
0884: GrammarAST tmp32_AST_in = (GrammarAST) _t;
0885: match(_t, ALT);
0886: _t = _t.getFirstChild();
0887: {
0888: if (_t == null)
0889: _t = ASTNULL;
0890: switch (_t.getType()) {
0891: case BACKTRACK_SEMPRED: {
0892: GrammarAST tmp33_AST_in = (GrammarAST) _t;
0893: match(_t, BACKTRACK_SEMPRED);
0894: _t = _t.getNextSibling();
0895: break;
0896: }
0897: case BLOCK:
0898: case CHAR_RANGE:
0899: case STRING_LITERAL:
0900: case CHAR_LITERAL:
0901: case TOKEN_REF:
0902: case NOT: {
0903: break;
0904: }
0905: default: {
0906: throw new NoViableAltException(_t);
0907: }
0908: }
0909: }
0910: setElement(_t, elements);
0911: _t = _retTree;
0912: GrammarAST tmp34_AST_in = (GrammarAST) _t;
0913: match(_t, EOA);
0914: _t = _t.getNextSibling();
0915: _t = __t101;
0916: _t = _t.getNextSibling();
0917: } else {
0918: if (_cnt103 >= 1) {
0919: break _loop103;
0920: } else {
0921: throw new NoViableAltException(_t);
0922: }
0923: }
0924:
0925: _cnt103++;
0926: } while (true);
0927: }
0928: GrammarAST tmp35_AST_in = (GrammarAST) _t;
0929: match(_t, EOB);
0930: _t = _t.getNextSibling();
0931: _t = __t99;
0932: _t = _t.getNextSibling();
0933:
0934: g = factory.build_Set(elements);
0935: b.followingNFAState = g.right;
0936: b.setValue = elements; // track set value of this block
0937:
0938: } catch (RecognitionException ex) {
0939: reportError(ex);
0940: if (_t != null) {
0941: _t = _t.getNextSibling();
0942: }
0943: }
0944: _retTree = _t;
0945: return g;
0946: }
0947:
0948: public final StateCluster alternative(AST _t)
0949: throws RecognitionException {
0950: StateCluster g = null;
0951:
0952: GrammarAST alternative_AST_in = (_t == ASTNULL) ? null
0953: : (GrammarAST) _t;
0954:
0955: StateCluster e = null;
0956:
0957: try { // for error handling
0958: AST __t46 = _t;
0959: GrammarAST tmp36_AST_in = (GrammarAST) _t;
0960: match(_t, ALT);
0961: _t = _t.getFirstChild();
0962: {
0963: int _cnt48 = 0;
0964: _loop48: do {
0965: if (_t == null)
0966: _t = ASTNULL;
0967: if ((_tokenSet_0.member(_t.getType()))) {
0968: e = element(_t);
0969: _t = _retTree;
0970: g = factory.build_AB(g, e);
0971: } else {
0972: if (_cnt48 >= 1) {
0973: break _loop48;
0974: } else {
0975: throw new NoViableAltException(_t);
0976: }
0977: }
0978:
0979: _cnt48++;
0980: } while (true);
0981: }
0982: _t = __t46;
0983: _t = _t.getNextSibling();
0984:
0985: if (g == null) { // if alt was a list of actions or whatever
0986: g = factory.build_Epsilon();
0987: } else {
0988: factory.optimizeAlternative(g);
0989: }
0990:
0991: } catch (RecognitionException ex) {
0992: reportError(ex);
0993: if (_t != null) {
0994: _t = _t.getNextSibling();
0995: }
0996: }
0997: _retTree = _t;
0998: return g;
0999: }
1000:
1001: public final void rewrite(AST _t) throws RecognitionException {
1002:
1003: GrammarAST rewrite_AST_in = (_t == ASTNULL) ? null
1004: : (GrammarAST) _t;
1005:
1006: try { // for error handling
1007: {
1008: _loop62: do {
1009: if (_t == null)
1010: _t = ASTNULL;
1011: if ((_t.getType() == REWRITE)) {
1012:
1013: if (grammar.getOption("output") == null) {
1014: ErrorManager
1015: .grammarError(
1016: ErrorManager.MSG_REWRITE_OR_OP_WITH_NO_OUTPUT_OPTION,
1017: grammar,
1018: rewrite_AST_in.token,
1019: currentRuleName);
1020: }
1021:
1022: AST __t59 = _t;
1023: GrammarAST tmp37_AST_in = (GrammarAST) _t;
1024: match(_t, REWRITE);
1025: _t = _t.getFirstChild();
1026: {
1027: if (_t == null)
1028: _t = ASTNULL;
1029: switch (_t.getType()) {
1030: case SEMPRED: {
1031: GrammarAST tmp38_AST_in = (GrammarAST) _t;
1032: match(_t, SEMPRED);
1033: _t = _t.getNextSibling();
1034: break;
1035: }
1036: case ALT:
1037: case TEMPLATE:
1038: case ACTION: {
1039: break;
1040: }
1041: default: {
1042: throw new NoViableAltException(_t);
1043: }
1044: }
1045: }
1046: {
1047: if (_t == null)
1048: _t = ASTNULL;
1049: switch (_t.getType()) {
1050: case ALT: {
1051: GrammarAST tmp39_AST_in = (GrammarAST) _t;
1052: match(_t, ALT);
1053: _t = _t.getNextSibling();
1054: break;
1055: }
1056: case TEMPLATE: {
1057: GrammarAST tmp40_AST_in = (GrammarAST) _t;
1058: match(_t, TEMPLATE);
1059: _t = _t.getNextSibling();
1060: break;
1061: }
1062: case ACTION: {
1063: GrammarAST tmp41_AST_in = (GrammarAST) _t;
1064: match(_t, ACTION);
1065: _t = _t.getNextSibling();
1066: break;
1067: }
1068: default: {
1069: throw new NoViableAltException(_t);
1070: }
1071: }
1072: }
1073: _t = __t59;
1074: _t = _t.getNextSibling();
1075: } else {
1076: break _loop62;
1077: }
1078:
1079: } while (true);
1080: }
1081: } catch (RecognitionException ex) {
1082: reportError(ex);
1083: if (_t != null) {
1084: _t = _t.getNextSibling();
1085: }
1086: }
1087: _retTree = _t;
1088: }
1089:
1090: public final StateCluster element(AST _t)
1091: throws RecognitionException {
1092: StateCluster g = null;
1093:
1094: GrammarAST element_AST_in = (_t == ASTNULL) ? null
1095: : (GrammarAST) _t;
1096: GrammarAST a = null;
1097: GrammarAST b = null;
1098: GrammarAST c1 = null;
1099: GrammarAST c2 = null;
1100: GrammarAST pred = null;
1101: GrammarAST spred = null;
1102: GrammarAST bpred = null;
1103: GrammarAST gpred = null;
1104:
1105: try { // for error handling
1106: if (_t == null)
1107: _t = ASTNULL;
1108: switch (_t.getType()) {
1109: case ROOT: {
1110: AST __t64 = _t;
1111: GrammarAST tmp42_AST_in = (GrammarAST) _t;
1112: match(_t, ROOT);
1113: _t = _t.getFirstChild();
1114: g = element(_t);
1115: _t = _retTree;
1116: _t = __t64;
1117: _t = _t.getNextSibling();
1118: break;
1119: }
1120: case BANG: {
1121: AST __t65 = _t;
1122: GrammarAST tmp43_AST_in = (GrammarAST) _t;
1123: match(_t, BANG);
1124: _t = _t.getFirstChild();
1125: g = element(_t);
1126: _t = _retTree;
1127: _t = __t65;
1128: _t = _t.getNextSibling();
1129: break;
1130: }
1131: case ASSIGN: {
1132: AST __t66 = _t;
1133: GrammarAST tmp44_AST_in = (GrammarAST) _t;
1134: match(_t, ASSIGN);
1135: _t = _t.getFirstChild();
1136: GrammarAST tmp45_AST_in = (GrammarAST) _t;
1137: match(_t, ID);
1138: _t = _t.getNextSibling();
1139: g = element(_t);
1140: _t = _retTree;
1141: _t = __t66;
1142: _t = _t.getNextSibling();
1143: break;
1144: }
1145: case PLUS_ASSIGN: {
1146: AST __t67 = _t;
1147: GrammarAST tmp46_AST_in = (GrammarAST) _t;
1148: match(_t, PLUS_ASSIGN);
1149: _t = _t.getFirstChild();
1150: GrammarAST tmp47_AST_in = (GrammarAST) _t;
1151: match(_t, ID);
1152: _t = _t.getNextSibling();
1153: g = element(_t);
1154: _t = _retTree;
1155: _t = __t67;
1156: _t = _t.getNextSibling();
1157: break;
1158: }
1159: case RANGE: {
1160: AST __t68 = _t;
1161: GrammarAST tmp48_AST_in = (GrammarAST) _t;
1162: match(_t, RANGE);
1163: _t = _t.getFirstChild();
1164: a = _t == ASTNULL ? null : (GrammarAST) _t;
1165: atom(_t);
1166: _t = _retTree;
1167: b = _t == ASTNULL ? null : (GrammarAST) _t;
1168: atom(_t);
1169: _t = _retTree;
1170: _t = __t68;
1171: _t = _t.getNextSibling();
1172: g = factory.build_Range(grammar.getTokenType(a
1173: .getText()), grammar.getTokenType(b.getText()));
1174: break;
1175: }
1176: case CHAR_RANGE: {
1177: AST __t69 = _t;
1178: GrammarAST tmp49_AST_in = (GrammarAST) _t;
1179: match(_t, CHAR_RANGE);
1180: _t = _t.getFirstChild();
1181: c1 = (GrammarAST) _t;
1182: match(_t, CHAR_LITERAL);
1183: _t = _t.getNextSibling();
1184: c2 = (GrammarAST) _t;
1185: match(_t, CHAR_LITERAL);
1186: _t = _t.getNextSibling();
1187: _t = __t69;
1188: _t = _t.getNextSibling();
1189:
1190: if (grammar.type == Grammar.LEXER) {
1191: g = factory.build_CharRange(c1.getText(), c2
1192: .getText());
1193: }
1194:
1195: break;
1196: }
1197: case STRING_LITERAL:
1198: case CHAR_LITERAL:
1199: case TOKEN_REF:
1200: case RULE_REF:
1201: case NOT:
1202: case WILDCARD: {
1203: g = atom_or_notatom(_t);
1204: _t = _retTree;
1205: break;
1206: }
1207: case BLOCK:
1208: case OPTIONAL:
1209: case CLOSURE:
1210: case POSITIVE_CLOSURE: {
1211: g = ebnf(_t);
1212: _t = _retTree;
1213: break;
1214: }
1215: case TREE_BEGIN: {
1216: g = tree(_t);
1217: _t = _retTree;
1218: break;
1219: }
1220: case SYNPRED: {
1221: AST __t70 = _t;
1222: GrammarAST tmp50_AST_in = (GrammarAST) _t;
1223: match(_t, SYNPRED);
1224: _t = _t.getFirstChild();
1225: block(_t);
1226: _t = _retTree;
1227: _t = __t70;
1228: _t = _t.getNextSibling();
1229: break;
1230: }
1231: case ACTION: {
1232: GrammarAST tmp51_AST_in = (GrammarAST) _t;
1233: match(_t, ACTION);
1234: _t = _t.getNextSibling();
1235: break;
1236: }
1237: case SEMPRED: {
1238: pred = (GrammarAST) _t;
1239: match(_t, SEMPRED);
1240: _t = _t.getNextSibling();
1241: g = factory.build_SemanticPredicate(pred);
1242: break;
1243: }
1244: case SYN_SEMPRED: {
1245: spred = (GrammarAST) _t;
1246: match(_t, SYN_SEMPRED);
1247: _t = _t.getNextSibling();
1248: g = factory.build_SemanticPredicate(spred);
1249: break;
1250: }
1251: case BACKTRACK_SEMPRED: {
1252: bpred = (GrammarAST) _t;
1253: match(_t, BACKTRACK_SEMPRED);
1254: _t = _t.getNextSibling();
1255: g = factory.build_SemanticPredicate(bpred);
1256: break;
1257: }
1258: case GATED_SEMPRED: {
1259: gpred = (GrammarAST) _t;
1260: match(_t, GATED_SEMPRED);
1261: _t = _t.getNextSibling();
1262: g = factory.build_SemanticPredicate(gpred);
1263: break;
1264: }
1265: case EPSILON: {
1266: GrammarAST tmp52_AST_in = (GrammarAST) _t;
1267: match(_t, EPSILON);
1268: _t = _t.getNextSibling();
1269: g = factory.build_Epsilon();
1270: break;
1271: }
1272: default: {
1273: throw new NoViableAltException(_t);
1274: }
1275: }
1276: } catch (RecognitionException ex) {
1277: reportError(ex);
1278: if (_t != null) {
1279: _t = _t.getNextSibling();
1280: }
1281: }
1282: _retTree = _t;
1283: return g;
1284: }
1285:
1286: public final void exceptionHandler(AST _t)
1287: throws RecognitionException {
1288:
1289: GrammarAST exceptionHandler_AST_in = (_t == ASTNULL) ? null
1290: : (GrammarAST) _t;
1291:
1292: try { // for error handling
1293: AST __t54 = _t;
1294: GrammarAST tmp53_AST_in = (GrammarAST) _t;
1295: match(_t, LITERAL_catch);
1296: _t = _t.getFirstChild();
1297: GrammarAST tmp54_AST_in = (GrammarAST) _t;
1298: match(_t, ARG_ACTION);
1299: _t = _t.getNextSibling();
1300: GrammarAST tmp55_AST_in = (GrammarAST) _t;
1301: match(_t, ACTION);
1302: _t = _t.getNextSibling();
1303: _t = __t54;
1304: _t = _t.getNextSibling();
1305: } catch (RecognitionException ex) {
1306: reportError(ex);
1307: if (_t != null) {
1308: _t = _t.getNextSibling();
1309: }
1310: }
1311: _retTree = _t;
1312: }
1313:
1314: public final void finallyClause(AST _t) throws RecognitionException {
1315:
1316: GrammarAST finallyClause_AST_in = (_t == ASTNULL) ? null
1317: : (GrammarAST) _t;
1318:
1319: try { // for error handling
1320: AST __t56 = _t;
1321: GrammarAST tmp56_AST_in = (GrammarAST) _t;
1322: match(_t, LITERAL_finally);
1323: _t = _t.getFirstChild();
1324: GrammarAST tmp57_AST_in = (GrammarAST) _t;
1325: match(_t, ACTION);
1326: _t = _t.getNextSibling();
1327: _t = __t56;
1328: _t = _t.getNextSibling();
1329: } catch (RecognitionException ex) {
1330: reportError(ex);
1331: if (_t != null) {
1332: _t = _t.getNextSibling();
1333: }
1334: }
1335: _retTree = _t;
1336: }
1337:
1338: public final StateCluster atom(AST _t) throws RecognitionException {
1339: StateCluster g = null;
1340:
1341: GrammarAST atom_AST_in = (_t == ASTNULL) ? null
1342: : (GrammarAST) _t;
1343: GrammarAST r = null;
1344: GrammarAST rarg = null;
1345: GrammarAST as1 = null;
1346: GrammarAST t = null;
1347: GrammarAST targ = null;
1348: GrammarAST as2 = null;
1349: GrammarAST c = null;
1350: GrammarAST as3 = null;
1351: GrammarAST s = null;
1352: GrammarAST as4 = null;
1353: GrammarAST w = null;
1354: GrammarAST as5 = null;
1355:
1356: try { // for error handling
1357: if (_t == null)
1358: _t = ASTNULL;
1359: switch (_t.getType()) {
1360: case RULE_REF: {
1361: AST __t85 = _t;
1362: r = _t == ASTNULL ? null : (GrammarAST) _t;
1363: match(_t, RULE_REF);
1364: _t = _t.getFirstChild();
1365: {
1366: if (_t == null)
1367: _t = ASTNULL;
1368: switch (_t.getType()) {
1369: case ARG_ACTION: {
1370: rarg = (GrammarAST) _t;
1371: match(_t, ARG_ACTION);
1372: _t = _t.getNextSibling();
1373: break;
1374: }
1375: case 3:
1376: case BANG:
1377: case ROOT: {
1378: break;
1379: }
1380: default: {
1381: throw new NoViableAltException(_t);
1382: }
1383: }
1384: }
1385: {
1386: if (_t == null)
1387: _t = ASTNULL;
1388: switch (_t.getType()) {
1389: case BANG:
1390: case ROOT: {
1391: as1 = _t == ASTNULL ? null : (GrammarAST) _t;
1392: ast_suffix(_t);
1393: _t = _retTree;
1394: break;
1395: }
1396: case 3: {
1397: break;
1398: }
1399: default: {
1400: throw new NoViableAltException(_t);
1401: }
1402: }
1403: }
1404: _t = __t85;
1405: _t = _t.getNextSibling();
1406:
1407: NFAState start = grammar.getRuleStartState(r.getText());
1408: if (start != null) {
1409: int ruleIndex = grammar.getRuleIndex(r.getText());
1410: g = factory.build_RuleRef(ruleIndex, start);
1411: r.followingNFAState = g.right;
1412: if (g.left.transition(0) instanceof RuleClosureTransition
1413: && grammar.type != Grammar.LEXER) {
1414: addFollowTransition(r.getText(), g.right);
1415: }
1416: // else rule ref got inlined to a set
1417: }
1418:
1419: break;
1420: }
1421: case TOKEN_REF: {
1422: AST __t88 = _t;
1423: t = _t == ASTNULL ? null : (GrammarAST) _t;
1424: match(_t, TOKEN_REF);
1425: _t = _t.getFirstChild();
1426: {
1427: if (_t == null)
1428: _t = ASTNULL;
1429: switch (_t.getType()) {
1430: case ARG_ACTION: {
1431: targ = (GrammarAST) _t;
1432: match(_t, ARG_ACTION);
1433: _t = _t.getNextSibling();
1434: break;
1435: }
1436: case 3:
1437: case BANG:
1438: case ROOT: {
1439: break;
1440: }
1441: default: {
1442: throw new NoViableAltException(_t);
1443: }
1444: }
1445: }
1446: {
1447: if (_t == null)
1448: _t = ASTNULL;
1449: switch (_t.getType()) {
1450: case BANG:
1451: case ROOT: {
1452: as2 = _t == ASTNULL ? null : (GrammarAST) _t;
1453: ast_suffix(_t);
1454: _t = _retTree;
1455: break;
1456: }
1457: case 3: {
1458: break;
1459: }
1460: default: {
1461: throw new NoViableAltException(_t);
1462: }
1463: }
1464: }
1465: _t = __t88;
1466: _t = _t.getNextSibling();
1467:
1468: if (grammar.type == Grammar.LEXER) {
1469: NFAState start = grammar.getRuleStartState(t
1470: .getText());
1471: if (start != null) {
1472: int ruleIndex = grammar.getRuleIndex(t
1473: .getText());
1474: g = factory.build_RuleRef(ruleIndex, start);
1475: // don't add FOLLOW transitions in the lexer;
1476: // only exact context should be used.
1477: }
1478: } else {
1479: int tokenType = grammar.getTokenType(t.getText());
1480: g = factory.build_Atom(tokenType);
1481: t.followingNFAState = g.right;
1482: }
1483:
1484: break;
1485: }
1486: case CHAR_LITERAL: {
1487: AST __t91 = _t;
1488: c = _t == ASTNULL ? null : (GrammarAST) _t;
1489: match(_t, CHAR_LITERAL);
1490: _t = _t.getFirstChild();
1491: {
1492: if (_t == null)
1493: _t = ASTNULL;
1494: switch (_t.getType()) {
1495: case BANG:
1496: case ROOT: {
1497: as3 = _t == ASTNULL ? null : (GrammarAST) _t;
1498: ast_suffix(_t);
1499: _t = _retTree;
1500: break;
1501: }
1502: case 3: {
1503: break;
1504: }
1505: default: {
1506: throw new NoViableAltException(_t);
1507: }
1508: }
1509: }
1510: _t = __t91;
1511: _t = _t.getNextSibling();
1512:
1513: if (grammar.type == Grammar.LEXER) {
1514: g = factory.build_CharLiteralAtom(c.getText());
1515: } else {
1516: int tokenType = grammar.getTokenType(c.getText());
1517: g = factory.build_Atom(tokenType);
1518: c.followingNFAState = g.right;
1519: }
1520:
1521: break;
1522: }
1523: case STRING_LITERAL: {
1524: AST __t93 = _t;
1525: s = _t == ASTNULL ? null : (GrammarAST) _t;
1526: match(_t, STRING_LITERAL);
1527: _t = _t.getFirstChild();
1528: {
1529: if (_t == null)
1530: _t = ASTNULL;
1531: switch (_t.getType()) {
1532: case BANG:
1533: case ROOT: {
1534: as4 = _t == ASTNULL ? null : (GrammarAST) _t;
1535: ast_suffix(_t);
1536: _t = _retTree;
1537: break;
1538: }
1539: case 3: {
1540: break;
1541: }
1542: default: {
1543: throw new NoViableAltException(_t);
1544: }
1545: }
1546: }
1547: _t = __t93;
1548: _t = _t.getNextSibling();
1549:
1550: if (grammar.type == Grammar.LEXER) {
1551: g = factory.build_StringLiteralAtom(s.getText());
1552: } else {
1553: int tokenType = grammar.getTokenType(s.getText());
1554: g = factory.build_Atom(tokenType);
1555: s.followingNFAState = g.right;
1556: }
1557:
1558: break;
1559: }
1560: case WILDCARD: {
1561: AST __t95 = _t;
1562: w = _t == ASTNULL ? null : (GrammarAST) _t;
1563: match(_t, WILDCARD);
1564: _t = _t.getFirstChild();
1565: {
1566: if (_t == null)
1567: _t = ASTNULL;
1568: switch (_t.getType()) {
1569: case BANG:
1570: case ROOT: {
1571: as5 = _t == ASTNULL ? null : (GrammarAST) _t;
1572: ast_suffix(_t);
1573: _t = _retTree;
1574: break;
1575: }
1576: case 3: {
1577: break;
1578: }
1579: default: {
1580: throw new NoViableAltException(_t);
1581: }
1582: }
1583: }
1584: _t = __t95;
1585: _t = _t.getNextSibling();
1586: g = factory.build_Wildcard();
1587: break;
1588: }
1589: default: {
1590: throw new NoViableAltException(_t);
1591: }
1592: }
1593: } catch (RecognitionException ex) {
1594: reportError(ex);
1595: if (_t != null) {
1596: _t = _t.getNextSibling();
1597: }
1598: }
1599: _retTree = _t;
1600: return g;
1601: }
1602:
1603: public final StateCluster atom_or_notatom(AST _t)
1604: throws RecognitionException {
1605: StateCluster g = null;
1606:
1607: GrammarAST atom_or_notatom_AST_in = (_t == ASTNULL) ? null
1608: : (GrammarAST) _t;
1609: GrammarAST n = null;
1610: GrammarAST c = null;
1611: GrammarAST ast1 = null;
1612: GrammarAST t = null;
1613: GrammarAST ast3 = null;
1614:
1615: try { // for error handling
1616: if (_t == null)
1617: _t = ASTNULL;
1618: switch (_t.getType()) {
1619: case STRING_LITERAL:
1620: case CHAR_LITERAL:
1621: case TOKEN_REF:
1622: case RULE_REF:
1623: case WILDCARD: {
1624: g = atom(_t);
1625: _t = _retTree;
1626: break;
1627: }
1628: case NOT: {
1629: AST __t80 = _t;
1630: n = _t == ASTNULL ? null : (GrammarAST) _t;
1631: match(_t, NOT);
1632: _t = _t.getFirstChild();
1633: {
1634: if (_t == null)
1635: _t = ASTNULL;
1636: switch (_t.getType()) {
1637: case CHAR_LITERAL: {
1638: c = (GrammarAST) _t;
1639: match(_t, CHAR_LITERAL);
1640: _t = _t.getNextSibling();
1641: {
1642: if (_t == null)
1643: _t = ASTNULL;
1644: switch (_t.getType()) {
1645: case BANG:
1646: case ROOT: {
1647: ast1 = _t == ASTNULL ? null
1648: : (GrammarAST) _t;
1649: ast_suffix(_t);
1650: _t = _retTree;
1651: break;
1652: }
1653: case 3: {
1654: break;
1655: }
1656: default: {
1657: throw new NoViableAltException(_t);
1658: }
1659: }
1660: }
1661:
1662: int ttype = 0;
1663: if (grammar.type == Grammar.LEXER) {
1664: ttype = Grammar
1665: .getCharValueFromGrammarCharLiteral(c
1666: .getText());
1667: } else {
1668: ttype = grammar.getTokenType(c.getText());
1669: }
1670: IntSet notAtom = grammar.complement(ttype);
1671: if (notAtom.isNil()) {
1672: ErrorManager.grammarError(
1673: ErrorManager.MSG_EMPTY_COMPLEMENT,
1674: grammar, c.token, c.getText());
1675: }
1676: g = factory.build_Set(notAtom);
1677:
1678: break;
1679: }
1680: case TOKEN_REF: {
1681: t = (GrammarAST) _t;
1682: match(_t, TOKEN_REF);
1683: _t = _t.getNextSibling();
1684: {
1685: if (_t == null)
1686: _t = ASTNULL;
1687: switch (_t.getType()) {
1688: case BANG:
1689: case ROOT: {
1690: ast3 = _t == ASTNULL ? null
1691: : (GrammarAST) _t;
1692: ast_suffix(_t);
1693: _t = _retTree;
1694: break;
1695: }
1696: case 3: {
1697: break;
1698: }
1699: default: {
1700: throw new NoViableAltException(_t);
1701: }
1702: }
1703: }
1704:
1705: int ttype = 0;
1706: IntSet notAtom = null;
1707: if (grammar.type == Grammar.LEXER) {
1708: notAtom = grammar.getSetFromRule(this , t
1709: .getText());
1710: if (notAtom == null) {
1711: ErrorManager
1712: .grammarError(
1713: ErrorManager.MSG_RULE_INVALID_SET,
1714: grammar, t.token, t
1715: .getText());
1716: } else {
1717: notAtom = grammar.complement(notAtom);
1718: }
1719: } else {
1720: ttype = grammar.getTokenType(t.getText());
1721: notAtom = grammar.complement(ttype);
1722: }
1723: if (notAtom == null || notAtom.isNil()) {
1724: ErrorManager.grammarError(
1725: ErrorManager.MSG_EMPTY_COMPLEMENT,
1726: grammar, t.token, t.getText());
1727: }
1728: g = factory.build_Set(notAtom);
1729:
1730: break;
1731: }
1732: case BLOCK: {
1733: g = set(_t);
1734: _t = _retTree;
1735:
1736: GrammarAST stNode = (GrammarAST) n
1737: .getFirstChild();
1738: //IntSet notSet = grammar.complement(stNode.getSetValue());
1739: // let code generator complement the sets
1740: IntSet s = stNode.getSetValue();
1741: stNode.setSetValue(s);
1742: // let code gen do the complement again; here we compute
1743: // for NFA construction
1744: s = grammar.complement(s);
1745: if (s.isNil()) {
1746: ErrorManager.grammarError(
1747: ErrorManager.MSG_EMPTY_COMPLEMENT,
1748: grammar, n.token);
1749: }
1750: g = factory.build_Set(s);
1751:
1752: break;
1753: }
1754: default: {
1755: throw new NoViableAltException(_t);
1756: }
1757: }
1758: }
1759: n.followingNFAState = g.right;
1760: _t = __t80;
1761: _t = _t.getNextSibling();
1762: break;
1763: }
1764: default: {
1765: throw new NoViableAltException(_t);
1766: }
1767: }
1768: } catch (RecognitionException ex) {
1769: reportError(ex);
1770: if (_t != null) {
1771: _t = _t.getNextSibling();
1772: }
1773: }
1774: _retTree = _t;
1775: return g;
1776: }
1777:
1778: public final StateCluster ebnf(AST _t) throws RecognitionException {
1779: StateCluster g = null;
1780:
1781: GrammarAST ebnf_AST_in = (_t == ASTNULL) ? null
1782: : (GrammarAST) _t;
1783:
1784: StateCluster b = null;
1785: GrammarAST blk = ebnf_AST_in;
1786: if (blk.getType() != BLOCK) {
1787: blk = (GrammarAST) blk.getFirstChild();
1788: }
1789: GrammarAST eob = blk.getLastChild();
1790:
1791: try { // for error handling
1792: if (_t == null)
1793: _t = ASTNULL;
1794: switch (_t.getType()) {
1795: case OPTIONAL: {
1796: AST __t72 = _t;
1797: GrammarAST tmp58_AST_in = (GrammarAST) _t;
1798: match(_t, OPTIONAL);
1799: _t = _t.getFirstChild();
1800: b = block(_t);
1801: _t = _retTree;
1802: _t = __t72;
1803: _t = _t.getNextSibling();
1804:
1805: if (blk.setValue != null) {
1806: // if block comes back SET not BLOCK, make it
1807: // a single ALT block
1808: b = factory.build_AlternativeBlockFromSet(b);
1809: }
1810: g = factory.build_Aoptional(b);
1811: g.left.setDescription(grammar.grammarTreeToString(
1812: ebnf_AST_in, false));
1813: // there is always at least one alt even if block has just 1 alt
1814: int d = grammar.assignDecisionNumber(g.left);
1815: grammar.setDecisionNFA(d, g.left);
1816: grammar.setDecisionBlockAST(d, blk);
1817: g.left.setDecisionASTNode(ebnf_AST_in);
1818:
1819: break;
1820: }
1821: case CLOSURE: {
1822: AST __t73 = _t;
1823: GrammarAST tmp59_AST_in = (GrammarAST) _t;
1824: match(_t, CLOSURE);
1825: _t = _t.getFirstChild();
1826: b = block(_t);
1827: _t = _retTree;
1828: _t = __t73;
1829: _t = _t.getNextSibling();
1830:
1831: if (blk.setValue != null) {
1832: b = factory.build_AlternativeBlockFromSet(b);
1833: }
1834: g = factory.build_Astar(b);
1835: // track the loop back / exit decision point
1836: b.right.setDescription("()* loopback of "
1837: + grammar.grammarTreeToString(ebnf_AST_in,
1838: false));
1839: int d = grammar.assignDecisionNumber(b.right);
1840: grammar.setDecisionNFA(d, b.right);
1841: grammar.setDecisionBlockAST(d, blk);
1842: b.right.setDecisionASTNode(eob);
1843: // make block entry state also have same decision for interpreting grammar
1844: NFAState altBlockState = (NFAState) g.left
1845: .transition(0).target;
1846: altBlockState.setDecisionASTNode(ebnf_AST_in);
1847: altBlockState.setDecisionNumber(d);
1848: g.left.setDecisionNumber(d); // this is the bypass decision (2 alts)
1849: g.left.setDecisionASTNode(ebnf_AST_in);
1850:
1851: break;
1852: }
1853: case POSITIVE_CLOSURE: {
1854: AST __t74 = _t;
1855: GrammarAST tmp60_AST_in = (GrammarAST) _t;
1856: match(_t, POSITIVE_CLOSURE);
1857: _t = _t.getFirstChild();
1858: b = block(_t);
1859: _t = _retTree;
1860: _t = __t74;
1861: _t = _t.getNextSibling();
1862:
1863: if (blk.setValue != null) {
1864: b = factory.build_AlternativeBlockFromSet(b);
1865: }
1866: g = factory.build_Aplus(b);
1867: // don't make a decision on left edge, can reuse loop end decision
1868: // track the loop back / exit decision point
1869: b.right.setDescription("()+ loopback of "
1870: + grammar.grammarTreeToString(ebnf_AST_in,
1871: false));
1872: int d = grammar.assignDecisionNumber(b.right);
1873: grammar.setDecisionNFA(d, b.right);
1874: grammar.setDecisionBlockAST(d, blk);
1875: b.right.setDecisionASTNode(eob);
1876: // make block entry state also have same decision for interpreting grammar
1877: NFAState altBlockState = (NFAState) g.left
1878: .transition(0).target;
1879: altBlockState.setDecisionASTNode(ebnf_AST_in);
1880: altBlockState.setDecisionNumber(d);
1881:
1882: break;
1883: }
1884: default:
1885: if (_t == null)
1886: _t = ASTNULL;
1887: if (((_t.getType() == BLOCK))
1888: && (grammar.isValidSet(this , ebnf_AST_in))) {
1889: g = set(_t);
1890: _t = _retTree;
1891: } else if ((_t.getType() == BLOCK)) {
1892: b = block(_t);
1893: _t = _retTree;
1894:
1895: // track decision if > 1 alts
1896: if (grammar.getNumberOfAltsForDecisionNFA(b.left) > 1) {
1897: b.left.setDescription(grammar
1898: .grammarTreeToString(blk, false));
1899: b.left.setDecisionASTNode(blk);
1900: int d = grammar.assignDecisionNumber(b.left);
1901: grammar.setDecisionNFA(d, b.left);
1902: grammar.setDecisionBlockAST(d, blk);
1903: }
1904: g = b;
1905:
1906: } else {
1907: throw new NoViableAltException(_t);
1908: }
1909: }
1910: } catch (RecognitionException ex) {
1911: reportError(ex);
1912: if (_t != null) {
1913: _t = _t.getNextSibling();
1914: }
1915: }
1916: _retTree = _t;
1917: return g;
1918: }
1919:
1920: public final StateCluster tree(AST _t) throws RecognitionException {
1921: StateCluster g = null;
1922:
1923: GrammarAST tree_AST_in = (_t == ASTNULL) ? null
1924: : (GrammarAST) _t;
1925:
1926: StateCluster e = null;
1927: GrammarAST el = null;
1928: StateCluster down = null, up = null;
1929:
1930: try { // for error handling
1931: AST __t76 = _t;
1932: GrammarAST tmp61_AST_in = (GrammarAST) _t;
1933: match(_t, TREE_BEGIN);
1934: _t = _t.getFirstChild();
1935: el = (GrammarAST) _t;
1936: g = element(_t);
1937: _t = _retTree;
1938:
1939: down = factory.build_Atom(Label.DOWN);
1940: // TODO set following states for imaginary nodes?
1941: //el.followingNFAState = down.right;
1942: g = factory.build_AB(g, down);
1943:
1944: {
1945: _loop78: do {
1946: if (_t == null)
1947: _t = ASTNULL;
1948: if ((_tokenSet_0.member(_t.getType()))) {
1949: el = (GrammarAST) _t;
1950: e = element(_t);
1951: _t = _retTree;
1952: g = factory.build_AB(g, e);
1953: } else {
1954: break _loop78;
1955: }
1956:
1957: } while (true);
1958: }
1959:
1960: up = factory.build_Atom(Label.UP);
1961: //el.followingNFAState = up.right;
1962: g = factory.build_AB(g, up);
1963: // tree roots point at right edge of DOWN for LOOK computation later
1964: tree_AST_in.NFATreeDownState = down.left;
1965:
1966: _t = __t76;
1967: _t = _t.getNextSibling();
1968: } catch (RecognitionException ex) {
1969: reportError(ex);
1970: if (_t != null) {
1971: _t = _t.getNextSibling();
1972: }
1973: }
1974: _retTree = _t;
1975: return g;
1976: }
1977:
1978: public final void ast_suffix(AST _t) throws RecognitionException {
1979:
1980: GrammarAST ast_suffix_AST_in = (_t == ASTNULL) ? null
1981: : (GrammarAST) _t;
1982:
1983: if (grammar.getOption("output") == null) {
1984: ErrorManager
1985: .grammarError(
1986: ErrorManager.MSG_REWRITE_OR_OP_WITH_NO_OUTPUT_OPTION,
1987: grammar, ast_suffix_AST_in.token,
1988: currentRuleName);
1989: }
1990:
1991: try { // for error handling
1992: if (_t == null)
1993: _t = ASTNULL;
1994: switch (_t.getType()) {
1995: case ROOT: {
1996: GrammarAST tmp62_AST_in = (GrammarAST) _t;
1997: match(_t, ROOT);
1998: _t = _t.getNextSibling();
1999: break;
2000: }
2001: case BANG: {
2002: GrammarAST tmp63_AST_in = (GrammarAST) _t;
2003: match(_t, BANG);
2004: _t = _t.getNextSibling();
2005: break;
2006: }
2007: default: {
2008: throw new NoViableAltException(_t);
2009: }
2010: }
2011: } catch (RecognitionException ex) {
2012: reportError(ex);
2013: if (_t != null) {
2014: _t = _t.getNextSibling();
2015: }
2016: }
2017: _retTree = _t;
2018: }
2019:
2020: public final void setElement(AST _t, IntSet elements)
2021: throws RecognitionException {
2022:
2023: GrammarAST setElement_AST_in = (_t == ASTNULL) ? null
2024: : (GrammarAST) _t;
2025: GrammarAST c = null;
2026: GrammarAST t = null;
2027: GrammarAST s = null;
2028: GrammarAST c1 = null;
2029: GrammarAST c2 = null;
2030:
2031: int ttype;
2032: IntSet ns = null;
2033: StateCluster gset;
2034:
2035: try { // for error handling
2036: if (_t == null)
2037: _t = ASTNULL;
2038: switch (_t.getType()) {
2039: case CHAR_LITERAL: {
2040: c = (GrammarAST) _t;
2041: match(_t, CHAR_LITERAL);
2042: _t = _t.getNextSibling();
2043:
2044: if (grammar.type == Grammar.LEXER) {
2045: ttype = Grammar
2046: .getCharValueFromGrammarCharLiteral(c
2047: .getText());
2048: } else {
2049: ttype = grammar.getTokenType(c.getText());
2050: }
2051: if (elements.member(ttype)) {
2052: ErrorManager.grammarError(
2053: ErrorManager.MSG_DUPLICATE_SET_ENTRY,
2054: grammar, c.token, c.getText());
2055: }
2056: elements.add(ttype);
2057:
2058: break;
2059: }
2060: case TOKEN_REF: {
2061: t = (GrammarAST) _t;
2062: match(_t, TOKEN_REF);
2063: _t = _t.getNextSibling();
2064:
2065: if (grammar.type == Grammar.LEXER) {
2066: // recursively will invoke this rule to match elements in target rule ref
2067: IntSet ruleSet = grammar.getSetFromRule(this , t
2068: .getText());
2069: if (ruleSet == null) {
2070: ErrorManager.grammarError(
2071: ErrorManager.MSG_RULE_INVALID_SET,
2072: grammar, t.token, t.getText());
2073: } else {
2074: elements.addAll(ruleSet);
2075: }
2076: } else {
2077: ttype = grammar.getTokenType(t.getText());
2078: if (elements.member(ttype)) {
2079: ErrorManager.grammarError(
2080: ErrorManager.MSG_DUPLICATE_SET_ENTRY,
2081: grammar, t.token, t.getText());
2082: }
2083: elements.add(ttype);
2084: }
2085:
2086: break;
2087: }
2088: case STRING_LITERAL: {
2089: s = (GrammarAST) _t;
2090: match(_t, STRING_LITERAL);
2091: _t = _t.getNextSibling();
2092:
2093: ttype = grammar.getTokenType(s.getText());
2094: if (elements.member(ttype)) {
2095: ErrorManager.grammarError(
2096: ErrorManager.MSG_DUPLICATE_SET_ENTRY,
2097: grammar, s.token, s.getText());
2098: }
2099: elements.add(ttype);
2100:
2101: break;
2102: }
2103: case CHAR_RANGE: {
2104: AST __t118 = _t;
2105: GrammarAST tmp64_AST_in = (GrammarAST) _t;
2106: match(_t, CHAR_RANGE);
2107: _t = _t.getFirstChild();
2108: c1 = (GrammarAST) _t;
2109: match(_t, CHAR_LITERAL);
2110: _t = _t.getNextSibling();
2111: c2 = (GrammarAST) _t;
2112: match(_t, CHAR_LITERAL);
2113: _t = _t.getNextSibling();
2114: _t = __t118;
2115: _t = _t.getNextSibling();
2116:
2117: if (grammar.type == Grammar.LEXER) {
2118: int a = Grammar
2119: .getCharValueFromGrammarCharLiteral(c1
2120: .getText());
2121: int b = Grammar
2122: .getCharValueFromGrammarCharLiteral(c2
2123: .getText());
2124: elements.addAll(IntervalSet.of(a, b));
2125: }
2126:
2127: break;
2128: }
2129: case BLOCK: {
2130: gset = set(_t);
2131: _t = _retTree;
2132:
2133: Transition setTrans = gset.left.transition(0);
2134: elements.addAll(setTrans.label.getSet());
2135:
2136: break;
2137: }
2138: case NOT: {
2139: AST __t119 = _t;
2140: GrammarAST tmp65_AST_in = (GrammarAST) _t;
2141: match(_t, NOT);
2142: _t = _t.getFirstChild();
2143: ns = new IntervalSet();
2144: setElement(_t, ns);
2145: _t = _retTree;
2146:
2147: IntSet not = grammar.complement(ns);
2148: elements.addAll(not);
2149:
2150: _t = __t119;
2151: _t = _t.getNextSibling();
2152: break;
2153: }
2154: default: {
2155: throw new NoViableAltException(_t);
2156: }
2157: }
2158: } catch (RecognitionException ex) {
2159: reportError(ex);
2160: if (_t != null) {
2161: _t = _t.getNextSibling();
2162: }
2163: }
2164: _retTree = _t;
2165: }
2166:
2167: public final IntSet setRule(AST _t) throws RecognitionException {
2168: IntSet elements = new IntervalSet();
2169:
2170: GrammarAST setRule_AST_in = (_t == ASTNULL) ? null
2171: : (GrammarAST) _t;
2172: GrammarAST id = null;
2173: IntSet s = null;
2174:
2175: try { // for error handling
2176: AST __t105 = _t;
2177: GrammarAST tmp66_AST_in = (GrammarAST) _t;
2178: match(_t, RULE);
2179: _t = _t.getFirstChild();
2180: id = (GrammarAST) _t;
2181: match(_t, ID);
2182: _t = _t.getNextSibling();
2183: {
2184: if (_t == null)
2185: _t = ASTNULL;
2186: switch (_t.getType()) {
2187: case FRAGMENT:
2188: case LITERAL_protected:
2189: case LITERAL_public:
2190: case LITERAL_private: {
2191: modifier(_t);
2192: _t = _retTree;
2193: break;
2194: }
2195: case ARG: {
2196: break;
2197: }
2198: default: {
2199: throw new NoViableAltException(_t);
2200: }
2201: }
2202: }
2203: GrammarAST tmp67_AST_in = (GrammarAST) _t;
2204: match(_t, ARG);
2205: _t = _t.getNextSibling();
2206: GrammarAST tmp68_AST_in = (GrammarAST) _t;
2207: match(_t, RET);
2208: _t = _t.getNextSibling();
2209: {
2210: if (_t == null)
2211: _t = ASTNULL;
2212: switch (_t.getType()) {
2213: case OPTIONS: {
2214: GrammarAST tmp69_AST_in = (GrammarAST) _t;
2215: match(_t, OPTIONS);
2216: _t = _t.getNextSibling();
2217: break;
2218: }
2219: case BLOCK:
2220: case SCOPE:
2221: case AMPERSAND: {
2222: break;
2223: }
2224: default: {
2225: throw new NoViableAltException(_t);
2226: }
2227: }
2228: }
2229: {
2230: if (_t == null)
2231: _t = ASTNULL;
2232: switch (_t.getType()) {
2233: case SCOPE: {
2234: ruleScopeSpec(_t);
2235: _t = _retTree;
2236: break;
2237: }
2238: case BLOCK:
2239: case AMPERSAND: {
2240: break;
2241: }
2242: default: {
2243: throw new NoViableAltException(_t);
2244: }
2245: }
2246: }
2247: {
2248: _loop110: do {
2249: if (_t == null)
2250: _t = ASTNULL;
2251: if ((_t.getType() == AMPERSAND)) {
2252: GrammarAST tmp70_AST_in = (GrammarAST) _t;
2253: match(_t, AMPERSAND);
2254: _t = _t.getNextSibling();
2255: } else {
2256: break _loop110;
2257: }
2258:
2259: } while (true);
2260: }
2261: AST __t111 = _t;
2262: GrammarAST tmp71_AST_in = (GrammarAST) _t;
2263: match(_t, BLOCK);
2264: _t = _t.getFirstChild();
2265: {
2266: if (_t == null)
2267: _t = ASTNULL;
2268: switch (_t.getType()) {
2269: case OPTIONS: {
2270: GrammarAST tmp72_AST_in = (GrammarAST) _t;
2271: match(_t, OPTIONS);
2272: _t = _t.getNextSibling();
2273: break;
2274: }
2275: case ALT: {
2276: break;
2277: }
2278: default: {
2279: throw new NoViableAltException(_t);
2280: }
2281: }
2282: }
2283: {
2284: int _cnt115 = 0;
2285: _loop115: do {
2286: if (_t == null)
2287: _t = ASTNULL;
2288: if ((_t.getType() == ALT)) {
2289: AST __t114 = _t;
2290: GrammarAST tmp73_AST_in = (GrammarAST) _t;
2291: match(_t, ALT);
2292: _t = _t.getFirstChild();
2293: setElement(_t, elements);
2294: _t = _retTree;
2295: GrammarAST tmp74_AST_in = (GrammarAST) _t;
2296: match(_t, EOA);
2297: _t = _t.getNextSibling();
2298: _t = __t114;
2299: _t = _t.getNextSibling();
2300: } else {
2301: if (_cnt115 >= 1) {
2302: break _loop115;
2303: } else {
2304: throw new NoViableAltException(_t);
2305: }
2306: }
2307:
2308: _cnt115++;
2309: } while (true);
2310: }
2311: GrammarAST tmp75_AST_in = (GrammarAST) _t;
2312: match(_t, EOB);
2313: _t = _t.getNextSibling();
2314: _t = __t111;
2315: _t = _t.getNextSibling();
2316: {
2317: if (_t == null)
2318: _t = ASTNULL;
2319: switch (_t.getType()) {
2320: case LITERAL_catch:
2321: case LITERAL_finally: {
2322: exceptionGroup(_t);
2323: _t = _retTree;
2324: break;
2325: }
2326: case EOR: {
2327: break;
2328: }
2329: default: {
2330: throw new NoViableAltException(_t);
2331: }
2332: }
2333: }
2334: GrammarAST tmp76_AST_in = (GrammarAST) _t;
2335: match(_t, EOR);
2336: _t = _t.getNextSibling();
2337: _t = __t105;
2338: _t = _t.getNextSibling();
2339: } catch (RecognitionException re) {
2340: throw re;
2341: }
2342: _retTree = _t;
2343: return elements;
2344: }
2345:
2346: /** Check to see if this block can be a set. Can't have actions
2347: * etc... Also can't be in a rule with a rewrite as we need
2348: * to track what's inside set for use in rewrite.
2349: */
2350: public final void testBlockAsSet(AST _t)
2351: throws RecognitionException {
2352:
2353: GrammarAST testBlockAsSet_AST_in = (_t == ASTNULL) ? null
2354: : (GrammarAST) _t;
2355:
2356: int nAlts = 0;
2357: Rule r = grammar.getRule(currentRuleName);
2358:
2359: try { // for error handling
2360: AST __t121 = _t;
2361: GrammarAST tmp77_AST_in = (GrammarAST) _t;
2362: match(_t, BLOCK);
2363: _t = _t.getFirstChild();
2364: {
2365: int _cnt125 = 0;
2366: _loop125: do {
2367: if (_t == null)
2368: _t = ASTNULL;
2369: if ((_t.getType() == ALT)) {
2370: AST __t123 = _t;
2371: GrammarAST tmp78_AST_in = (GrammarAST) _t;
2372: match(_t, ALT);
2373: _t = _t.getFirstChild();
2374: {
2375: if (_t == null)
2376: _t = ASTNULL;
2377: switch (_t.getType()) {
2378: case BACKTRACK_SEMPRED: {
2379: GrammarAST tmp79_AST_in = (GrammarAST) _t;
2380: match(_t, BACKTRACK_SEMPRED);
2381: _t = _t.getNextSibling();
2382: break;
2383: }
2384: case BLOCK:
2385: case CHAR_RANGE:
2386: case STRING_LITERAL:
2387: case CHAR_LITERAL:
2388: case TOKEN_REF:
2389: case NOT: {
2390: break;
2391: }
2392: default: {
2393: throw new NoViableAltException(_t);
2394: }
2395: }
2396: }
2397: testSetElement(_t);
2398: _t = _retTree;
2399: nAlts++;
2400: GrammarAST tmp80_AST_in = (GrammarAST) _t;
2401: match(_t, EOA);
2402: _t = _t.getNextSibling();
2403: _t = __t123;
2404: _t = _t.getNextSibling();
2405: if (!(!r.hasRewrite(outerAltNum)))
2406: throw new SemanticException(
2407: "!r.hasRewrite(outerAltNum)");
2408: } else {
2409: if (_cnt125 >= 1) {
2410: break _loop125;
2411: } else {
2412: throw new NoViableAltException(_t);
2413: }
2414: }
2415:
2416: _cnt125++;
2417: } while (true);
2418: }
2419: GrammarAST tmp81_AST_in = (GrammarAST) _t;
2420: match(_t, EOB);
2421: _t = _t.getNextSibling();
2422: _t = __t121;
2423: _t = _t.getNextSibling();
2424: if (!(nAlts > 1))
2425: throw new SemanticException("nAlts>1");
2426: } catch (RecognitionException re) {
2427: throw re;
2428: }
2429: _retTree = _t;
2430: }
2431:
2432: /** Match just an element; no ast suffix etc.. */
2433: public final void testSetElement(AST _t)
2434: throws RecognitionException {
2435:
2436: GrammarAST testSetElement_AST_in = (_t == ASTNULL) ? null
2437: : (GrammarAST) _t;
2438: GrammarAST c = null;
2439: GrammarAST t = null;
2440: GrammarAST s = null;
2441: GrammarAST c1 = null;
2442: GrammarAST c2 = null;
2443:
2444: AST r = _t;
2445:
2446: try { // for error handling
2447: if (_t == null)
2448: _t = ASTNULL;
2449: switch (_t.getType()) {
2450: case CHAR_LITERAL: {
2451: c = (GrammarAST) _t;
2452: match(_t, CHAR_LITERAL);
2453: _t = _t.getNextSibling();
2454: break;
2455: }
2456: case TOKEN_REF: {
2457: t = (GrammarAST) _t;
2458: match(_t, TOKEN_REF);
2459: _t = _t.getNextSibling();
2460:
2461: if (grammar.type == Grammar.LEXER) {
2462: Rule rule = grammar.getRule(t.getText());
2463: if (rule == null) {
2464: throw new RecognitionException("invalid rule");
2465: }
2466: // recursively will invoke this rule to match elements in target rule ref
2467: testSetRule(rule.tree);
2468: }
2469:
2470: break;
2471: }
2472: case CHAR_RANGE: {
2473: AST __t140 = _t;
2474: GrammarAST tmp82_AST_in = (GrammarAST) _t;
2475: match(_t, CHAR_RANGE);
2476: _t = _t.getFirstChild();
2477: c1 = (GrammarAST) _t;
2478: match(_t, CHAR_LITERAL);
2479: _t = _t.getNextSibling();
2480: c2 = (GrammarAST) _t;
2481: match(_t, CHAR_LITERAL);
2482: _t = _t.getNextSibling();
2483: _t = __t140;
2484: _t = _t.getNextSibling();
2485: break;
2486: }
2487: case BLOCK: {
2488: testBlockAsSet(_t);
2489: _t = _retTree;
2490: break;
2491: }
2492: case NOT: {
2493: AST __t141 = _t;
2494: GrammarAST tmp83_AST_in = (GrammarAST) _t;
2495: match(_t, NOT);
2496: _t = _t.getFirstChild();
2497: testSetElement(_t);
2498: _t = _retTree;
2499: _t = __t141;
2500: _t = _t.getNextSibling();
2501: break;
2502: }
2503: default:
2504: if (_t == null)
2505: _t = ASTNULL;
2506: if (((_t.getType() == STRING_LITERAL))
2507: && (grammar.type != Grammar.LEXER)) {
2508: s = (GrammarAST) _t;
2509: match(_t, STRING_LITERAL);
2510: _t = _t.getNextSibling();
2511: } else {
2512: throw new NoViableAltException(_t);
2513: }
2514: }
2515: } catch (RecognitionException re) {
2516: throw re;
2517: }
2518: _retTree = _t;
2519: }
2520:
2521: public final void testSetRule(AST _t) throws RecognitionException {
2522:
2523: GrammarAST testSetRule_AST_in = (_t == ASTNULL) ? null
2524: : (GrammarAST) _t;
2525: GrammarAST id = null;
2526:
2527: try { // for error handling
2528: AST __t127 = _t;
2529: GrammarAST tmp84_AST_in = (GrammarAST) _t;
2530: match(_t, RULE);
2531: _t = _t.getFirstChild();
2532: id = (GrammarAST) _t;
2533: match(_t, ID);
2534: _t = _t.getNextSibling();
2535: {
2536: if (_t == null)
2537: _t = ASTNULL;
2538: switch (_t.getType()) {
2539: case FRAGMENT:
2540: case LITERAL_protected:
2541: case LITERAL_public:
2542: case LITERAL_private: {
2543: modifier(_t);
2544: _t = _retTree;
2545: break;
2546: }
2547: case ARG: {
2548: break;
2549: }
2550: default: {
2551: throw new NoViableAltException(_t);
2552: }
2553: }
2554: }
2555: GrammarAST tmp85_AST_in = (GrammarAST) _t;
2556: match(_t, ARG);
2557: _t = _t.getNextSibling();
2558: GrammarAST tmp86_AST_in = (GrammarAST) _t;
2559: match(_t, RET);
2560: _t = _t.getNextSibling();
2561: {
2562: if (_t == null)
2563: _t = ASTNULL;
2564: switch (_t.getType()) {
2565: case OPTIONS: {
2566: GrammarAST tmp87_AST_in = (GrammarAST) _t;
2567: match(_t, OPTIONS);
2568: _t = _t.getNextSibling();
2569: break;
2570: }
2571: case BLOCK:
2572: case SCOPE:
2573: case AMPERSAND: {
2574: break;
2575: }
2576: default: {
2577: throw new NoViableAltException(_t);
2578: }
2579: }
2580: }
2581: {
2582: if (_t == null)
2583: _t = ASTNULL;
2584: switch (_t.getType()) {
2585: case SCOPE: {
2586: ruleScopeSpec(_t);
2587: _t = _retTree;
2588: break;
2589: }
2590: case BLOCK:
2591: case AMPERSAND: {
2592: break;
2593: }
2594: default: {
2595: throw new NoViableAltException(_t);
2596: }
2597: }
2598: }
2599: {
2600: _loop132: do {
2601: if (_t == null)
2602: _t = ASTNULL;
2603: if ((_t.getType() == AMPERSAND)) {
2604: GrammarAST tmp88_AST_in = (GrammarAST) _t;
2605: match(_t, AMPERSAND);
2606: _t = _t.getNextSibling();
2607: } else {
2608: break _loop132;
2609: }
2610:
2611: } while (true);
2612: }
2613: AST __t133 = _t;
2614: GrammarAST tmp89_AST_in = (GrammarAST) _t;
2615: match(_t, BLOCK);
2616: _t = _t.getFirstChild();
2617: {
2618: int _cnt137 = 0;
2619: _loop137: do {
2620: if (_t == null)
2621: _t = ASTNULL;
2622: if ((_t.getType() == ALT)) {
2623: AST __t135 = _t;
2624: GrammarAST tmp90_AST_in = (GrammarAST) _t;
2625: match(_t, ALT);
2626: _t = _t.getFirstChild();
2627: {
2628: if (_t == null)
2629: _t = ASTNULL;
2630: switch (_t.getType()) {
2631: case BACKTRACK_SEMPRED: {
2632: GrammarAST tmp91_AST_in = (GrammarAST) _t;
2633: match(_t, BACKTRACK_SEMPRED);
2634: _t = _t.getNextSibling();
2635: break;
2636: }
2637: case BLOCK:
2638: case CHAR_RANGE:
2639: case STRING_LITERAL:
2640: case CHAR_LITERAL:
2641: case TOKEN_REF:
2642: case NOT: {
2643: break;
2644: }
2645: default: {
2646: throw new NoViableAltException(_t);
2647: }
2648: }
2649: }
2650: testSetElement(_t);
2651: _t = _retTree;
2652: GrammarAST tmp92_AST_in = (GrammarAST) _t;
2653: match(_t, EOA);
2654: _t = _t.getNextSibling();
2655: _t = __t135;
2656: _t = _t.getNextSibling();
2657: } else {
2658: if (_cnt137 >= 1) {
2659: break _loop137;
2660: } else {
2661: throw new NoViableAltException(_t);
2662: }
2663: }
2664:
2665: _cnt137++;
2666: } while (true);
2667: }
2668: GrammarAST tmp93_AST_in = (GrammarAST) _t;
2669: match(_t, EOB);
2670: _t = _t.getNextSibling();
2671: _t = __t133;
2672: _t = _t.getNextSibling();
2673: {
2674: if (_t == null)
2675: _t = ASTNULL;
2676: switch (_t.getType()) {
2677: case LITERAL_catch:
2678: case LITERAL_finally: {
2679: exceptionGroup(_t);
2680: _t = _retTree;
2681: break;
2682: }
2683: case EOR: {
2684: break;
2685: }
2686: default: {
2687: throw new NoViableAltException(_t);
2688: }
2689: }
2690: }
2691: GrammarAST tmp94_AST_in = (GrammarAST) _t;
2692: match(_t, EOR);
2693: _t = _t.getNextSibling();
2694: _t = __t127;
2695: _t = _t.getNextSibling();
2696: } catch (RecognitionException re) {
2697: throw re;
2698: }
2699: _retTree = _t;
2700: }
2701:
2702: public static final String[] _tokenNames = { "<0>", "EOF", "<2>",
2703: "NULL_TREE_LOOKAHEAD", "\"options\"", "\"tokens\"",
2704: "\"parser\"", "LEXER", "RULE", "BLOCK", "OPTIONAL",
2705: "CLOSURE", "POSITIVE_CLOSURE", "SYNPRED", "RANGE",
2706: "CHAR_RANGE", "EPSILON", "ALT", "EOR", "EOB", "EOA", "ID",
2707: "ARG", "ARGLIST", "RET", "LEXER_GRAMMAR", "PARSER_GRAMMAR",
2708: "TREE_GRAMMAR", "COMBINED_GRAMMAR", "INITACTION", "LABEL",
2709: "TEMPLATE", "\"scope\"", "GATED_SEMPRED", "SYN_SEMPRED",
2710: "BACKTRACK_SEMPRED", "\"fragment\"", "ACTION",
2711: "DOC_COMMENT", "SEMI", "\"lexer\"", "\"tree\"",
2712: "\"grammar\"", "AMPERSAND", "COLON", "RCURLY", "ASSIGN",
2713: "STRING_LITERAL", "CHAR_LITERAL", "INT", "STAR",
2714: "TOKEN_REF", "\"protected\"", "\"public\"", "\"private\"",
2715: "BANG", "ARG_ACTION", "\"returns\"", "\"throws\"", "COMMA",
2716: "LPAREN", "OR", "RPAREN", "\"catch\"", "\"finally\"",
2717: "PLUS_ASSIGN", "SEMPRED", "IMPLIES", "ROOT", "RULE_REF",
2718: "NOT", "TREE_BEGIN", "QUESTION", "PLUS", "WILDCARD",
2719: "REWRITE", "DOLLAR", "DOUBLE_QUOTE_STRING_LITERAL",
2720: "DOUBLE_ANGLE_STRING_LITERAL", "WS", "COMMENT",
2721: "SL_COMMENT", "ML_COMMENT", "OPEN_ELEMENT_OPTION",
2722: "CLOSE_ELEMENT_OPTION", "ESC", "DIGIT", "XDIGIT",
2723: "NESTED_ARG_ACTION", "NESTED_ACTION",
2724: "ACTION_CHAR_LITERAL", "ACTION_STRING_LITERAL",
2725: "ACTION_ESC", "WS_LOOP", "INTERNAL_RULE_REF", "WS_OPT",
2726: "SRC" };
2727:
2728: private static final long[] mk_tokenSet_0() {
2729: long[] data = { 38773375610519040L, 1270L, 0L, 0L };
2730: return data;
2731: }
2732:
2733: public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0());
2734: }
|