0001: // $ANTLR 2.7.7 (2006-01-29): "assign.types.g" -> "AssignTokenTypesWalker.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: import java.io.*;
0036:
0037: import antlr.TreeParser;
0038: import antlr.Token;
0039: import antlr.collections.AST;
0040: import antlr.RecognitionException;
0041: import antlr.ANTLRException;
0042: import antlr.NoViableAltException;
0043: import antlr.MismatchedTokenException;
0044: import antlr.SemanticException;
0045: import antlr.collections.impl.BitSet;
0046: import antlr.ASTPair;
0047: import antlr.collections.impl.ASTArray;
0048:
0049: /** [Warning: TJP says that this is probably out of date as of 11/19/2005,
0050: * but since it's probably still useful, I'll leave in. Don't have energy
0051: * to update at the moment.]
0052: *
0053: * Compute the token types for all literals and rules etc.. There are
0054: * a few different cases to consider for grammar types and a few situations
0055: * within.
0056: *
0057: * CASE 1 : pure parser grammar
0058: * a) Any reference to a token gets a token type.
0059: * b) The tokens section may alias a token name to a string or char
0060: *
0061: * CASE 2 : pure lexer grammar
0062: * a) Import token vocabulary if available. Set token types for any new tokens
0063: * to values above last imported token type
0064: * b) token rule definitions get token types if not already defined
0065: * c) literals do NOT get token types
0066: *
0067: * CASE 3 : merged parser / lexer grammar
0068: * a) Any char or string literal gets a token type in a parser rule
0069: * b) Any reference to a token gets a token type if not referencing
0070: * a fragment lexer rule
0071: * c) The tokens section may alias a token name to a string or char
0072: * which must add a rule to the lexer
0073: * d) token rule definitions get token types if not already defined
0074: * e) token rule definitions may also alias a token name to a literal.
0075: * E.g., Rule 'FOR : "for";' will alias FOR to "for" in the sense that
0076: * references to either in the parser grammar will yield the token type
0077: *
0078: * What this pass does:
0079: *
0080: * 0. Collects basic info about the grammar like grammar name and type;
0081: * Oh, I have go get the options in case they affect the token types.
0082: * E.g., tokenVocab option.
0083: * Imports any token vocab name/type pairs into a local hashtable.
0084: * 1. Finds a list of all literals and token names.
0085: * 2. Finds a list of all token name rule definitions;
0086: * no token rules implies pure parser.
0087: * 3. Finds a list of all simple token rule defs of form "<NAME> : <literal>;"
0088: * and aliases them.
0089: * 4. Walks token names table and assign types to any unassigned
0090: * 5. Walks aliases and assign types to referenced literals
0091: * 6. Walks literals, assigning types if untyped
0092: * 4. Informs the Grammar object of the type definitions such as:
0093: * g.defineToken(<charliteral>, ttype);
0094: * g.defineToken(<stringliteral>, ttype);
0095: * g.defineToken(<tokenID>, ttype);
0096: * where some of the ttype values will be the same for aliases tokens.
0097: */
0098: public class AssignTokenTypesWalker extends antlr.TreeParser implements
0099: AssignTokenTypesWalkerTokenTypes {
0100:
0101: public void reportError(RecognitionException ex) {
0102: Token token = null;
0103: if (ex instanceof MismatchedTokenException) {
0104: token = ((MismatchedTokenException) ex).token;
0105: } else if (ex instanceof NoViableAltException) {
0106: token = ((NoViableAltException) ex).token;
0107: }
0108: ErrorManager.syntaxError(ErrorManager.MSG_SYNTAX_ERROR,
0109: grammar, token, "assign.types: " + ex.toString(), ex);
0110: }
0111:
0112: protected GrammarAST stringAlias;
0113: protected GrammarAST charAlias;
0114: protected GrammarAST stringAlias2;
0115: protected GrammarAST charAlias2;
0116:
0117: protected Grammar grammar;
0118: protected Map stringLiterals = new LinkedHashMap(); // Map<literal,Integer>
0119: protected Map tokens = new LinkedHashMap(); // Map<name,Integer>
0120: /** Track actual lexer rule defs so we don't get repeated token defs in
0121: * generated lexer.
0122: */
0123: protected Set tokenRuleDefs = new HashSet(); // Set<name>
0124: protected Map aliases = new LinkedHashMap(); // Map<name,literal>
0125: protected String currentRuleName;
0126: protected static final Integer UNASSIGNED = Utils.integer(-1);
0127: protected static final Integer UNASSIGNED_IN_PARSER_RULE = Utils
0128: .integer(-2);
0129:
0130: /** Track string literals in any non-lexer rule (could be in tokens{} section) */
0131: protected void trackString(GrammarAST t) {
0132: // if lexer, don't allow aliasing in tokens section
0133: if (currentRuleName == null && grammar.type == Grammar.LEXER) {
0134: ErrorManager.grammarError(
0135: ErrorManager.MSG_CANNOT_ALIAS_TOKENS_IN_LEXER,
0136: grammar, t.token, t.getText());
0137: return;
0138: }
0139: // in a plain parser grammar rule, cannot reference literals
0140: // (unless defined previously via tokenVocab option)
0141: if (grammar.type == Grammar.PARSER
0142: && grammar.getTokenType(t.getText()) == Label.INVALID) {
0143: ErrorManager
0144: .grammarError(
0145: ErrorManager.MSG_LITERAL_NOT_ASSOCIATED_WITH_LEXER_RULE,
0146: grammar, t.token, t.getText());
0147: }
0148: // otherwise add literal to token types if referenced from parser rule
0149: // or in the tokens{} section
0150: if ((currentRuleName == null || Character
0151: .isLowerCase(currentRuleName.charAt(0)))
0152: && grammar.getTokenType(t.getText()) == Label.INVALID) {
0153: stringLiterals.put(t.getText(), UNASSIGNED_IN_PARSER_RULE);
0154: }
0155: }
0156:
0157: protected void trackToken(GrammarAST t) {
0158: // imported token names might exist, only add if new
0159: if (grammar.getTokenType(t.getText()) == Label.INVALID) {
0160: tokens.put(t.getText(), UNASSIGNED);
0161: }
0162: }
0163:
0164: protected void trackTokenRule(GrammarAST t, GrammarAST modifier,
0165: GrammarAST block) {
0166: // imported token names might exist, only add if new
0167: if (grammar.type == Grammar.LEXER
0168: || grammar.type == Grammar.COMBINED) {
0169: if (!Character.isUpperCase(t.getText().charAt(0))) {
0170: return;
0171: }
0172: int existing = grammar.getTokenType(t.getText());
0173: if (existing == Label.INVALID) {
0174: tokens.put(t.getText(), UNASSIGNED);
0175: }
0176: // look for "<TOKEN> : <literal> ;" pattern
0177: // (can have optional action last)
0178: if (block.hasSameTreeStructure(charAlias)
0179: || block.hasSameTreeStructure(stringAlias)
0180: || block.hasSameTreeStructure(charAlias2)
0181: || block.hasSameTreeStructure(stringAlias2)) {
0182: alias(t, (GrammarAST) block.getFirstChild()
0183: .getFirstChild());
0184: tokenRuleDefs.add(t.getText());
0185: }
0186: }
0187: // else error
0188: }
0189:
0190: protected void alias(GrammarAST t, GrammarAST s) {
0191: aliases.put(t.getText(), s.getText());
0192: }
0193:
0194: protected void assignTypes() {
0195: /*
0196: System.out.println("stringLiterals="+stringLiterals);
0197: System.out.println("tokens="+tokens);
0198: System.out.println("aliases="+aliases);
0199: */
0200:
0201: assignTokenIDTypes();
0202:
0203: aliasTokenIDsAndLiterals();
0204:
0205: assignStringTypes();
0206:
0207: /*
0208: System.out.println("AFTER:");
0209: System.out.println("stringLiterals="+stringLiterals);
0210: System.out.println("tokens="+tokens);
0211: System.out.println("aliases="+aliases);
0212: */
0213:
0214: notifyGrammarObject();
0215: }
0216:
0217: protected void assignStringTypes() {
0218: // walk string literals assigning types to unassigned ones
0219: Set s = stringLiterals.keySet();
0220: for (Iterator it = s.iterator(); it.hasNext();) {
0221: String lit = (String) it.next();
0222: Integer oldTypeI = (Integer) stringLiterals.get(lit);
0223: int oldType = oldTypeI.intValue();
0224: if (oldType < Label.MIN_TOKEN_TYPE) {
0225: Integer typeI = Utils
0226: .integer(grammar.getNewTokenType());
0227: stringLiterals.put(lit, typeI);
0228: // if string referenced in combined grammar parser rule,
0229: // automatically define in the generated lexer
0230: grammar.defineLexerRuleForStringLiteral(lit, typeI
0231: .intValue());
0232: }
0233: }
0234: }
0235:
0236: protected void aliasTokenIDsAndLiterals() {
0237: if (grammar.type == Grammar.LEXER) {
0238: return; // strings/chars are never token types in LEXER
0239: }
0240: // walk aliases if any and assign types to aliased literals if literal
0241: // was referenced
0242: Set s = aliases.keySet();
0243: for (Iterator it = s.iterator(); it.hasNext();) {
0244: String tokenID = (String) it.next();
0245: String literal = (String) aliases.get(tokenID);
0246: if (literal.charAt(0) == '\''
0247: && stringLiterals.get(literal) != null) {
0248: stringLiterals.put(literal, tokens.get(tokenID));
0249: // an alias still means you need a lexer rule for it
0250: Integer typeI = (Integer) tokens.get(tokenID);
0251: if (!tokenRuleDefs.contains(tokenID)) {
0252: grammar.defineLexerRuleForAliasedStringLiteral(
0253: tokenID, literal, typeI.intValue());
0254: }
0255: }
0256: }
0257: }
0258:
0259: protected void assignTokenIDTypes() {
0260: // walk token names, assigning values if unassigned
0261: Set s = tokens.keySet();
0262: for (Iterator it = s.iterator(); it.hasNext();) {
0263: String tokenID = (String) it.next();
0264: if (tokens.get(tokenID) == UNASSIGNED) {
0265: tokens.put(tokenID, Utils.integer(grammar
0266: .getNewTokenType()));
0267: }
0268: }
0269: }
0270:
0271: protected void notifyGrammarObject() {
0272: Set s = tokens.keySet();
0273: for (Iterator it = s.iterator(); it.hasNext();) {
0274: String tokenID = (String) it.next();
0275: int ttype = ((Integer) tokens.get(tokenID)).intValue();
0276: grammar.defineToken(tokenID, ttype);
0277: }
0278: s = stringLiterals.keySet();
0279: for (Iterator it = s.iterator(); it.hasNext();) {
0280: String lit = (String) it.next();
0281: int ttype = ((Integer) stringLiterals.get(lit)).intValue();
0282: grammar.defineToken(lit, ttype);
0283: }
0284: }
0285:
0286: protected void init(Grammar g) {
0287: this .grammar = g;
0288: stringAlias = (GrammarAST) astFactory
0289: .make((new ASTArray(3))
0290: .add((GrammarAST) astFactory.create(BLOCK))
0291: .add(
0292: (GrammarAST) astFactory
0293: .make((new ASTArray(3))
0294: .add(
0295: (GrammarAST) astFactory
0296: .create(ALT))
0297: .add(
0298: (GrammarAST) astFactory
0299: .create(STRING_LITERAL))
0300: .add(
0301: (GrammarAST) astFactory
0302: .create(EOA))))
0303: .add((GrammarAST) astFactory.create(EOB)));
0304: charAlias = (GrammarAST) astFactory.make((new ASTArray(3)).add(
0305: (GrammarAST) astFactory.create(BLOCK)).add(
0306: (GrammarAST) astFactory.make((new ASTArray(3)).add(
0307: (GrammarAST) astFactory.create(ALT)).add(
0308: (GrammarAST) astFactory.create(CHAR_LITERAL))
0309: .add((GrammarAST) astFactory.create(EOA))))
0310: .add((GrammarAST) astFactory.create(EOB)));
0311: stringAlias2 = (GrammarAST) astFactory
0312: .make((new ASTArray(3))
0313: .add((GrammarAST) astFactory.create(BLOCK))
0314: .add(
0315: (GrammarAST) astFactory
0316: .make((new ASTArray(4))
0317: .add(
0318: (GrammarAST) astFactory
0319: .create(ALT))
0320: .add(
0321: (GrammarAST) astFactory
0322: .create(STRING_LITERAL))
0323: .add(
0324: (GrammarAST) astFactory
0325: .create(ACTION))
0326: .add(
0327: (GrammarAST) astFactory
0328: .create(EOA))))
0329: .add((GrammarAST) astFactory.create(EOB)));
0330: charAlias2 = (GrammarAST) astFactory.make((new ASTArray(3))
0331: .add((GrammarAST) astFactory.create(BLOCK)).add(
0332: (GrammarAST) astFactory.make((new ASTArray(4))
0333: .add(
0334: (GrammarAST) astFactory
0335: .create(ALT)).add(
0336: (GrammarAST) astFactory
0337: .create(CHAR_LITERAL))
0338: .add(
0339: (GrammarAST) astFactory
0340: .create(ACTION)).add(
0341: (GrammarAST) astFactory
0342: .create(EOA)))).add(
0343: (GrammarAST) astFactory.create(EOB)));
0344: }
0345:
0346: public AssignTokenTypesWalker() {
0347: tokenNames = _tokenNames;
0348: }
0349:
0350: public final void grammar(AST _t, Grammar g)
0351: throws RecognitionException {
0352:
0353: GrammarAST grammar_AST_in = (_t == ASTNULL) ? null
0354: : (GrammarAST) _t;
0355:
0356: init(g);
0357:
0358: try { // for error handling
0359: {
0360: if (_t == null)
0361: _t = ASTNULL;
0362: switch (_t.getType()) {
0363: case LEXER_GRAMMAR: {
0364: AST __t3 = _t;
0365: GrammarAST tmp1_AST_in = (GrammarAST) _t;
0366: match(_t, LEXER_GRAMMAR);
0367: _t = _t.getFirstChild();
0368: grammar.type = Grammar.LEXER;
0369: grammarSpec(_t);
0370: _t = _retTree;
0371: _t = __t3;
0372: _t = _t.getNextSibling();
0373: break;
0374: }
0375: case PARSER_GRAMMAR: {
0376: AST __t4 = _t;
0377: GrammarAST tmp2_AST_in = (GrammarAST) _t;
0378: match(_t, PARSER_GRAMMAR);
0379: _t = _t.getFirstChild();
0380: grammar.type = Grammar.PARSER;
0381: grammarSpec(_t);
0382: _t = _retTree;
0383: _t = __t4;
0384: _t = _t.getNextSibling();
0385: break;
0386: }
0387: case TREE_GRAMMAR: {
0388: AST __t5 = _t;
0389: GrammarAST tmp3_AST_in = (GrammarAST) _t;
0390: match(_t, TREE_GRAMMAR);
0391: _t = _t.getFirstChild();
0392: grammar.type = Grammar.TREE_PARSER;
0393: grammarSpec(_t);
0394: _t = _retTree;
0395: _t = __t5;
0396: _t = _t.getNextSibling();
0397: break;
0398: }
0399: case COMBINED_GRAMMAR: {
0400: AST __t6 = _t;
0401: GrammarAST tmp4_AST_in = (GrammarAST) _t;
0402: match(_t, COMBINED_GRAMMAR);
0403: _t = _t.getFirstChild();
0404: grammar.type = Grammar.COMBINED;
0405: grammarSpec(_t);
0406: _t = _retTree;
0407: _t = __t6;
0408: _t = _t.getNextSibling();
0409: break;
0410: }
0411: default: {
0412: throw new NoViableAltException(_t);
0413: }
0414: }
0415: }
0416: assignTypes();
0417: } catch (RecognitionException ex) {
0418: reportError(ex);
0419: if (_t != null) {
0420: _t = _t.getNextSibling();
0421: }
0422: }
0423: _retTree = _t;
0424: }
0425:
0426: public final void grammarSpec(AST _t) throws RecognitionException {
0427:
0428: GrammarAST grammarSpec_AST_in = (_t == ASTNULL) ? null
0429: : (GrammarAST) _t;
0430: GrammarAST id = null;
0431: GrammarAST cmt = null;
0432: Map opts = null;
0433:
0434: try { // for error handling
0435: id = (GrammarAST) _t;
0436: match(_t, ID);
0437: _t = _t.getNextSibling();
0438: grammar.setName(id.getText());
0439: {
0440: if (_t == null)
0441: _t = ASTNULL;
0442: switch (_t.getType()) {
0443: case DOC_COMMENT: {
0444: cmt = (GrammarAST) _t;
0445: match(_t, DOC_COMMENT);
0446: _t = _t.getNextSibling();
0447: break;
0448: }
0449: case OPTIONS:
0450: case TOKENS:
0451: case RULE:
0452: case SCOPE:
0453: case AMPERSAND: {
0454: break;
0455: }
0456: default: {
0457: throw new NoViableAltException(_t);
0458: }
0459: }
0460: }
0461: {
0462: if (_t == null)
0463: _t = ASTNULL;
0464: switch (_t.getType()) {
0465: case OPTIONS: {
0466: optionsSpec(_t);
0467: _t = _retTree;
0468: break;
0469: }
0470: case TOKENS:
0471: case RULE:
0472: case SCOPE:
0473: case AMPERSAND: {
0474: break;
0475: }
0476: default: {
0477: throw new NoViableAltException(_t);
0478: }
0479: }
0480: }
0481: {
0482: if (_t == null)
0483: _t = ASTNULL;
0484: switch (_t.getType()) {
0485: case TOKENS: {
0486: tokensSpec(_t);
0487: _t = _retTree;
0488: break;
0489: }
0490: case RULE:
0491: case SCOPE:
0492: case AMPERSAND: {
0493: break;
0494: }
0495: default: {
0496: throw new NoViableAltException(_t);
0497: }
0498: }
0499: }
0500: {
0501: _loop12: do {
0502: if (_t == null)
0503: _t = ASTNULL;
0504: if ((_t.getType() == SCOPE)) {
0505: attrScope(_t);
0506: _t = _retTree;
0507: } else {
0508: break _loop12;
0509: }
0510:
0511: } while (true);
0512: }
0513: {
0514: _loop14: do {
0515: if (_t == null)
0516: _t = ASTNULL;
0517: if ((_t.getType() == AMPERSAND)) {
0518: GrammarAST tmp5_AST_in = (GrammarAST) _t;
0519: match(_t, AMPERSAND);
0520: _t = _t.getNextSibling();
0521: } else {
0522: break _loop14;
0523: }
0524:
0525: } while (true);
0526: }
0527: rules(_t);
0528: _t = _retTree;
0529: } catch (RecognitionException ex) {
0530: reportError(ex);
0531: if (_t != null) {
0532: _t = _t.getNextSibling();
0533: }
0534: }
0535: _retTree = _t;
0536: }
0537:
0538: public final Map optionsSpec(AST _t) throws RecognitionException {
0539: Map opts = new HashMap();
0540:
0541: GrammarAST optionsSpec_AST_in = (_t == ASTNULL) ? null
0542: : (GrammarAST) _t;
0543:
0544: try { // for error handling
0545: AST __t18 = _t;
0546: GrammarAST tmp6_AST_in = (GrammarAST) _t;
0547: match(_t, OPTIONS);
0548: _t = _t.getFirstChild();
0549: {
0550: int _cnt20 = 0;
0551: _loop20: do {
0552: if (_t == null)
0553: _t = ASTNULL;
0554: if ((_t.getType() == ASSIGN)) {
0555: option(_t, opts);
0556: _t = _retTree;
0557: } else {
0558: if (_cnt20 >= 1) {
0559: break _loop20;
0560: } else {
0561: throw new NoViableAltException(_t);
0562: }
0563: }
0564:
0565: _cnt20++;
0566: } while (true);
0567: }
0568: _t = __t18;
0569: _t = _t.getNextSibling();
0570: } catch (RecognitionException ex) {
0571: reportError(ex);
0572: if (_t != null) {
0573: _t = _t.getNextSibling();
0574: }
0575: }
0576: _retTree = _t;
0577: return opts;
0578: }
0579:
0580: public final void tokensSpec(AST _t) throws RecognitionException {
0581:
0582: GrammarAST tokensSpec_AST_in = (_t == ASTNULL) ? null
0583: : (GrammarAST) _t;
0584:
0585: try { // for error handling
0586: AST __t30 = _t;
0587: GrammarAST tmp7_AST_in = (GrammarAST) _t;
0588: match(_t, TOKENS);
0589: _t = _t.getFirstChild();
0590: {
0591: int _cnt32 = 0;
0592: _loop32: do {
0593: if (_t == null)
0594: _t = ASTNULL;
0595: if ((_t.getType() == ASSIGN || _t.getType() == TOKEN_REF)) {
0596: tokenSpec(_t);
0597: _t = _retTree;
0598: } else {
0599: if (_cnt32 >= 1) {
0600: break _loop32;
0601: } else {
0602: throw new NoViableAltException(_t);
0603: }
0604: }
0605:
0606: _cnt32++;
0607: } while (true);
0608: }
0609: _t = __t30;
0610: _t = _t.getNextSibling();
0611: } catch (RecognitionException ex) {
0612: reportError(ex);
0613: if (_t != null) {
0614: _t = _t.getNextSibling();
0615: }
0616: }
0617: _retTree = _t;
0618: }
0619:
0620: public final void attrScope(AST _t) throws RecognitionException {
0621:
0622: GrammarAST attrScope_AST_in = (_t == ASTNULL) ? null
0623: : (GrammarAST) _t;
0624:
0625: try { // for error handling
0626: AST __t16 = _t;
0627: GrammarAST tmp8_AST_in = (GrammarAST) _t;
0628: match(_t, SCOPE);
0629: _t = _t.getFirstChild();
0630: GrammarAST tmp9_AST_in = (GrammarAST) _t;
0631: match(_t, ID);
0632: _t = _t.getNextSibling();
0633: GrammarAST tmp10_AST_in = (GrammarAST) _t;
0634: match(_t, ACTION);
0635: _t = _t.getNextSibling();
0636: _t = __t16;
0637: _t = _t.getNextSibling();
0638: } catch (RecognitionException ex) {
0639: reportError(ex);
0640: if (_t != null) {
0641: _t = _t.getNextSibling();
0642: }
0643: }
0644: _retTree = _t;
0645: }
0646:
0647: public final void rules(AST _t) throws RecognitionException {
0648:
0649: GrammarAST rules_AST_in = (_t == ASTNULL) ? null
0650: : (GrammarAST) _t;
0651:
0652: try { // for error handling
0653: {
0654: int _cnt38 = 0;
0655: _loop38: do {
0656: if (_t == null)
0657: _t = ASTNULL;
0658: if ((_t.getType() == RULE)) {
0659: rule(_t);
0660: _t = _retTree;
0661: } else {
0662: if (_cnt38 >= 1) {
0663: break _loop38;
0664: } else {
0665: throw new NoViableAltException(_t);
0666: }
0667: }
0668:
0669: _cnt38++;
0670: } while (true);
0671: }
0672: } catch (RecognitionException ex) {
0673: reportError(ex);
0674: if (_t != null) {
0675: _t = _t.getNextSibling();
0676: }
0677: }
0678: _retTree = _t;
0679: }
0680:
0681: public final void option(AST _t, Map opts)
0682: throws RecognitionException {
0683:
0684: GrammarAST option_AST_in = (_t == ASTNULL) ? null
0685: : (GrammarAST) _t;
0686: GrammarAST id = null;
0687:
0688: String key = null;
0689: Object value = null;
0690:
0691: try { // for error handling
0692: AST __t22 = _t;
0693: GrammarAST tmp11_AST_in = (GrammarAST) _t;
0694: match(_t, ASSIGN);
0695: _t = _t.getFirstChild();
0696: id = (GrammarAST) _t;
0697: match(_t, ID);
0698: _t = _t.getNextSibling();
0699: key = id.getText();
0700: value = optionValue(_t);
0701: _t = _retTree;
0702: _t = __t22;
0703: _t = _t.getNextSibling();
0704:
0705: opts.put(key, value);
0706: // check for grammar-level option to import vocabulary
0707: if (currentRuleName == null && key.equals("tokenVocab")) {
0708: grammar.importTokenVocabulary((String) value);
0709: }
0710:
0711: } catch (RecognitionException ex) {
0712: reportError(ex);
0713: if (_t != null) {
0714: _t = _t.getNextSibling();
0715: }
0716: }
0717: _retTree = _t;
0718: }
0719:
0720: public final Object optionValue(AST _t) throws RecognitionException {
0721: Object value = null;
0722:
0723: GrammarAST optionValue_AST_in = (_t == ASTNULL) ? null
0724: : (GrammarAST) _t;
0725: GrammarAST id = null;
0726: GrammarAST s = null;
0727: GrammarAST c = null;
0728: GrammarAST i = null;
0729:
0730: try { // for error handling
0731: if (_t == null)
0732: _t = ASTNULL;
0733: switch (_t.getType()) {
0734: case ID: {
0735: id = (GrammarAST) _t;
0736: match(_t, ID);
0737: _t = _t.getNextSibling();
0738: value = id.getText();
0739: break;
0740: }
0741: case STRING_LITERAL: {
0742: s = (GrammarAST) _t;
0743: match(_t, STRING_LITERAL);
0744: _t = _t.getNextSibling();
0745: value = s.getText();
0746: break;
0747: }
0748: case CHAR_LITERAL: {
0749: c = (GrammarAST) _t;
0750: match(_t, CHAR_LITERAL);
0751: _t = _t.getNextSibling();
0752: value = c.getText();
0753: break;
0754: }
0755: case INT: {
0756: i = (GrammarAST) _t;
0757: match(_t, INT);
0758: _t = _t.getNextSibling();
0759: value = new Integer(i.getText());
0760: break;
0761: }
0762: default: {
0763: throw new NoViableAltException(_t);
0764: }
0765: }
0766: } catch (RecognitionException ex) {
0767: reportError(ex);
0768: if (_t != null) {
0769: _t = _t.getNextSibling();
0770: }
0771: }
0772: _retTree = _t;
0773: return value;
0774: }
0775:
0776: public final void charSet(AST _t) throws RecognitionException {
0777:
0778: GrammarAST charSet_AST_in = (_t == ASTNULL) ? null
0779: : (GrammarAST) _t;
0780:
0781: try { // for error handling
0782: AST __t25 = _t;
0783: GrammarAST tmp12_AST_in = (GrammarAST) _t;
0784: match(_t, CHARSET);
0785: _t = _t.getFirstChild();
0786: charSetElement(_t);
0787: _t = _retTree;
0788: _t = __t25;
0789: _t = _t.getNextSibling();
0790: } catch (RecognitionException ex) {
0791: reportError(ex);
0792: if (_t != null) {
0793: _t = _t.getNextSibling();
0794: }
0795: }
0796: _retTree = _t;
0797: }
0798:
0799: public final void charSetElement(AST _t)
0800: throws RecognitionException {
0801:
0802: GrammarAST charSetElement_AST_in = (_t == ASTNULL) ? null
0803: : (GrammarAST) _t;
0804: GrammarAST c = null;
0805: GrammarAST c1 = null;
0806: GrammarAST c2 = null;
0807: GrammarAST c3 = null;
0808: GrammarAST c4 = null;
0809:
0810: try { // for error handling
0811: if (_t == null)
0812: _t = ASTNULL;
0813: switch (_t.getType()) {
0814: case CHAR_LITERAL: {
0815: c = (GrammarAST) _t;
0816: match(_t, CHAR_LITERAL);
0817: _t = _t.getNextSibling();
0818: break;
0819: }
0820: case OR: {
0821: AST __t27 = _t;
0822: GrammarAST tmp13_AST_in = (GrammarAST) _t;
0823: match(_t, OR);
0824: _t = _t.getFirstChild();
0825: c1 = (GrammarAST) _t;
0826: match(_t, CHAR_LITERAL);
0827: _t = _t.getNextSibling();
0828: c2 = (GrammarAST) _t;
0829: match(_t, CHAR_LITERAL);
0830: _t = _t.getNextSibling();
0831: _t = __t27;
0832: _t = _t.getNextSibling();
0833: break;
0834: }
0835: case RANGE: {
0836: AST __t28 = _t;
0837: GrammarAST tmp14_AST_in = (GrammarAST) _t;
0838: match(_t, RANGE);
0839: _t = _t.getFirstChild();
0840: c3 = (GrammarAST) _t;
0841: match(_t, CHAR_LITERAL);
0842: _t = _t.getNextSibling();
0843: c4 = (GrammarAST) _t;
0844: match(_t, CHAR_LITERAL);
0845: _t = _t.getNextSibling();
0846: _t = __t28;
0847: _t = _t.getNextSibling();
0848: break;
0849: }
0850: default: {
0851: throw new NoViableAltException(_t);
0852: }
0853: }
0854: } catch (RecognitionException ex) {
0855: reportError(ex);
0856: if (_t != null) {
0857: _t = _t.getNextSibling();
0858: }
0859: }
0860: _retTree = _t;
0861: }
0862:
0863: public final void tokenSpec(AST _t) throws RecognitionException {
0864:
0865: GrammarAST tokenSpec_AST_in = (_t == ASTNULL) ? null
0866: : (GrammarAST) _t;
0867: GrammarAST t = null;
0868: GrammarAST t2 = null;
0869: GrammarAST s = null;
0870: GrammarAST c = null;
0871:
0872: try { // for error handling
0873: if (_t == null)
0874: _t = ASTNULL;
0875: switch (_t.getType()) {
0876: case TOKEN_REF: {
0877: t = (GrammarAST) _t;
0878: match(_t, TOKEN_REF);
0879: _t = _t.getNextSibling();
0880: trackToken(t);
0881: break;
0882: }
0883: case ASSIGN: {
0884: AST __t34 = _t;
0885: GrammarAST tmp15_AST_in = (GrammarAST) _t;
0886: match(_t, ASSIGN);
0887: _t = _t.getFirstChild();
0888: t2 = (GrammarAST) _t;
0889: match(_t, TOKEN_REF);
0890: _t = _t.getNextSibling();
0891: trackToken(t2);
0892: {
0893: if (_t == null)
0894: _t = ASTNULL;
0895: switch (_t.getType()) {
0896: case STRING_LITERAL: {
0897: s = (GrammarAST) _t;
0898: match(_t, STRING_LITERAL);
0899: _t = _t.getNextSibling();
0900: trackString(s);
0901: alias(t2, s);
0902: break;
0903: }
0904: case CHAR_LITERAL: {
0905: c = (GrammarAST) _t;
0906: match(_t, CHAR_LITERAL);
0907: _t = _t.getNextSibling();
0908: trackString(c);
0909: alias(t2, c);
0910: break;
0911: }
0912: default: {
0913: throw new NoViableAltException(_t);
0914: }
0915: }
0916: }
0917: _t = __t34;
0918: _t = _t.getNextSibling();
0919: break;
0920: }
0921: default: {
0922: throw new NoViableAltException(_t);
0923: }
0924: }
0925: } catch (RecognitionException ex) {
0926: reportError(ex);
0927: if (_t != null) {
0928: _t = _t.getNextSibling();
0929: }
0930: }
0931: _retTree = _t;
0932: }
0933:
0934: public final void rule(AST _t) throws RecognitionException {
0935:
0936: GrammarAST rule_AST_in = (_t == ASTNULL) ? null
0937: : (GrammarAST) _t;
0938: GrammarAST id = null;
0939: GrammarAST m = null;
0940: GrammarAST b = null;
0941:
0942: try { // for error handling
0943: AST __t40 = _t;
0944: GrammarAST tmp16_AST_in = (GrammarAST) _t;
0945: match(_t, RULE);
0946: _t = _t.getFirstChild();
0947: id = (GrammarAST) _t;
0948: match(_t, ID);
0949: _t = _t.getNextSibling();
0950: currentRuleName = id.getText();
0951: {
0952: if (_t == null)
0953: _t = ASTNULL;
0954: switch (_t.getType()) {
0955: case FRAGMENT:
0956: case LITERAL_protected:
0957: case LITERAL_public:
0958: case LITERAL_private: {
0959: m = _t == ASTNULL ? null : (GrammarAST) _t;
0960: modifier(_t);
0961: _t = _retTree;
0962: break;
0963: }
0964: case ARG: {
0965: break;
0966: }
0967: default: {
0968: throw new NoViableAltException(_t);
0969: }
0970: }
0971: }
0972: {
0973: GrammarAST tmp17_AST_in = (GrammarAST) _t;
0974: match(_t, ARG);
0975: _t = _t.getNextSibling();
0976: {
0977: if (_t == null)
0978: _t = ASTNULL;
0979: switch (_t.getType()) {
0980: case ARG_ACTION: {
0981: GrammarAST tmp18_AST_in = (GrammarAST) _t;
0982: match(_t, ARG_ACTION);
0983: _t = _t.getNextSibling();
0984: break;
0985: }
0986: case RET: {
0987: break;
0988: }
0989: default: {
0990: throw new NoViableAltException(_t);
0991: }
0992: }
0993: }
0994: }
0995: {
0996: GrammarAST tmp19_AST_in = (GrammarAST) _t;
0997: match(_t, RET);
0998: _t = _t.getNextSibling();
0999: {
1000: if (_t == null)
1001: _t = ASTNULL;
1002: switch (_t.getType()) {
1003: case ARG_ACTION: {
1004: GrammarAST tmp20_AST_in = (GrammarAST) _t;
1005: match(_t, ARG_ACTION);
1006: _t = _t.getNextSibling();
1007: break;
1008: }
1009: case OPTIONS:
1010: case BLOCK:
1011: case SCOPE:
1012: case AMPERSAND: {
1013: break;
1014: }
1015: default: {
1016: throw new NoViableAltException(_t);
1017: }
1018: }
1019: }
1020: }
1021: {
1022: if (_t == null)
1023: _t = ASTNULL;
1024: switch (_t.getType()) {
1025: case OPTIONS: {
1026: optionsSpec(_t);
1027: _t = _retTree;
1028: break;
1029: }
1030: case BLOCK:
1031: case SCOPE:
1032: case AMPERSAND: {
1033: break;
1034: }
1035: default: {
1036: throw new NoViableAltException(_t);
1037: }
1038: }
1039: }
1040: {
1041: if (_t == null)
1042: _t = ASTNULL;
1043: switch (_t.getType()) {
1044: case SCOPE: {
1045: ruleScopeSpec(_t);
1046: _t = _retTree;
1047: break;
1048: }
1049: case BLOCK:
1050: case AMPERSAND: {
1051: break;
1052: }
1053: default: {
1054: throw new NoViableAltException(_t);
1055: }
1056: }
1057: }
1058: {
1059: _loop49: do {
1060: if (_t == null)
1061: _t = ASTNULL;
1062: if ((_t.getType() == AMPERSAND)) {
1063: GrammarAST tmp21_AST_in = (GrammarAST) _t;
1064: match(_t, AMPERSAND);
1065: _t = _t.getNextSibling();
1066: } else {
1067: break _loop49;
1068: }
1069:
1070: } while (true);
1071: }
1072: b = _t == ASTNULL ? null : (GrammarAST) _t;
1073: block(_t);
1074: _t = _retTree;
1075: {
1076: if (_t == null)
1077: _t = ASTNULL;
1078: switch (_t.getType()) {
1079: case LITERAL_catch:
1080: case LITERAL_finally: {
1081: exceptionGroup(_t);
1082: _t = _retTree;
1083: break;
1084: }
1085: case EOR: {
1086: break;
1087: }
1088: default: {
1089: throw new NoViableAltException(_t);
1090: }
1091: }
1092: }
1093: GrammarAST tmp22_AST_in = (GrammarAST) _t;
1094: match(_t, EOR);
1095: _t = _t.getNextSibling();
1096: trackTokenRule(id, m, b);
1097: _t = __t40;
1098: _t = _t.getNextSibling();
1099: } catch (RecognitionException ex) {
1100: reportError(ex);
1101: if (_t != null) {
1102: _t = _t.getNextSibling();
1103: }
1104: }
1105: _retTree = _t;
1106: }
1107:
1108: public final void modifier(AST _t) throws RecognitionException {
1109:
1110: GrammarAST modifier_AST_in = (_t == ASTNULL) ? null
1111: : (GrammarAST) _t;
1112:
1113: try { // for error handling
1114: if (_t == null)
1115: _t = ASTNULL;
1116: switch (_t.getType()) {
1117: case LITERAL_protected: {
1118: GrammarAST tmp23_AST_in = (GrammarAST) _t;
1119: match(_t, LITERAL_protected);
1120: _t = _t.getNextSibling();
1121: break;
1122: }
1123: case LITERAL_public: {
1124: GrammarAST tmp24_AST_in = (GrammarAST) _t;
1125: match(_t, LITERAL_public);
1126: _t = _t.getNextSibling();
1127: break;
1128: }
1129: case LITERAL_private: {
1130: GrammarAST tmp25_AST_in = (GrammarAST) _t;
1131: match(_t, LITERAL_private);
1132: _t = _t.getNextSibling();
1133: break;
1134: }
1135: case FRAGMENT: {
1136: GrammarAST tmp26_AST_in = (GrammarAST) _t;
1137: match(_t, FRAGMENT);
1138: _t = _t.getNextSibling();
1139: break;
1140: }
1141: default: {
1142: throw new NoViableAltException(_t);
1143: }
1144: }
1145: } catch (RecognitionException ex) {
1146: reportError(ex);
1147: if (_t != null) {
1148: _t = _t.getNextSibling();
1149: }
1150: }
1151: _retTree = _t;
1152: }
1153:
1154: public final void ruleScopeSpec(AST _t) throws RecognitionException {
1155:
1156: GrammarAST ruleScopeSpec_AST_in = (_t == ASTNULL) ? null
1157: : (GrammarAST) _t;
1158:
1159: try { // for error handling
1160: AST __t53 = _t;
1161: GrammarAST tmp27_AST_in = (GrammarAST) _t;
1162: match(_t, SCOPE);
1163: _t = _t.getFirstChild();
1164: {
1165: if (_t == null)
1166: _t = ASTNULL;
1167: switch (_t.getType()) {
1168: case ACTION: {
1169: GrammarAST tmp28_AST_in = (GrammarAST) _t;
1170: match(_t, ACTION);
1171: _t = _t.getNextSibling();
1172: break;
1173: }
1174: case 3:
1175: case ID: {
1176: break;
1177: }
1178: default: {
1179: throw new NoViableAltException(_t);
1180: }
1181: }
1182: }
1183: {
1184: _loop56: do {
1185: if (_t == null)
1186: _t = ASTNULL;
1187: if ((_t.getType() == ID)) {
1188: GrammarAST tmp29_AST_in = (GrammarAST) _t;
1189: match(_t, ID);
1190: _t = _t.getNextSibling();
1191: } else {
1192: break _loop56;
1193: }
1194:
1195: } while (true);
1196: }
1197: _t = __t53;
1198: _t = _t.getNextSibling();
1199: } catch (RecognitionException ex) {
1200: reportError(ex);
1201: if (_t != null) {
1202: _t = _t.getNextSibling();
1203: }
1204: }
1205: _retTree = _t;
1206: }
1207:
1208: public final void block(AST _t) throws RecognitionException {
1209:
1210: GrammarAST block_AST_in = (_t == ASTNULL) ? null
1211: : (GrammarAST) _t;
1212:
1213: try { // for error handling
1214: AST __t58 = _t;
1215: GrammarAST tmp30_AST_in = (GrammarAST) _t;
1216: match(_t, BLOCK);
1217: _t = _t.getFirstChild();
1218: {
1219: if (_t == null)
1220: _t = ASTNULL;
1221: switch (_t.getType()) {
1222: case OPTIONS: {
1223: optionsSpec(_t);
1224: _t = _retTree;
1225: break;
1226: }
1227: case ALT: {
1228: break;
1229: }
1230: default: {
1231: throw new NoViableAltException(_t);
1232: }
1233: }
1234: }
1235: {
1236: int _cnt61 = 0;
1237: _loop61: do {
1238: if (_t == null)
1239: _t = ASTNULL;
1240: if ((_t.getType() == ALT)) {
1241: alternative(_t);
1242: _t = _retTree;
1243: rewrite(_t);
1244: _t = _retTree;
1245: } else {
1246: if (_cnt61 >= 1) {
1247: break _loop61;
1248: } else {
1249: throw new NoViableAltException(_t);
1250: }
1251: }
1252:
1253: _cnt61++;
1254: } while (true);
1255: }
1256: GrammarAST tmp31_AST_in = (GrammarAST) _t;
1257: match(_t, EOB);
1258: _t = _t.getNextSibling();
1259: _t = __t58;
1260: _t = _t.getNextSibling();
1261: } catch (RecognitionException ex) {
1262: reportError(ex);
1263: if (_t != null) {
1264: _t = _t.getNextSibling();
1265: }
1266: }
1267: _retTree = _t;
1268: }
1269:
1270: public final void exceptionGroup(AST _t)
1271: throws RecognitionException {
1272:
1273: GrammarAST exceptionGroup_AST_in = (_t == ASTNULL) ? null
1274: : (GrammarAST) _t;
1275:
1276: try { // for error handling
1277: if (_t == null)
1278: _t = ASTNULL;
1279: switch (_t.getType()) {
1280: case LITERAL_catch: {
1281: {
1282: int _cnt68 = 0;
1283: _loop68: do {
1284: if (_t == null)
1285: _t = ASTNULL;
1286: if ((_t.getType() == LITERAL_catch)) {
1287: exceptionHandler(_t);
1288: _t = _retTree;
1289: } else {
1290: if (_cnt68 >= 1) {
1291: break _loop68;
1292: } else {
1293: throw new NoViableAltException(_t);
1294: }
1295: }
1296:
1297: _cnt68++;
1298: } while (true);
1299: }
1300: {
1301: if (_t == null)
1302: _t = ASTNULL;
1303: switch (_t.getType()) {
1304: case LITERAL_finally: {
1305: finallyClause(_t);
1306: _t = _retTree;
1307: break;
1308: }
1309: case EOR: {
1310: break;
1311: }
1312: default: {
1313: throw new NoViableAltException(_t);
1314: }
1315: }
1316: }
1317: break;
1318: }
1319: case LITERAL_finally: {
1320: finallyClause(_t);
1321: _t = _retTree;
1322: break;
1323: }
1324: default: {
1325: throw new NoViableAltException(_t);
1326: }
1327: }
1328: } catch (RecognitionException ex) {
1329: reportError(ex);
1330: if (_t != null) {
1331: _t = _t.getNextSibling();
1332: }
1333: }
1334: _retTree = _t;
1335: }
1336:
1337: public final void alternative(AST _t) throws RecognitionException {
1338:
1339: GrammarAST alternative_AST_in = (_t == ASTNULL) ? null
1340: : (GrammarAST) _t;
1341:
1342: try { // for error handling
1343: AST __t63 = _t;
1344: GrammarAST tmp32_AST_in = (GrammarAST) _t;
1345: match(_t, ALT);
1346: _t = _t.getFirstChild();
1347: {
1348: int _cnt65 = 0;
1349: _loop65: do {
1350: if (_t == null)
1351: _t = ASTNULL;
1352: if ((_t.getType() == BLOCK
1353: || _t.getType() == OPTIONAL
1354: || _t.getType() == CLOSURE
1355: || _t.getType() == POSITIVE_CLOSURE
1356: || _t.getType() == SYNPRED
1357: || _t.getType() == RANGE
1358: || _t.getType() == CHAR_RANGE
1359: || _t.getType() == EPSILON
1360: || _t.getType() == GATED_SEMPRED
1361: || _t.getType() == SYN_SEMPRED
1362: || _t.getType() == BACKTRACK_SEMPRED
1363: || _t.getType() == ACTION
1364: || _t.getType() == ASSIGN
1365: || _t.getType() == STRING_LITERAL
1366: || _t.getType() == CHAR_LITERAL
1367: || _t.getType() == TOKEN_REF
1368: || _t.getType() == BANG
1369: || _t.getType() == PLUS_ASSIGN
1370: || _t.getType() == SEMPRED
1371: || _t.getType() == ROOT
1372: || _t.getType() == RULE_REF
1373: || _t.getType() == NOT
1374: || _t.getType() == TREE_BEGIN || _t
1375: .getType() == WILDCARD)) {
1376: element(_t);
1377: _t = _retTree;
1378: } else {
1379: if (_cnt65 >= 1) {
1380: break _loop65;
1381: } else {
1382: throw new NoViableAltException(_t);
1383: }
1384: }
1385:
1386: _cnt65++;
1387: } while (true);
1388: }
1389: GrammarAST tmp33_AST_in = (GrammarAST) _t;
1390: match(_t, EOA);
1391: _t = _t.getNextSibling();
1392: _t = __t63;
1393: _t = _t.getNextSibling();
1394: } catch (RecognitionException ex) {
1395: reportError(ex);
1396: if (_t != null) {
1397: _t = _t.getNextSibling();
1398: }
1399: }
1400: _retTree = _t;
1401: }
1402:
1403: public final void rewrite(AST _t) throws RecognitionException {
1404:
1405: GrammarAST rewrite_AST_in = (_t == ASTNULL) ? null
1406: : (GrammarAST) _t;
1407:
1408: try { // for error handling
1409: {
1410: _loop79: do {
1411: if (_t == null)
1412: _t = ASTNULL;
1413: if ((_t.getType() == REWRITE)) {
1414: AST __t76 = _t;
1415: GrammarAST tmp34_AST_in = (GrammarAST) _t;
1416: match(_t, REWRITE);
1417: _t = _t.getFirstChild();
1418: {
1419: if (_t == null)
1420: _t = ASTNULL;
1421: switch (_t.getType()) {
1422: case SEMPRED: {
1423: GrammarAST tmp35_AST_in = (GrammarAST) _t;
1424: match(_t, SEMPRED);
1425: _t = _t.getNextSibling();
1426: break;
1427: }
1428: case ALT:
1429: case TEMPLATE:
1430: case ACTION: {
1431: break;
1432: }
1433: default: {
1434: throw new NoViableAltException(_t);
1435: }
1436: }
1437: }
1438: {
1439: if (_t == null)
1440: _t = ASTNULL;
1441: switch (_t.getType()) {
1442: case ALT: {
1443: GrammarAST tmp36_AST_in = (GrammarAST) _t;
1444: match(_t, ALT);
1445: _t = _t.getNextSibling();
1446: break;
1447: }
1448: case TEMPLATE: {
1449: GrammarAST tmp37_AST_in = (GrammarAST) _t;
1450: match(_t, TEMPLATE);
1451: _t = _t.getNextSibling();
1452: break;
1453: }
1454: case ACTION: {
1455: GrammarAST tmp38_AST_in = (GrammarAST) _t;
1456: match(_t, ACTION);
1457: _t = _t.getNextSibling();
1458: break;
1459: }
1460: default: {
1461: throw new NoViableAltException(_t);
1462: }
1463: }
1464: }
1465: _t = __t76;
1466: _t = _t.getNextSibling();
1467: } else {
1468: break _loop79;
1469: }
1470:
1471: } while (true);
1472: }
1473: } catch (RecognitionException ex) {
1474: reportError(ex);
1475: if (_t != null) {
1476: _t = _t.getNextSibling();
1477: }
1478: }
1479: _retTree = _t;
1480: }
1481:
1482: public final void element(AST _t) throws RecognitionException {
1483:
1484: GrammarAST element_AST_in = (_t == ASTNULL) ? null
1485: : (GrammarAST) _t;
1486:
1487: try { // for error handling
1488: if (_t == null)
1489: _t = ASTNULL;
1490: switch (_t.getType()) {
1491: case ROOT: {
1492: AST __t81 = _t;
1493: GrammarAST tmp39_AST_in = (GrammarAST) _t;
1494: match(_t, ROOT);
1495: _t = _t.getFirstChild();
1496: element(_t);
1497: _t = _retTree;
1498: _t = __t81;
1499: _t = _t.getNextSibling();
1500: break;
1501: }
1502: case BANG: {
1503: AST __t82 = _t;
1504: GrammarAST tmp40_AST_in = (GrammarAST) _t;
1505: match(_t, BANG);
1506: _t = _t.getFirstChild();
1507: element(_t);
1508: _t = _retTree;
1509: _t = __t82;
1510: _t = _t.getNextSibling();
1511: break;
1512: }
1513: case STRING_LITERAL:
1514: case CHAR_LITERAL:
1515: case TOKEN_REF:
1516: case RULE_REF:
1517: case WILDCARD: {
1518: atom(_t);
1519: _t = _retTree;
1520: break;
1521: }
1522: case NOT: {
1523: AST __t83 = _t;
1524: GrammarAST tmp41_AST_in = (GrammarAST) _t;
1525: match(_t, NOT);
1526: _t = _t.getFirstChild();
1527: element(_t);
1528: _t = _retTree;
1529: _t = __t83;
1530: _t = _t.getNextSibling();
1531: break;
1532: }
1533: case RANGE: {
1534: AST __t84 = _t;
1535: GrammarAST tmp42_AST_in = (GrammarAST) _t;
1536: match(_t, RANGE);
1537: _t = _t.getFirstChild();
1538: atom(_t);
1539: _t = _retTree;
1540: atom(_t);
1541: _t = _retTree;
1542: _t = __t84;
1543: _t = _t.getNextSibling();
1544: break;
1545: }
1546: case CHAR_RANGE: {
1547: AST __t85 = _t;
1548: GrammarAST tmp43_AST_in = (GrammarAST) _t;
1549: match(_t, CHAR_RANGE);
1550: _t = _t.getFirstChild();
1551: atom(_t);
1552: _t = _retTree;
1553: atom(_t);
1554: _t = _retTree;
1555: _t = __t85;
1556: _t = _t.getNextSibling();
1557: break;
1558: }
1559: case ASSIGN: {
1560: AST __t86 = _t;
1561: GrammarAST tmp44_AST_in = (GrammarAST) _t;
1562: match(_t, ASSIGN);
1563: _t = _t.getFirstChild();
1564: GrammarAST tmp45_AST_in = (GrammarAST) _t;
1565: match(_t, ID);
1566: _t = _t.getNextSibling();
1567: element(_t);
1568: _t = _retTree;
1569: _t = __t86;
1570: _t = _t.getNextSibling();
1571: break;
1572: }
1573: case PLUS_ASSIGN: {
1574: AST __t87 = _t;
1575: GrammarAST tmp46_AST_in = (GrammarAST) _t;
1576: match(_t, PLUS_ASSIGN);
1577: _t = _t.getFirstChild();
1578: GrammarAST tmp47_AST_in = (GrammarAST) _t;
1579: match(_t, ID);
1580: _t = _t.getNextSibling();
1581: element(_t);
1582: _t = _retTree;
1583: _t = __t87;
1584: _t = _t.getNextSibling();
1585: break;
1586: }
1587: case BLOCK:
1588: case OPTIONAL:
1589: case CLOSURE:
1590: case POSITIVE_CLOSURE: {
1591: ebnf(_t);
1592: _t = _retTree;
1593: break;
1594: }
1595: case TREE_BEGIN: {
1596: tree(_t);
1597: _t = _retTree;
1598: break;
1599: }
1600: case SYNPRED: {
1601: AST __t88 = _t;
1602: GrammarAST tmp48_AST_in = (GrammarAST) _t;
1603: match(_t, SYNPRED);
1604: _t = _t.getFirstChild();
1605: block(_t);
1606: _t = _retTree;
1607: _t = __t88;
1608: _t = _t.getNextSibling();
1609: break;
1610: }
1611: case ACTION: {
1612: GrammarAST tmp49_AST_in = (GrammarAST) _t;
1613: match(_t, ACTION);
1614: _t = _t.getNextSibling();
1615: break;
1616: }
1617: case SEMPRED: {
1618: GrammarAST tmp50_AST_in = (GrammarAST) _t;
1619: match(_t, SEMPRED);
1620: _t = _t.getNextSibling();
1621: break;
1622: }
1623: case SYN_SEMPRED: {
1624: GrammarAST tmp51_AST_in = (GrammarAST) _t;
1625: match(_t, SYN_SEMPRED);
1626: _t = _t.getNextSibling();
1627: break;
1628: }
1629: case BACKTRACK_SEMPRED: {
1630: GrammarAST tmp52_AST_in = (GrammarAST) _t;
1631: match(_t, BACKTRACK_SEMPRED);
1632: _t = _t.getNextSibling();
1633: break;
1634: }
1635: case GATED_SEMPRED: {
1636: GrammarAST tmp53_AST_in = (GrammarAST) _t;
1637: match(_t, GATED_SEMPRED);
1638: _t = _t.getNextSibling();
1639: break;
1640: }
1641: case EPSILON: {
1642: GrammarAST tmp54_AST_in = (GrammarAST) _t;
1643: match(_t, EPSILON);
1644: _t = _t.getNextSibling();
1645: break;
1646: }
1647: default: {
1648: throw new NoViableAltException(_t);
1649: }
1650: }
1651: } catch (RecognitionException ex) {
1652: reportError(ex);
1653: if (_t != null) {
1654: _t = _t.getNextSibling();
1655: }
1656: }
1657: _retTree = _t;
1658: }
1659:
1660: public final void exceptionHandler(AST _t)
1661: throws RecognitionException {
1662:
1663: GrammarAST exceptionHandler_AST_in = (_t == ASTNULL) ? null
1664: : (GrammarAST) _t;
1665:
1666: try { // for error handling
1667: AST __t71 = _t;
1668: GrammarAST tmp55_AST_in = (GrammarAST) _t;
1669: match(_t, LITERAL_catch);
1670: _t = _t.getFirstChild();
1671: GrammarAST tmp56_AST_in = (GrammarAST) _t;
1672: match(_t, ARG_ACTION);
1673: _t = _t.getNextSibling();
1674: GrammarAST tmp57_AST_in = (GrammarAST) _t;
1675: match(_t, ACTION);
1676: _t = _t.getNextSibling();
1677: _t = __t71;
1678: _t = _t.getNextSibling();
1679: } catch (RecognitionException ex) {
1680: reportError(ex);
1681: if (_t != null) {
1682: _t = _t.getNextSibling();
1683: }
1684: }
1685: _retTree = _t;
1686: }
1687:
1688: public final void finallyClause(AST _t) throws RecognitionException {
1689:
1690: GrammarAST finallyClause_AST_in = (_t == ASTNULL) ? null
1691: : (GrammarAST) _t;
1692:
1693: try { // for error handling
1694: AST __t73 = _t;
1695: GrammarAST tmp58_AST_in = (GrammarAST) _t;
1696: match(_t, LITERAL_finally);
1697: _t = _t.getFirstChild();
1698: GrammarAST tmp59_AST_in = (GrammarAST) _t;
1699: match(_t, ACTION);
1700: _t = _t.getNextSibling();
1701: _t = __t73;
1702: _t = _t.getNextSibling();
1703: } catch (RecognitionException ex) {
1704: reportError(ex);
1705: if (_t != null) {
1706: _t = _t.getNextSibling();
1707: }
1708: }
1709: _retTree = _t;
1710: }
1711:
1712: public final void atom(AST _t) throws RecognitionException {
1713:
1714: GrammarAST atom_AST_in = (_t == ASTNULL) ? null
1715: : (GrammarAST) _t;
1716: GrammarAST t = null;
1717: GrammarAST c = null;
1718: GrammarAST s = null;
1719:
1720: try { // for error handling
1721: if (_t == null)
1722: _t = ASTNULL;
1723: switch (_t.getType()) {
1724: case RULE_REF: {
1725: GrammarAST tmp60_AST_in = (GrammarAST) _t;
1726: match(_t, RULE_REF);
1727: _t = _t.getNextSibling();
1728: break;
1729: }
1730: case TOKEN_REF: {
1731: t = (GrammarAST) _t;
1732: match(_t, TOKEN_REF);
1733: _t = _t.getNextSibling();
1734: trackToken(t);
1735: break;
1736: }
1737: case CHAR_LITERAL: {
1738: c = (GrammarAST) _t;
1739: match(_t, CHAR_LITERAL);
1740: _t = _t.getNextSibling();
1741: trackString(c);
1742: break;
1743: }
1744: case STRING_LITERAL: {
1745: s = (GrammarAST) _t;
1746: match(_t, STRING_LITERAL);
1747: _t = _t.getNextSibling();
1748: trackString(s);
1749: break;
1750: }
1751: case WILDCARD: {
1752: GrammarAST tmp61_AST_in = (GrammarAST) _t;
1753: match(_t, WILDCARD);
1754: _t = _t.getNextSibling();
1755: break;
1756: }
1757: default: {
1758: throw new NoViableAltException(_t);
1759: }
1760: }
1761: } catch (RecognitionException ex) {
1762: reportError(ex);
1763: if (_t != null) {
1764: _t = _t.getNextSibling();
1765: }
1766: }
1767: _retTree = _t;
1768: }
1769:
1770: public final void ebnf(AST _t) throws RecognitionException {
1771:
1772: GrammarAST ebnf_AST_in = (_t == ASTNULL) ? null
1773: : (GrammarAST) _t;
1774:
1775: try { // for error handling
1776: if (_t == null)
1777: _t = ASTNULL;
1778: switch (_t.getType()) {
1779: case BLOCK: {
1780: block(_t);
1781: _t = _retTree;
1782: break;
1783: }
1784: case OPTIONAL: {
1785: AST __t90 = _t;
1786: GrammarAST tmp62_AST_in = (GrammarAST) _t;
1787: match(_t, OPTIONAL);
1788: _t = _t.getFirstChild();
1789: block(_t);
1790: _t = _retTree;
1791: _t = __t90;
1792: _t = _t.getNextSibling();
1793: break;
1794: }
1795: case CLOSURE: {
1796: AST __t91 = _t;
1797: GrammarAST tmp63_AST_in = (GrammarAST) _t;
1798: match(_t, CLOSURE);
1799: _t = _t.getFirstChild();
1800: block(_t);
1801: _t = _retTree;
1802: _t = __t91;
1803: _t = _t.getNextSibling();
1804: break;
1805: }
1806: case POSITIVE_CLOSURE: {
1807: AST __t92 = _t;
1808: GrammarAST tmp64_AST_in = (GrammarAST) _t;
1809: match(_t, POSITIVE_CLOSURE);
1810: _t = _t.getFirstChild();
1811: block(_t);
1812: _t = _retTree;
1813: _t = __t92;
1814: _t = _t.getNextSibling();
1815: break;
1816: }
1817: default: {
1818: throw new NoViableAltException(_t);
1819: }
1820: }
1821: } catch (RecognitionException ex) {
1822: reportError(ex);
1823: if (_t != null) {
1824: _t = _t.getNextSibling();
1825: }
1826: }
1827: _retTree = _t;
1828: }
1829:
1830: public final void tree(AST _t) throws RecognitionException {
1831:
1832: GrammarAST tree_AST_in = (_t == ASTNULL) ? null
1833: : (GrammarAST) _t;
1834:
1835: try { // for error handling
1836: AST __t94 = _t;
1837: GrammarAST tmp65_AST_in = (GrammarAST) _t;
1838: match(_t, TREE_BEGIN);
1839: _t = _t.getFirstChild();
1840: element(_t);
1841: _t = _retTree;
1842: {
1843: _loop96: do {
1844: if (_t == null)
1845: _t = ASTNULL;
1846: if ((_t.getType() == BLOCK
1847: || _t.getType() == OPTIONAL
1848: || _t.getType() == CLOSURE
1849: || _t.getType() == POSITIVE_CLOSURE
1850: || _t.getType() == SYNPRED
1851: || _t.getType() == RANGE
1852: || _t.getType() == CHAR_RANGE
1853: || _t.getType() == EPSILON
1854: || _t.getType() == GATED_SEMPRED
1855: || _t.getType() == SYN_SEMPRED
1856: || _t.getType() == BACKTRACK_SEMPRED
1857: || _t.getType() == ACTION
1858: || _t.getType() == ASSIGN
1859: || _t.getType() == STRING_LITERAL
1860: || _t.getType() == CHAR_LITERAL
1861: || _t.getType() == TOKEN_REF
1862: || _t.getType() == BANG
1863: || _t.getType() == PLUS_ASSIGN
1864: || _t.getType() == SEMPRED
1865: || _t.getType() == ROOT
1866: || _t.getType() == RULE_REF
1867: || _t.getType() == NOT
1868: || _t.getType() == TREE_BEGIN || _t
1869: .getType() == WILDCARD)) {
1870: element(_t);
1871: _t = _retTree;
1872: } else {
1873: break _loop96;
1874: }
1875:
1876: } while (true);
1877: }
1878: _t = __t94;
1879: _t = _t.getNextSibling();
1880: } catch (RecognitionException ex) {
1881: reportError(ex);
1882: if (_t != null) {
1883: _t = _t.getNextSibling();
1884: }
1885: }
1886: _retTree = _t;
1887: }
1888:
1889: public final void ast_suffix(AST _t) throws RecognitionException {
1890:
1891: GrammarAST ast_suffix_AST_in = (_t == ASTNULL) ? null
1892: : (GrammarAST) _t;
1893:
1894: try { // for error handling
1895: if (_t == null)
1896: _t = ASTNULL;
1897: switch (_t.getType()) {
1898: case ROOT: {
1899: GrammarAST tmp66_AST_in = (GrammarAST) _t;
1900: match(_t, ROOT);
1901: _t = _t.getNextSibling();
1902: break;
1903: }
1904: case BANG: {
1905: GrammarAST tmp67_AST_in = (GrammarAST) _t;
1906: match(_t, BANG);
1907: _t = _t.getNextSibling();
1908: break;
1909: }
1910: default: {
1911: throw new NoViableAltException(_t);
1912: }
1913: }
1914: } catch (RecognitionException ex) {
1915: reportError(ex);
1916: if (_t != null) {
1917: _t = _t.getNextSibling();
1918: }
1919: }
1920: _retTree = _t;
1921: }
1922:
1923: public static final String[] _tokenNames = { "<0>", "EOF", "<2>",
1924: "NULL_TREE_LOOKAHEAD", "\"options\"", "\"tokens\"",
1925: "\"parser\"", "LEXER", "RULE", "BLOCK", "OPTIONAL",
1926: "CLOSURE", "POSITIVE_CLOSURE", "SYNPRED", "RANGE",
1927: "CHAR_RANGE", "EPSILON", "ALT", "EOR", "EOB", "EOA", "ID",
1928: "ARG", "ARGLIST", "RET", "LEXER_GRAMMAR", "PARSER_GRAMMAR",
1929: "TREE_GRAMMAR", "COMBINED_GRAMMAR", "INITACTION", "LABEL",
1930: "TEMPLATE", "\"scope\"", "GATED_SEMPRED", "SYN_SEMPRED",
1931: "BACKTRACK_SEMPRED", "\"fragment\"", "ACTION",
1932: "DOC_COMMENT", "SEMI", "\"lexer\"", "\"tree\"",
1933: "\"grammar\"", "AMPERSAND", "COLON", "RCURLY", "ASSIGN",
1934: "STRING_LITERAL", "CHAR_LITERAL", "INT", "STAR",
1935: "TOKEN_REF", "\"protected\"", "\"public\"", "\"private\"",
1936: "BANG", "ARG_ACTION", "\"returns\"", "\"throws\"", "COMMA",
1937: "LPAREN", "OR", "RPAREN", "\"catch\"", "\"finally\"",
1938: "PLUS_ASSIGN", "SEMPRED", "IMPLIES", "ROOT", "RULE_REF",
1939: "NOT", "TREE_BEGIN", "QUESTION", "PLUS", "WILDCARD",
1940: "REWRITE", "DOLLAR", "DOUBLE_QUOTE_STRING_LITERAL",
1941: "DOUBLE_ANGLE_STRING_LITERAL", "WS", "COMMENT",
1942: "SL_COMMENT", "ML_COMMENT", "OPEN_ELEMENT_OPTION",
1943: "CLOSE_ELEMENT_OPTION", "ESC", "DIGIT", "XDIGIT",
1944: "NESTED_ARG_ACTION", "NESTED_ACTION",
1945: "ACTION_CHAR_LITERAL", "ACTION_STRING_LITERAL",
1946: "ACTION_ESC", "WS_LOOP", "INTERNAL_RULE_REF", "WS_OPT",
1947: "SRC", "CHARSET" };
1948:
1949: }
|