Source Code Cross Referenced for DefineGrammarItemsWalker.java in  » Parser » antlr-3.0.1 » org » antlr » tool » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Parser » antlr 3.0.1 » org.antlr.tool 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        // $ANTLR 2.7.7 (2006-01-29): "define.g" -> "DefineGrammarItemsWalker.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.misc.*;
0034:
0035:        import antlr.TreeParser;
0036:        import antlr.Token;
0037:        import antlr.collections.AST;
0038:        import antlr.RecognitionException;
0039:        import antlr.ANTLRException;
0040:        import antlr.NoViableAltException;
0041:        import antlr.MismatchedTokenException;
0042:        import antlr.SemanticException;
0043:        import antlr.collections.impl.BitSet;
0044:        import antlr.ASTPair;
0045:        import antlr.collections.impl.ASTArray;
0046:
0047:        public class DefineGrammarItemsWalker extends antlr.TreeParser
0048:                implements  DefineGrammarItemsWalkerTokenTypes {
0049:
0050:            protected Grammar grammar;
0051:            protected GrammarAST root;
0052:            protected String currentRuleName;
0053:            protected GrammarAST currentRewriteBlock;
0054:            protected GrammarAST currentRewriteRule;
0055:            protected int outerAltNum = 0;
0056:            protected int blockLevel = 0;
0057:
0058:            public void reportError(RecognitionException ex) {
0059:                Token token = null;
0060:                if (ex instanceof  MismatchedTokenException) {
0061:                    token = ((MismatchedTokenException) ex).token;
0062:                } else if (ex instanceof  NoViableAltException) {
0063:                    token = ((NoViableAltException) ex).token;
0064:                }
0065:                ErrorManager.syntaxError(ErrorManager.MSG_SYNTAX_ERROR,
0066:                        grammar, token, "define: " + ex.toString(), ex);
0067:            }
0068:
0069:            protected void finish() {
0070:                trimGrammar();
0071:            }
0072:
0073:            /** Remove any lexer rules from a COMBINED; already passed to lexer */
0074:            protected void trimGrammar() {
0075:                if (grammar.type != Grammar.COMBINED) {
0076:                    return;
0077:                }
0078:                // form is (header ... ) ( grammar ID (scope ...) ... ( rule ... ) ( rule ... ) ... )
0079:                GrammarAST p = root;
0080:                // find the grammar spec
0081:                while (!p.getText().equals("grammar")) {
0082:                    p = (GrammarAST) p.getNextSibling();
0083:                }
0084:                p = (GrammarAST) p.getFirstChild(); // jump down to first child of grammar
0085:                // look for first RULE def
0086:                GrammarAST prev = p; // points to the ID (grammar name)
0087:                while (p.getType() != RULE) {
0088:                    prev = p;
0089:                    p = (GrammarAST) p.getNextSibling();
0090:                }
0091:                // prev points at last node before first rule subtree at this point
0092:                while (p != null) {
0093:                    String ruleName = p.getFirstChild().getText();
0094:                    //System.out.println("rule "+ruleName+" prev="+prev.getText());
0095:                    if (Character.isUpperCase(ruleName.charAt(0))) {
0096:                        // remove lexer rule
0097:                        prev.setNextSibling(p.getNextSibling());
0098:                    } else {
0099:                        prev = p; // non-lexer rule; move on
0100:                    }
0101:                    p = (GrammarAST) p.getNextSibling();
0102:                }
0103:                //System.out.println("root after removal is: "+root.toStringList());
0104:            }
0105:
0106:            protected void trackInlineAction(GrammarAST actionAST) {
0107:                Rule r = grammar.getRule(currentRuleName);
0108:                if (r != null) {
0109:                    r.trackInlineAction(actionAST);
0110:                }
0111:            }
0112:
0113:            public DefineGrammarItemsWalker() {
0114:                tokenNames = _tokenNames;
0115:            }
0116:
0117:            public final void grammar(AST _t, Grammar g)
0118:                    throws RecognitionException {
0119:
0120:                GrammarAST grammar_AST_in = (_t == ASTNULL) ? null
0121:                        : (GrammarAST) _t;
0122:
0123:                grammar = g;
0124:                root = grammar_AST_in;
0125:
0126:                try { // for error handling
0127:                    {
0128:                        if (_t == null)
0129:                            _t = ASTNULL;
0130:                        switch (_t.getType()) {
0131:                        case LEXER_GRAMMAR: {
0132:                            AST __t3 = _t;
0133:                            GrammarAST tmp1_AST_in = (GrammarAST) _t;
0134:                            match(_t, LEXER_GRAMMAR);
0135:                            _t = _t.getFirstChild();
0136:                            if (inputState.guessing == 0) {
0137:                                grammar.type = Grammar.LEXER;
0138:                            }
0139:                            grammarSpec(_t);
0140:                            _t = _retTree;
0141:                            _t = __t3;
0142:                            _t = _t.getNextSibling();
0143:                            break;
0144:                        }
0145:                        case PARSER_GRAMMAR: {
0146:                            AST __t4 = _t;
0147:                            GrammarAST tmp2_AST_in = (GrammarAST) _t;
0148:                            match(_t, PARSER_GRAMMAR);
0149:                            _t = _t.getFirstChild();
0150:                            if (inputState.guessing == 0) {
0151:                                grammar.type = Grammar.PARSER;
0152:                            }
0153:                            grammarSpec(_t);
0154:                            _t = _retTree;
0155:                            _t = __t4;
0156:                            _t = _t.getNextSibling();
0157:                            break;
0158:                        }
0159:                        case TREE_GRAMMAR: {
0160:                            AST __t5 = _t;
0161:                            GrammarAST tmp3_AST_in = (GrammarAST) _t;
0162:                            match(_t, TREE_GRAMMAR);
0163:                            _t = _t.getFirstChild();
0164:                            if (inputState.guessing == 0) {
0165:                                grammar.type = Grammar.TREE_PARSER;
0166:                            }
0167:                            grammarSpec(_t);
0168:                            _t = _retTree;
0169:                            _t = __t5;
0170:                            _t = _t.getNextSibling();
0171:                            break;
0172:                        }
0173:                        case COMBINED_GRAMMAR: {
0174:                            AST __t6 = _t;
0175:                            GrammarAST tmp4_AST_in = (GrammarAST) _t;
0176:                            match(_t, COMBINED_GRAMMAR);
0177:                            _t = _t.getFirstChild();
0178:                            if (inputState.guessing == 0) {
0179:                                grammar.type = Grammar.COMBINED;
0180:                            }
0181:                            grammarSpec(_t);
0182:                            _t = _retTree;
0183:                            _t = __t6;
0184:                            _t = _t.getNextSibling();
0185:                            break;
0186:                        }
0187:                        default: {
0188:                            throw new NoViableAltException(_t);
0189:                        }
0190:                        }
0191:                    }
0192:                    if (inputState.guessing == 0) {
0193:                        finish();
0194:                    }
0195:                } catch (RecognitionException ex) {
0196:                    if (inputState.guessing == 0) {
0197:                        reportError(ex);
0198:                        if (_t != null) {
0199:                            _t = _t.getNextSibling();
0200:                        }
0201:                    } else {
0202:                        throw ex;
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 id = null;
0213:                GrammarAST cmt = null;
0214:
0215:                Map opts = null;
0216:                Token optionsStartToken = null;
0217:
0218:                try { // for error handling
0219:                    id = (GrammarAST) _t;
0220:                    match(_t, ID);
0221:                    _t = _t.getNextSibling();
0222:                    {
0223:                        if (_t == null)
0224:                            _t = ASTNULL;
0225:                        switch (_t.getType()) {
0226:                        case DOC_COMMENT: {
0227:                            cmt = (GrammarAST) _t;
0228:                            match(_t, DOC_COMMENT);
0229:                            _t = _t.getNextSibling();
0230:                            break;
0231:                        }
0232:                        case OPTIONS:
0233:                        case TOKENS:
0234:                        case RULE:
0235:                        case SCOPE:
0236:                        case AMPERSAND: {
0237:                            break;
0238:                        }
0239:                        default: {
0240:                            throw new NoViableAltException(_t);
0241:                        }
0242:                        }
0243:                    }
0244:                    {
0245:                        if (_t == null)
0246:                            _t = ASTNULL;
0247:                        switch (_t.getType()) {
0248:                        case OPTIONS: {
0249:                            if (inputState.guessing == 0) {
0250:                                optionsStartToken = ((GrammarAST) _t)
0251:                                        .getToken();
0252:                            }
0253:                            optionsSpec(_t);
0254:                            _t = _retTree;
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:                            tokensSpec(_t);
0274:                            _t = _retTree;
0275:                            break;
0276:                        }
0277:                        case RULE:
0278:                        case SCOPE:
0279:                        case AMPERSAND: {
0280:                            break;
0281:                        }
0282:                        default: {
0283:                            throw new NoViableAltException(_t);
0284:                        }
0285:                        }
0286:                    }
0287:                    {
0288:                        _loop14: do {
0289:                            if (_t == null)
0290:                                _t = ASTNULL;
0291:                            if ((_t.getType() == SCOPE)) {
0292:                                attrScope(_t);
0293:                                _t = _retTree;
0294:                            } else {
0295:                                break _loop14;
0296:                            }
0297:
0298:                        } while (true);
0299:                    }
0300:                    {
0301:                        if (_t == null)
0302:                            _t = ASTNULL;
0303:                        switch (_t.getType()) {
0304:                        case AMPERSAND: {
0305:                            actions(_t);
0306:                            _t = _retTree;
0307:                            break;
0308:                        }
0309:                        case RULE: {
0310:                            break;
0311:                        }
0312:                        default: {
0313:                            throw new NoViableAltException(_t);
0314:                        }
0315:                        }
0316:                    }
0317:                    rules(_t);
0318:                    _t = _retTree;
0319:                } catch (RecognitionException ex) {
0320:                    if (inputState.guessing == 0) {
0321:                        reportError(ex);
0322:                        if (_t != null) {
0323:                            _t = _t.getNextSibling();
0324:                        }
0325:                    } else {
0326:                        throw ex;
0327:                    }
0328:                }
0329:                _retTree = _t;
0330:            }
0331:
0332:            public final void attrScope(AST _t) throws RecognitionException {
0333:
0334:                GrammarAST attrScope_AST_in = (_t == ASTNULL) ? null
0335:                        : (GrammarAST) _t;
0336:                GrammarAST name = null;
0337:                GrammarAST attrs = null;
0338:
0339:                try { // for error handling
0340:                    AST __t8 = _t;
0341:                    GrammarAST tmp5_AST_in = (GrammarAST) _t;
0342:                    match(_t, SCOPE);
0343:                    _t = _t.getFirstChild();
0344:                    name = (GrammarAST) _t;
0345:                    match(_t, ID);
0346:                    _t = _t.getNextSibling();
0347:                    attrs = (GrammarAST) _t;
0348:                    match(_t, ACTION);
0349:                    _t = _t.getNextSibling();
0350:                    _t = __t8;
0351:                    _t = _t.getNextSibling();
0352:                    if (inputState.guessing == 0) {
0353:
0354:                        AttributeScope scope = grammar.defineGlobalScope(name
0355:                                .getText(), attrs.token);
0356:                        scope.isDynamicGlobalScope = true;
0357:                        scope.addAttributes(attrs.getText(), ";");
0358:
0359:                    }
0360:                } catch (RecognitionException ex) {
0361:                    if (inputState.guessing == 0) {
0362:                        reportError(ex);
0363:                        if (_t != null) {
0364:                            _t = _t.getNextSibling();
0365:                        }
0366:                    } else {
0367:                        throw ex;
0368:                    }
0369:                }
0370:                _retTree = _t;
0371:            }
0372:
0373:            public final void optionsSpec(AST _t) throws RecognitionException {
0374:
0375:                GrammarAST optionsSpec_AST_in = (_t == ASTNULL) ? null
0376:                        : (GrammarAST) _t;
0377:
0378:                try { // for error handling
0379:                    GrammarAST tmp6_AST_in = (GrammarAST) _t;
0380:                    match(_t, OPTIONS);
0381:                    _t = _t.getNextSibling();
0382:                } catch (RecognitionException ex) {
0383:                    if (inputState.guessing == 0) {
0384:                        reportError(ex);
0385:                        if (_t != null) {
0386:                            _t = _t.getNextSibling();
0387:                        }
0388:                    } else {
0389:                        throw ex;
0390:                    }
0391:                }
0392:                _retTree = _t;
0393:            }
0394:
0395:            public final void tokensSpec(AST _t) throws RecognitionException {
0396:
0397:                GrammarAST tokensSpec_AST_in = (_t == ASTNULL) ? null
0398:                        : (GrammarAST) _t;
0399:
0400:                try { // for error handling
0401:                    AST __t24 = _t;
0402:                    GrammarAST tmp7_AST_in = (GrammarAST) _t;
0403:                    match(_t, TOKENS);
0404:                    _t = _t.getFirstChild();
0405:                    {
0406:                        int _cnt26 = 0;
0407:                        _loop26: do {
0408:                            if (_t == null)
0409:                                _t = ASTNULL;
0410:                            if ((_t.getType() == ASSIGN || _t.getType() == TOKEN_REF)) {
0411:                                tokenSpec(_t);
0412:                                _t = _retTree;
0413:                            } else {
0414:                                if (_cnt26 >= 1) {
0415:                                    break _loop26;
0416:                                } else {
0417:                                    throw new NoViableAltException(_t);
0418:                                }
0419:                            }
0420:
0421:                            _cnt26++;
0422:                        } while (true);
0423:                    }
0424:                    _t = __t24;
0425:                    _t = _t.getNextSibling();
0426:                } catch (RecognitionException ex) {
0427:                    if (inputState.guessing == 0) {
0428:                        reportError(ex);
0429:                        if (_t != null) {
0430:                            _t = _t.getNextSibling();
0431:                        }
0432:                    } else {
0433:                        throw ex;
0434:                    }
0435:                }
0436:                _retTree = _t;
0437:            }
0438:
0439:            public final void actions(AST _t) throws RecognitionException {
0440:
0441:                GrammarAST actions_AST_in = (_t == ASTNULL) ? null
0442:                        : (GrammarAST) _t;
0443:
0444:                try { // for error handling
0445:                    {
0446:                        int _cnt18 = 0;
0447:                        _loop18: do {
0448:                            if (_t == null)
0449:                                _t = ASTNULL;
0450:                            if ((_t.getType() == AMPERSAND)) {
0451:                                action(_t);
0452:                                _t = _retTree;
0453:                            } else {
0454:                                if (_cnt18 >= 1) {
0455:                                    break _loop18;
0456:                                } else {
0457:                                    throw new NoViableAltException(_t);
0458:                                }
0459:                            }
0460:
0461:                            _cnt18++;
0462:                        } while (true);
0463:                    }
0464:                } catch (RecognitionException ex) {
0465:                    if (inputState.guessing == 0) {
0466:                        reportError(ex);
0467:                        if (_t != null) {
0468:                            _t = _t.getNextSibling();
0469:                        }
0470:                    } else {
0471:                        throw ex;
0472:                    }
0473:                }
0474:                _retTree = _t;
0475:            }
0476:
0477:            public final void rules(AST _t) throws RecognitionException {
0478:
0479:                GrammarAST rules_AST_in = (_t == ASTNULL) ? null
0480:                        : (GrammarAST) _t;
0481:
0482:                try { // for error handling
0483:                    {
0484:                        int _cnt32 = 0;
0485:                        _loop32: do {
0486:                            if (_t == null)
0487:                                _t = ASTNULL;
0488:                            if ((_t.getType() == RULE)) {
0489:                                rule(_t);
0490:                                _t = _retTree;
0491:                            } else {
0492:                                if (_cnt32 >= 1) {
0493:                                    break _loop32;
0494:                                } else {
0495:                                    throw new NoViableAltException(_t);
0496:                                }
0497:                            }
0498:
0499:                            _cnt32++;
0500:                        } while (true);
0501:                    }
0502:                } catch (RecognitionException ex) {
0503:                    if (inputState.guessing == 0) {
0504:                        reportError(ex);
0505:                        if (_t != null) {
0506:                            _t = _t.getNextSibling();
0507:                        }
0508:                    } else {
0509:                        throw ex;
0510:                    }
0511:                }
0512:                _retTree = _t;
0513:            }
0514:
0515:            public final void action(AST _t) throws RecognitionException {
0516:
0517:                GrammarAST action_AST_in = (_t == ASTNULL) ? null
0518:                        : (GrammarAST) _t;
0519:                GrammarAST amp = null;
0520:                GrammarAST id1 = null;
0521:                GrammarAST id2 = null;
0522:                GrammarAST a1 = null;
0523:                GrammarAST a2 = null;
0524:
0525:                String scope = null;
0526:                GrammarAST nameAST = null, actionAST = null;
0527:
0528:                try { // for error handling
0529:                    AST __t20 = _t;
0530:                    amp = _t == ASTNULL ? null : (GrammarAST) _t;
0531:                    match(_t, AMPERSAND);
0532:                    _t = _t.getFirstChild();
0533:                    id1 = (GrammarAST) _t;
0534:                    match(_t, ID);
0535:                    _t = _t.getNextSibling();
0536:                    {
0537:                        if (_t == null)
0538:                            _t = ASTNULL;
0539:                        switch (_t.getType()) {
0540:                        case ID: {
0541:                            id2 = (GrammarAST) _t;
0542:                            match(_t, ID);
0543:                            _t = _t.getNextSibling();
0544:                            a1 = (GrammarAST) _t;
0545:                            match(_t, ACTION);
0546:                            _t = _t.getNextSibling();
0547:                            if (inputState.guessing == 0) {
0548:                                scope = id1.getText();
0549:                                nameAST = id2;
0550:                                actionAST = a1;
0551:                            }
0552:                            break;
0553:                        }
0554:                        case ACTION: {
0555:                            a2 = (GrammarAST) _t;
0556:                            match(_t, ACTION);
0557:                            _t = _t.getNextSibling();
0558:                            if (inputState.guessing == 0) {
0559:                                scope = null;
0560:                                nameAST = id1;
0561:                                actionAST = a2;
0562:                            }
0563:                            break;
0564:                        }
0565:                        default: {
0566:                            throw new NoViableAltException(_t);
0567:                        }
0568:                        }
0569:                    }
0570:                    _t = __t20;
0571:                    _t = _t.getNextSibling();
0572:                    if (inputState.guessing == 0) {
0573:
0574:                        grammar.defineNamedAction(amp, scope, nameAST,
0575:                                actionAST);
0576:
0577:                    }
0578:                } catch (RecognitionException ex) {
0579:                    if (inputState.guessing == 0) {
0580:                        reportError(ex);
0581:                        if (_t != null) {
0582:                            _t = _t.getNextSibling();
0583:                        }
0584:                    } else {
0585:                        throw ex;
0586:                    }
0587:                }
0588:                _retTree = _t;
0589:            }
0590:
0591:            public final void tokenSpec(AST _t) throws RecognitionException {
0592:
0593:                GrammarAST tokenSpec_AST_in = (_t == ASTNULL) ? null
0594:                        : (GrammarAST) _t;
0595:                GrammarAST t = null;
0596:                GrammarAST t2 = null;
0597:                GrammarAST s = null;
0598:                GrammarAST c = null;
0599:
0600:                try { // for error handling
0601:                    if (_t == null)
0602:                        _t = ASTNULL;
0603:                    switch (_t.getType()) {
0604:                    case TOKEN_REF: {
0605:                        t = (GrammarAST) _t;
0606:                        match(_t, TOKEN_REF);
0607:                        _t = _t.getNextSibling();
0608:                        break;
0609:                    }
0610:                    case ASSIGN: {
0611:                        AST __t28 = _t;
0612:                        GrammarAST tmp8_AST_in = (GrammarAST) _t;
0613:                        match(_t, ASSIGN);
0614:                        _t = _t.getFirstChild();
0615:                        t2 = (GrammarAST) _t;
0616:                        match(_t, TOKEN_REF);
0617:                        _t = _t.getNextSibling();
0618:                        {
0619:                            if (_t == null)
0620:                                _t = ASTNULL;
0621:                            switch (_t.getType()) {
0622:                            case STRING_LITERAL: {
0623:                                s = (GrammarAST) _t;
0624:                                match(_t, STRING_LITERAL);
0625:                                _t = _t.getNextSibling();
0626:                                break;
0627:                            }
0628:                            case CHAR_LITERAL: {
0629:                                c = (GrammarAST) _t;
0630:                                match(_t, CHAR_LITERAL);
0631:                                _t = _t.getNextSibling();
0632:                                break;
0633:                            }
0634:                            default: {
0635:                                throw new NoViableAltException(_t);
0636:                            }
0637:                            }
0638:                        }
0639:                        _t = __t28;
0640:                        _t = _t.getNextSibling();
0641:                        break;
0642:                    }
0643:                    default: {
0644:                        throw new NoViableAltException(_t);
0645:                    }
0646:                    }
0647:                } catch (RecognitionException ex) {
0648:                    if (inputState.guessing == 0) {
0649:                        reportError(ex);
0650:                        if (_t != null) {
0651:                            _t = _t.getNextSibling();
0652:                        }
0653:                    } else {
0654:                        throw ex;
0655:                    }
0656:                }
0657:                _retTree = _t;
0658:            }
0659:
0660:            public final void rule(AST _t) throws RecognitionException {
0661:
0662:                GrammarAST rule_AST_in = (_t == ASTNULL) ? null
0663:                        : (GrammarAST) _t;
0664:                GrammarAST id = null;
0665:                GrammarAST args = null;
0666:                GrammarAST ret = null;
0667:                GrammarAST b = null;
0668:
0669:                String mod = null;
0670:                String name = null;
0671:                Map opts = null;
0672:                Rule r = null;
0673:
0674:                try { // for error handling
0675:                    AST __t34 = _t;
0676:                    GrammarAST tmp9_AST_in = (GrammarAST) _t;
0677:                    match(_t, RULE);
0678:                    _t = _t.getFirstChild();
0679:                    id = (GrammarAST) _t;
0680:                    match(_t, ID);
0681:                    _t = _t.getNextSibling();
0682:                    if (inputState.guessing == 0) {
0683:                        opts = tmp9_AST_in.options;
0684:                    }
0685:                    {
0686:                        if (_t == null)
0687:                            _t = ASTNULL;
0688:                        switch (_t.getType()) {
0689:                        case FRAGMENT:
0690:                        case LITERAL_protected:
0691:                        case LITERAL_public:
0692:                        case LITERAL_private: {
0693:                            mod = modifier(_t);
0694:                            _t = _retTree;
0695:                            break;
0696:                        }
0697:                        case ARG: {
0698:                            break;
0699:                        }
0700:                        default: {
0701:                            throw new NoViableAltException(_t);
0702:                        }
0703:                        }
0704:                    }
0705:                    AST __t36 = _t;
0706:                    GrammarAST tmp10_AST_in = (GrammarAST) _t;
0707:                    match(_t, ARG);
0708:                    _t = _t.getFirstChild();
0709:                    {
0710:                        if (_t == null)
0711:                            _t = ASTNULL;
0712:                        switch (_t.getType()) {
0713:                        case ARG_ACTION: {
0714:                            args = (GrammarAST) _t;
0715:                            match(_t, ARG_ACTION);
0716:                            _t = _t.getNextSibling();
0717:                            break;
0718:                        }
0719:                        case 3: {
0720:                            break;
0721:                        }
0722:                        default: {
0723:                            throw new NoViableAltException(_t);
0724:                        }
0725:                        }
0726:                    }
0727:                    _t = __t36;
0728:                    _t = _t.getNextSibling();
0729:                    AST __t38 = _t;
0730:                    GrammarAST tmp11_AST_in = (GrammarAST) _t;
0731:                    match(_t, RET);
0732:                    _t = _t.getFirstChild();
0733:                    {
0734:                        if (_t == null)
0735:                            _t = ASTNULL;
0736:                        switch (_t.getType()) {
0737:                        case ARG_ACTION: {
0738:                            ret = (GrammarAST) _t;
0739:                            match(_t, ARG_ACTION);
0740:                            _t = _t.getNextSibling();
0741:                            break;
0742:                        }
0743:                        case 3: {
0744:                            break;
0745:                        }
0746:                        default: {
0747:                            throw new NoViableAltException(_t);
0748:                        }
0749:                        }
0750:                    }
0751:                    _t = __t38;
0752:                    _t = _t.getNextSibling();
0753:                    {
0754:                        if (_t == null)
0755:                            _t = ASTNULL;
0756:                        switch (_t.getType()) {
0757:                        case OPTIONS: {
0758:                            optionsSpec(_t);
0759:                            _t = _retTree;
0760:                            break;
0761:                        }
0762:                        case BLOCK:
0763:                        case SCOPE:
0764:                        case AMPERSAND: {
0765:                            break;
0766:                        }
0767:                        default: {
0768:                            throw new NoViableAltException(_t);
0769:                        }
0770:                        }
0771:                    }
0772:                    if (inputState.guessing == 0) {
0773:
0774:                        name = id.getText();
0775:                        currentRuleName = name;
0776:                        if (Character.isUpperCase(name.charAt(0))
0777:                                && grammar.type == Grammar.COMBINED) {
0778:                            // a merged grammar spec, track lexer rules and send to another grammar
0779:                            grammar.defineLexerRuleFoundInParser(id.getToken(),
0780:                                    rule_AST_in);
0781:                        } else {
0782:                            int numAlts = countAltsForRule(rule_AST_in);
0783:                            grammar.defineRule(id.getToken(), mod, opts,
0784:                                    rule_AST_in, args, numAlts);
0785:                            r = grammar.getRule(name);
0786:                            if (args != null) {
0787:                                r.parameterScope = grammar
0788:                                        .createParameterScope(name, args.token);
0789:                                r.parameterScope.addAttributes(args.getText(),
0790:                                        ",");
0791:                            }
0792:                            if (ret != null) {
0793:                                r.returnScope = grammar.createReturnScope(name,
0794:                                        ret.token);
0795:                                r.returnScope.addAttributes(ret.getText(), ",");
0796:                            }
0797:                        }
0798:
0799:                    }
0800:                    {
0801:                        if (_t == null)
0802:                            _t = ASTNULL;
0803:                        switch (_t.getType()) {
0804:                        case SCOPE: {
0805:                            ruleScopeSpec(_t, r);
0806:                            _t = _retTree;
0807:                            break;
0808:                        }
0809:                        case BLOCK:
0810:                        case AMPERSAND: {
0811:                            break;
0812:                        }
0813:                        default: {
0814:                            throw new NoViableAltException(_t);
0815:                        }
0816:                        }
0817:                    }
0818:                    {
0819:                        _loop43: do {
0820:                            if (_t == null)
0821:                                _t = ASTNULL;
0822:                            if ((_t.getType() == AMPERSAND)) {
0823:                                ruleAction(_t, r);
0824:                                _t = _retTree;
0825:                            } else {
0826:                                break _loop43;
0827:                            }
0828:
0829:                        } while (true);
0830:                    }
0831:                    if (inputState.guessing == 0) {
0832:                        this .blockLevel = 0;
0833:                    }
0834:                    b = _t == ASTNULL ? null : (GrammarAST) _t;
0835:                    block(_t);
0836:                    _t = _retTree;
0837:                    {
0838:                        if (_t == null)
0839:                            _t = ASTNULL;
0840:                        switch (_t.getType()) {
0841:                        case LITERAL_catch:
0842:                        case LITERAL_finally: {
0843:                            exceptionGroup(_t);
0844:                            _t = _retTree;
0845:                            break;
0846:                        }
0847:                        case EOR: {
0848:                            break;
0849:                        }
0850:                        default: {
0851:                            throw new NoViableAltException(_t);
0852:                        }
0853:                        }
0854:                    }
0855:                    GrammarAST tmp12_AST_in = (GrammarAST) _t;
0856:                    match(_t, EOR);
0857:                    _t = _t.getNextSibling();
0858:                    if (inputState.guessing == 0) {
0859:
0860:                        // copy rule options into the block AST, which is where
0861:                        // the analysis will look for k option etc...
0862:                        b.options = opts;
0863:
0864:                    }
0865:                    _t = __t34;
0866:                    _t = _t.getNextSibling();
0867:                } catch (RecognitionException ex) {
0868:                    if (inputState.guessing == 0) {
0869:                        reportError(ex);
0870:                        if (_t != null) {
0871:                            _t = _t.getNextSibling();
0872:                        }
0873:                    } else {
0874:                        throw ex;
0875:                    }
0876:                }
0877:                _retTree = _t;
0878:            }
0879:
0880:            public final String modifier(AST _t) throws RecognitionException {
0881:                String mod;
0882:
0883:                GrammarAST modifier_AST_in = (_t == ASTNULL) ? null
0884:                        : (GrammarAST) _t;
0885:
0886:                mod = modifier_AST_in.getText();
0887:
0888:                try { // for error handling
0889:                    if (_t == null)
0890:                        _t = ASTNULL;
0891:                    switch (_t.getType()) {
0892:                    case LITERAL_protected: {
0893:                        GrammarAST tmp13_AST_in = (GrammarAST) _t;
0894:                        match(_t, LITERAL_protected);
0895:                        _t = _t.getNextSibling();
0896:                        break;
0897:                    }
0898:                    case LITERAL_public: {
0899:                        GrammarAST tmp14_AST_in = (GrammarAST) _t;
0900:                        match(_t, LITERAL_public);
0901:                        _t = _t.getNextSibling();
0902:                        break;
0903:                    }
0904:                    case LITERAL_private: {
0905:                        GrammarAST tmp15_AST_in = (GrammarAST) _t;
0906:                        match(_t, LITERAL_private);
0907:                        _t = _t.getNextSibling();
0908:                        break;
0909:                    }
0910:                    case FRAGMENT: {
0911:                        GrammarAST tmp16_AST_in = (GrammarAST) _t;
0912:                        match(_t, FRAGMENT);
0913:                        _t = _t.getNextSibling();
0914:                        break;
0915:                    }
0916:                    default: {
0917:                        throw new NoViableAltException(_t);
0918:                    }
0919:                    }
0920:                } catch (RecognitionException ex) {
0921:                    if (inputState.guessing == 0) {
0922:                        reportError(ex);
0923:                        if (_t != null) {
0924:                            _t = _t.getNextSibling();
0925:                        }
0926:                    } else {
0927:                        throw ex;
0928:                    }
0929:                }
0930:                _retTree = _t;
0931:                return mod;
0932:            }
0933:
0934:            public final void ruleScopeSpec(AST _t, Rule r)
0935:                    throws RecognitionException {
0936:
0937:                GrammarAST ruleScopeSpec_AST_in = (_t == ASTNULL) ? null
0938:                        : (GrammarAST) _t;
0939:                GrammarAST attrs = null;
0940:                GrammarAST uses = null;
0941:
0942:                try { // for error handling
0943:                    AST __t63 = _t;
0944:                    GrammarAST tmp17_AST_in = (GrammarAST) _t;
0945:                    match(_t, SCOPE);
0946:                    _t = _t.getFirstChild();
0947:                    {
0948:                        if (_t == null)
0949:                            _t = ASTNULL;
0950:                        switch (_t.getType()) {
0951:                        case ACTION: {
0952:                            attrs = (GrammarAST) _t;
0953:                            match(_t, ACTION);
0954:                            _t = _t.getNextSibling();
0955:                            if (inputState.guessing == 0) {
0956:
0957:                                r.ruleScope = grammar.createRuleScope(r.name,
0958:                                        attrs.token);
0959:                                r.ruleScope.isDynamicRuleScope = true;
0960:                                r.ruleScope.addAttributes(attrs.getText(), ";");
0961:
0962:                            }
0963:                            break;
0964:                        }
0965:                        case 3:
0966:                        case ID: {
0967:                            break;
0968:                        }
0969:                        default: {
0970:                            throw new NoViableAltException(_t);
0971:                        }
0972:                        }
0973:                    }
0974:                    {
0975:                        _loop66: do {
0976:                            if (_t == null)
0977:                                _t = ASTNULL;
0978:                            if ((_t.getType() == ID)) {
0979:                                uses = (GrammarAST) _t;
0980:                                match(_t, ID);
0981:                                _t = _t.getNextSibling();
0982:                                if (inputState.guessing == 0) {
0983:
0984:                                    if (grammar.getGlobalScope(uses.getText()) == null) {
0985:                                        ErrorManager
0986:                                                .grammarError(
0987:                                                        ErrorManager.MSG_UNKNOWN_DYNAMIC_SCOPE,
0988:                                                        grammar, uses.token,
0989:                                                        uses.getText());
0990:                                    } else {
0991:                                        if (r.useScopes == null) {
0992:                                            r.useScopes = new ArrayList();
0993:                                        }
0994:                                        r.useScopes.add(uses.getText());
0995:                                    }
0996:
0997:                                }
0998:                            } else {
0999:                                break _loop66;
1000:                            }
1001:
1002:                        } while (true);
1003:                    }
1004:                    _t = __t63;
1005:                    _t = _t.getNextSibling();
1006:                } catch (RecognitionException ex) {
1007:                    if (inputState.guessing == 0) {
1008:                        reportError(ex);
1009:                        if (_t != null) {
1010:                            _t = _t.getNextSibling();
1011:                        }
1012:                    } else {
1013:                        throw ex;
1014:                    }
1015:                }
1016:                _retTree = _t;
1017:            }
1018:
1019:            public final void ruleAction(AST _t, Rule r)
1020:                    throws RecognitionException {
1021:
1022:                GrammarAST ruleAction_AST_in = (_t == ASTNULL) ? null
1023:                        : (GrammarAST) _t;
1024:                GrammarAST amp = null;
1025:                GrammarAST id = null;
1026:                GrammarAST a = null;
1027:
1028:                try { // for error handling
1029:                    AST __t60 = _t;
1030:                    amp = _t == ASTNULL ? null : (GrammarAST) _t;
1031:                    match(_t, AMPERSAND);
1032:                    _t = _t.getFirstChild();
1033:                    id = (GrammarAST) _t;
1034:                    match(_t, ID);
1035:                    _t = _t.getNextSibling();
1036:                    a = (GrammarAST) _t;
1037:                    match(_t, ACTION);
1038:                    _t = _t.getNextSibling();
1039:                    _t = __t60;
1040:                    _t = _t.getNextSibling();
1041:                    if (inputState.guessing == 0) {
1042:                        if (r != null)
1043:                            r.defineNamedAction(amp, id, a);
1044:                    }
1045:                } catch (RecognitionException ex) {
1046:                    if (inputState.guessing == 0) {
1047:                        reportError(ex);
1048:                        if (_t != null) {
1049:                            _t = _t.getNextSibling();
1050:                        }
1051:                    } else {
1052:                        throw ex;
1053:                    }
1054:                }
1055:                _retTree = _t;
1056:            }
1057:
1058:            public final void block(AST _t) throws RecognitionException {
1059:
1060:                GrammarAST block_AST_in = (_t == ASTNULL) ? null
1061:                        : (GrammarAST) _t;
1062:
1063:                this .blockLevel++;
1064:                if (this .blockLevel == 1) {
1065:                    this .outerAltNum = 1;
1066:                }
1067:
1068:                try { // for error handling
1069:                    AST __t68 = _t;
1070:                    GrammarAST tmp18_AST_in = (GrammarAST) _t;
1071:                    match(_t, BLOCK);
1072:                    _t = _t.getFirstChild();
1073:                    {
1074:                        if (_t == null)
1075:                            _t = ASTNULL;
1076:                        switch (_t.getType()) {
1077:                        case OPTIONS: {
1078:                            optionsSpec(_t);
1079:                            _t = _retTree;
1080:                            break;
1081:                        }
1082:                        case ALT:
1083:                        case AMPERSAND: {
1084:                            break;
1085:                        }
1086:                        default: {
1087:                            throw new NoViableAltException(_t);
1088:                        }
1089:                        }
1090:                    }
1091:                    {
1092:                        _loop71: do {
1093:                            if (_t == null)
1094:                                _t = ASTNULL;
1095:                            if ((_t.getType() == AMPERSAND)) {
1096:                                blockAction(_t);
1097:                                _t = _retTree;
1098:                            } else {
1099:                                break _loop71;
1100:                            }
1101:
1102:                        } while (true);
1103:                    }
1104:                    {
1105:                        int _cnt73 = 0;
1106:                        _loop73: do {
1107:                            if (_t == null)
1108:                                _t = ASTNULL;
1109:                            if ((_t.getType() == ALT)) {
1110:                                alternative(_t);
1111:                                _t = _retTree;
1112:                                rewrite(_t);
1113:                                _t = _retTree;
1114:                                if (inputState.guessing == 0) {
1115:                                    if (this .blockLevel == 1) {
1116:                                        this .outerAltNum++;
1117:                                    }
1118:                                }
1119:                            } else {
1120:                                if (_cnt73 >= 1) {
1121:                                    break _loop73;
1122:                                } else {
1123:                                    throw new NoViableAltException(_t);
1124:                                }
1125:                            }
1126:
1127:                            _cnt73++;
1128:                        } while (true);
1129:                    }
1130:                    GrammarAST tmp19_AST_in = (GrammarAST) _t;
1131:                    match(_t, EOB);
1132:                    _t = _t.getNextSibling();
1133:                    _t = __t68;
1134:                    _t = _t.getNextSibling();
1135:                    if (inputState.guessing == 0) {
1136:                        this .blockLevel--;
1137:                    }
1138:                } catch (RecognitionException ex) {
1139:                    if (inputState.guessing == 0) {
1140:                        reportError(ex);
1141:                        if (_t != null) {
1142:                            _t = _t.getNextSibling();
1143:                        }
1144:                    } else {
1145:                        throw ex;
1146:                    }
1147:                }
1148:                _retTree = _t;
1149:            }
1150:
1151:            public final void exceptionGroup(AST _t)
1152:                    throws RecognitionException {
1153:
1154:                GrammarAST exceptionGroup_AST_in = (_t == ASTNULL) ? null
1155:                        : (GrammarAST) _t;
1156:
1157:                try { // for error handling
1158:                    if (_t == null)
1159:                        _t = ASTNULL;
1160:                    switch (_t.getType()) {
1161:                    case LITERAL_catch: {
1162:                        {
1163:                            int _cnt82 = 0;
1164:                            _loop82: do {
1165:                                if (_t == null)
1166:                                    _t = ASTNULL;
1167:                                if ((_t.getType() == LITERAL_catch)) {
1168:                                    exceptionHandler(_t);
1169:                                    _t = _retTree;
1170:                                } else {
1171:                                    if (_cnt82 >= 1) {
1172:                                        break _loop82;
1173:                                    } else {
1174:                                        throw new NoViableAltException(_t);
1175:                                    }
1176:                                }
1177:
1178:                                _cnt82++;
1179:                            } while (true);
1180:                        }
1181:                        {
1182:                            if (_t == null)
1183:                                _t = ASTNULL;
1184:                            switch (_t.getType()) {
1185:                            case LITERAL_finally: {
1186:                                finallyClause(_t);
1187:                                _t = _retTree;
1188:                                break;
1189:                            }
1190:                            case EOR: {
1191:                                break;
1192:                            }
1193:                            default: {
1194:                                throw new NoViableAltException(_t);
1195:                            }
1196:                            }
1197:                        }
1198:                        break;
1199:                    }
1200:                    case LITERAL_finally: {
1201:                        finallyClause(_t);
1202:                        _t = _retTree;
1203:                        break;
1204:                    }
1205:                    default: {
1206:                        throw new NoViableAltException(_t);
1207:                    }
1208:                    }
1209:                } catch (RecognitionException ex) {
1210:                    if (inputState.guessing == 0) {
1211:                        reportError(ex);
1212:                        if (_t != null) {
1213:                            _t = _t.getNextSibling();
1214:                        }
1215:                    } else {
1216:                        throw ex;
1217:                    }
1218:                }
1219:                _retTree = _t;
1220:            }
1221:
1222:            public final int countAltsForRule(AST _t)
1223:                    throws RecognitionException {
1224:                int n = 0;
1225:
1226:                GrammarAST countAltsForRule_AST_in = (_t == ASTNULL) ? null
1227:                        : (GrammarAST) _t;
1228:                GrammarAST id = null;
1229:
1230:                try { // for error handling
1231:                    AST __t46 = _t;
1232:                    GrammarAST tmp20_AST_in = (GrammarAST) _t;
1233:                    match(_t, RULE);
1234:                    _t = _t.getFirstChild();
1235:                    id = (GrammarAST) _t;
1236:                    match(_t, ID);
1237:                    _t = _t.getNextSibling();
1238:                    {
1239:                        if (_t == null)
1240:                            _t = ASTNULL;
1241:                        switch (_t.getType()) {
1242:                        case FRAGMENT:
1243:                        case LITERAL_protected:
1244:                        case LITERAL_public:
1245:                        case LITERAL_private: {
1246:                            modifier(_t);
1247:                            _t = _retTree;
1248:                            break;
1249:                        }
1250:                        case ARG: {
1251:                            break;
1252:                        }
1253:                        default: {
1254:                            throw new NoViableAltException(_t);
1255:                        }
1256:                        }
1257:                    }
1258:                    GrammarAST tmp21_AST_in = (GrammarAST) _t;
1259:                    match(_t, ARG);
1260:                    _t = _t.getNextSibling();
1261:                    GrammarAST tmp22_AST_in = (GrammarAST) _t;
1262:                    match(_t, RET);
1263:                    _t = _t.getNextSibling();
1264:                    {
1265:                        if (_t == null)
1266:                            _t = ASTNULL;
1267:                        switch (_t.getType()) {
1268:                        case OPTIONS: {
1269:                            GrammarAST tmp23_AST_in = (GrammarAST) _t;
1270:                            match(_t, OPTIONS);
1271:                            _t = _t.getNextSibling();
1272:                            break;
1273:                        }
1274:                        case BLOCK:
1275:                        case SCOPE:
1276:                        case AMPERSAND: {
1277:                            break;
1278:                        }
1279:                        default: {
1280:                            throw new NoViableAltException(_t);
1281:                        }
1282:                        }
1283:                    }
1284:                    {
1285:                        if (_t == null)
1286:                            _t = ASTNULL;
1287:                        switch (_t.getType()) {
1288:                        case SCOPE: {
1289:                            GrammarAST tmp24_AST_in = (GrammarAST) _t;
1290:                            match(_t, SCOPE);
1291:                            _t = _t.getNextSibling();
1292:                            break;
1293:                        }
1294:                        case BLOCK:
1295:                        case AMPERSAND: {
1296:                            break;
1297:                        }
1298:                        default: {
1299:                            throw new NoViableAltException(_t);
1300:                        }
1301:                        }
1302:                    }
1303:                    {
1304:                        _loop51: do {
1305:                            if (_t == null)
1306:                                _t = ASTNULL;
1307:                            if ((_t.getType() == AMPERSAND)) {
1308:                                GrammarAST tmp25_AST_in = (GrammarAST) _t;
1309:                                match(_t, AMPERSAND);
1310:                                _t = _t.getNextSibling();
1311:                            } else {
1312:                                break _loop51;
1313:                            }
1314:
1315:                        } while (true);
1316:                    }
1317:                    AST __t52 = _t;
1318:                    GrammarAST tmp26_AST_in = (GrammarAST) _t;
1319:                    match(_t, BLOCK);
1320:                    _t = _t.getFirstChild();
1321:                    {
1322:                        if (_t == null)
1323:                            _t = ASTNULL;
1324:                        switch (_t.getType()) {
1325:                        case OPTIONS: {
1326:                            GrammarAST tmp27_AST_in = (GrammarAST) _t;
1327:                            match(_t, OPTIONS);
1328:                            _t = _t.getNextSibling();
1329:                            break;
1330:                        }
1331:                        case ALT: {
1332:                            break;
1333:                        }
1334:                        default: {
1335:                            throw new NoViableAltException(_t);
1336:                        }
1337:                        }
1338:                    }
1339:                    {
1340:                        int _cnt57 = 0;
1341:                        _loop57: do {
1342:                            if (_t == null)
1343:                                _t = ASTNULL;
1344:                            if ((_t.getType() == ALT)) {
1345:                                GrammarAST tmp28_AST_in = (GrammarAST) _t;
1346:                                match(_t, ALT);
1347:                                _t = _t.getNextSibling();
1348:                                {
1349:                                    _loop56: do {
1350:                                        if (_t == null)
1351:                                            _t = ASTNULL;
1352:                                        if ((_t.getType() == REWRITE)) {
1353:                                            GrammarAST tmp29_AST_in = (GrammarAST) _t;
1354:                                            match(_t, REWRITE);
1355:                                            _t = _t.getNextSibling();
1356:                                        } else {
1357:                                            break _loop56;
1358:                                        }
1359:
1360:                                    } while (true);
1361:                                }
1362:                                if (inputState.guessing == 0) {
1363:                                    n++;
1364:                                }
1365:                            } else {
1366:                                if (_cnt57 >= 1) {
1367:                                    break _loop57;
1368:                                } else {
1369:                                    throw new NoViableAltException(_t);
1370:                                }
1371:                            }
1372:
1373:                            _cnt57++;
1374:                        } while (true);
1375:                    }
1376:                    GrammarAST tmp30_AST_in = (GrammarAST) _t;
1377:                    match(_t, EOB);
1378:                    _t = _t.getNextSibling();
1379:                    _t = __t52;
1380:                    _t = _t.getNextSibling();
1381:                    {
1382:                        if (_t == null)
1383:                            _t = ASTNULL;
1384:                        switch (_t.getType()) {
1385:                        case LITERAL_catch:
1386:                        case LITERAL_finally: {
1387:                            exceptionGroup(_t);
1388:                            _t = _retTree;
1389:                            break;
1390:                        }
1391:                        case EOR: {
1392:                            break;
1393:                        }
1394:                        default: {
1395:                            throw new NoViableAltException(_t);
1396:                        }
1397:                        }
1398:                    }
1399:                    GrammarAST tmp31_AST_in = (GrammarAST) _t;
1400:                    match(_t, EOR);
1401:                    _t = _t.getNextSibling();
1402:                    _t = __t46;
1403:                    _t = _t.getNextSibling();
1404:                } catch (RecognitionException ex) {
1405:                    if (inputState.guessing == 0) {
1406:                        reportError(ex);
1407:                        if (_t != null) {
1408:                            _t = _t.getNextSibling();
1409:                        }
1410:                    } else {
1411:                        throw ex;
1412:                    }
1413:                }
1414:                _retTree = _t;
1415:                return n;
1416:            }
1417:
1418:            public final void blockAction(AST _t) throws RecognitionException {
1419:
1420:                GrammarAST blockAction_AST_in = (_t == ASTNULL) ? null
1421:                        : (GrammarAST) _t;
1422:                GrammarAST amp = null;
1423:                GrammarAST id = null;
1424:                GrammarAST a = null;
1425:
1426:                try { // for error handling
1427:                    AST __t75 = _t;
1428:                    amp = _t == ASTNULL ? null : (GrammarAST) _t;
1429:                    match(_t, AMPERSAND);
1430:                    _t = _t.getFirstChild();
1431:                    id = (GrammarAST) _t;
1432:                    match(_t, ID);
1433:                    _t = _t.getNextSibling();
1434:                    a = (GrammarAST) _t;
1435:                    match(_t, ACTION);
1436:                    _t = _t.getNextSibling();
1437:                    _t = __t75;
1438:                    _t = _t.getNextSibling();
1439:                } catch (RecognitionException ex) {
1440:                    if (inputState.guessing == 0) {
1441:                        reportError(ex);
1442:                        if (_t != null) {
1443:                            _t = _t.getNextSibling();
1444:                        }
1445:                    } else {
1446:                        throw ex;
1447:                    }
1448:                }
1449:                _retTree = _t;
1450:            }
1451:
1452:            public final void alternative(AST _t) throws RecognitionException {
1453:
1454:                GrammarAST alternative_AST_in = (_t == ASTNULL) ? null
1455:                        : (GrammarAST) _t;
1456:
1457:                if (grammar.type != Grammar.LEXER
1458:                        && grammar.getOption("output") != null
1459:                        && blockLevel == 1) {
1460:                    GrammarAST aRewriteNode = alternative_AST_in
1461:                            .findFirstType(REWRITE);
1462:                    if (aRewriteNode != null
1463:                            || (alternative_AST_in.getNextSibling() != null && alternative_AST_in
1464:                                    .getNextSibling().getType() == REWRITE)) {
1465:                        Rule r = grammar.getRule(currentRuleName);
1466:                        r.trackAltsWithRewrites(alternative_AST_in,
1467:                                this .outerAltNum);
1468:                    }
1469:                }
1470:
1471:                try { // for error handling
1472:                    AST __t77 = _t;
1473:                    GrammarAST tmp32_AST_in = (GrammarAST) _t;
1474:                    match(_t, ALT);
1475:                    _t = _t.getFirstChild();
1476:                    {
1477:                        int _cnt79 = 0;
1478:                        _loop79: do {
1479:                            if (_t == null)
1480:                                _t = ASTNULL;
1481:                            if ((_t.getType() == BLOCK
1482:                                    || _t.getType() == OPTIONAL
1483:                                    || _t.getType() == CLOSURE
1484:                                    || _t.getType() == POSITIVE_CLOSURE
1485:                                    || _t.getType() == SYNPRED
1486:                                    || _t.getType() == RANGE
1487:                                    || _t.getType() == CHAR_RANGE
1488:                                    || _t.getType() == EPSILON
1489:                                    || _t.getType() == GATED_SEMPRED
1490:                                    || _t.getType() == SYN_SEMPRED
1491:                                    || _t.getType() == BACKTRACK_SEMPRED
1492:                                    || _t.getType() == ACTION
1493:                                    || _t.getType() == ASSIGN
1494:                                    || _t.getType() == STRING_LITERAL
1495:                                    || _t.getType() == CHAR_LITERAL
1496:                                    || _t.getType() == TOKEN_REF
1497:                                    || _t.getType() == BANG
1498:                                    || _t.getType() == PLUS_ASSIGN
1499:                                    || _t.getType() == SEMPRED
1500:                                    || _t.getType() == ROOT
1501:                                    || _t.getType() == RULE_REF
1502:                                    || _t.getType() == NOT
1503:                                    || _t.getType() == TREE_BEGIN || _t
1504:                                    .getType() == WILDCARD)) {
1505:                                element(_t);
1506:                                _t = _retTree;
1507:                            } else {
1508:                                if (_cnt79 >= 1) {
1509:                                    break _loop79;
1510:                                } else {
1511:                                    throw new NoViableAltException(_t);
1512:                                }
1513:                            }
1514:
1515:                            _cnt79++;
1516:                        } while (true);
1517:                    }
1518:                    GrammarAST tmp33_AST_in = (GrammarAST) _t;
1519:                    match(_t, EOA);
1520:                    _t = _t.getNextSibling();
1521:                    _t = __t77;
1522:                    _t = _t.getNextSibling();
1523:                } catch (RecognitionException ex) {
1524:                    if (inputState.guessing == 0) {
1525:                        reportError(ex);
1526:                        if (_t != null) {
1527:                            _t = _t.getNextSibling();
1528:                        }
1529:                    } else {
1530:                        throw ex;
1531:                    }
1532:                }
1533:                _retTree = _t;
1534:            }
1535:
1536:            public final void rewrite(AST _t) throws RecognitionException {
1537:
1538:                GrammarAST rewrite_AST_in = (_t == ASTNULL) ? null
1539:                        : (GrammarAST) _t;
1540:                GrammarAST pred = null;
1541:
1542:                currentRewriteRule = rewrite_AST_in; // has to execute during guessing
1543:                if (grammar.buildAST()) {
1544:                    rewrite_AST_in.rewriteRefsDeep = new HashSet<GrammarAST>();
1545:                }
1546:
1547:                try { // for error handling
1548:                    {
1549:                        _loop124: do {
1550:                            if (_t == null)
1551:                                _t = ASTNULL;
1552:                            if ((_t.getType() == REWRITE)) {
1553:                                AST __t122 = _t;
1554:                                GrammarAST tmp34_AST_in = (GrammarAST) _t;
1555:                                match(_t, REWRITE);
1556:                                _t = _t.getFirstChild();
1557:                                {
1558:                                    if (_t == null)
1559:                                        _t = ASTNULL;
1560:                                    switch (_t.getType()) {
1561:                                    case SEMPRED: {
1562:                                        pred = (GrammarAST) _t;
1563:                                        match(_t, SEMPRED);
1564:                                        _t = _t.getNextSibling();
1565:                                        break;
1566:                                    }
1567:                                    case ALT:
1568:                                    case TEMPLATE:
1569:                                    case ACTION: {
1570:                                        break;
1571:                                    }
1572:                                    default: {
1573:                                        throw new NoViableAltException(_t);
1574:                                    }
1575:                                    }
1576:                                }
1577:                                rewrite_alternative(_t);
1578:                                _t = _retTree;
1579:                                _t = __t122;
1580:                                _t = _t.getNextSibling();
1581:                                if (inputState.guessing == 0) {
1582:
1583:                                    if (pred != null) {
1584:                                        pred.outerAltNum = this .outerAltNum;
1585:                                        trackInlineAction(pred);
1586:                                    }
1587:
1588:                                }
1589:                            } else {
1590:                                break _loop124;
1591:                            }
1592:
1593:                        } while (true);
1594:                    }
1595:                } catch (RecognitionException ex) {
1596:                    if (inputState.guessing == 0) {
1597:                        reportError(ex);
1598:                        if (_t != null) {
1599:                            _t = _t.getNextSibling();
1600:                        }
1601:                    } else {
1602:                        throw ex;
1603:                    }
1604:                }
1605:                _retTree = _t;
1606:            }
1607:
1608:            public final void element(AST _t) throws RecognitionException {
1609:
1610:                GrammarAST element_AST_in = (_t == ASTNULL) ? null
1611:                        : (GrammarAST) _t;
1612:                GrammarAST id = null;
1613:                GrammarAST el = null;
1614:                GrammarAST id2 = null;
1615:                GrammarAST a2 = null;
1616:                GrammarAST act = null;
1617:
1618:                try { // for error handling
1619:                    if (_t == null)
1620:                        _t = ASTNULL;
1621:                    switch (_t.getType()) {
1622:                    case ROOT: {
1623:                        AST __t89 = _t;
1624:                        GrammarAST tmp35_AST_in = (GrammarAST) _t;
1625:                        match(_t, ROOT);
1626:                        _t = _t.getFirstChild();
1627:                        element(_t);
1628:                        _t = _retTree;
1629:                        _t = __t89;
1630:                        _t = _t.getNextSibling();
1631:                        break;
1632:                    }
1633:                    case BANG: {
1634:                        AST __t90 = _t;
1635:                        GrammarAST tmp36_AST_in = (GrammarAST) _t;
1636:                        match(_t, BANG);
1637:                        _t = _t.getFirstChild();
1638:                        element(_t);
1639:                        _t = _retTree;
1640:                        _t = __t90;
1641:                        _t = _t.getNextSibling();
1642:                        break;
1643:                    }
1644:                    case STRING_LITERAL:
1645:                    case CHAR_LITERAL:
1646:                    case TOKEN_REF:
1647:                    case RULE_REF:
1648:                    case WILDCARD: {
1649:                        atom(_t);
1650:                        _t = _retTree;
1651:                        break;
1652:                    }
1653:                    case NOT: {
1654:                        AST __t91 = _t;
1655:                        GrammarAST tmp37_AST_in = (GrammarAST) _t;
1656:                        match(_t, NOT);
1657:                        _t = _t.getFirstChild();
1658:                        element(_t);
1659:                        _t = _retTree;
1660:                        _t = __t91;
1661:                        _t = _t.getNextSibling();
1662:                        break;
1663:                    }
1664:                    case RANGE: {
1665:                        AST __t92 = _t;
1666:                        GrammarAST tmp38_AST_in = (GrammarAST) _t;
1667:                        match(_t, RANGE);
1668:                        _t = _t.getFirstChild();
1669:                        atom(_t);
1670:                        _t = _retTree;
1671:                        atom(_t);
1672:                        _t = _retTree;
1673:                        _t = __t92;
1674:                        _t = _t.getNextSibling();
1675:                        break;
1676:                    }
1677:                    case CHAR_RANGE: {
1678:                        AST __t93 = _t;
1679:                        GrammarAST tmp39_AST_in = (GrammarAST) _t;
1680:                        match(_t, CHAR_RANGE);
1681:                        _t = _t.getFirstChild();
1682:                        atom(_t);
1683:                        _t = _retTree;
1684:                        atom(_t);
1685:                        _t = _retTree;
1686:                        _t = __t93;
1687:                        _t = _t.getNextSibling();
1688:                        break;
1689:                    }
1690:                    case ASSIGN: {
1691:                        AST __t94 = _t;
1692:                        GrammarAST tmp40_AST_in = (GrammarAST) _t;
1693:                        match(_t, ASSIGN);
1694:                        _t = _t.getFirstChild();
1695:                        id = (GrammarAST) _t;
1696:                        match(_t, ID);
1697:                        _t = _t.getNextSibling();
1698:                        el = _t == ASTNULL ? null : (GrammarAST) _t;
1699:                        element(_t);
1700:                        _t = _retTree;
1701:                        _t = __t94;
1702:                        _t = _t.getNextSibling();
1703:                        if (inputState.guessing == 0) {
1704:
1705:                            if (el.getType() == ANTLRParser.ROOT
1706:                                    || el.getType() == ANTLRParser.BANG) {
1707:                                el = (GrammarAST) el.getFirstChild();
1708:                            }
1709:                            if (el.getType() == RULE_REF) {
1710:                                grammar.defineRuleRefLabel(currentRuleName, id
1711:                                        .getToken(), el);
1712:                            } else {
1713:                                grammar.defineTokenRefLabel(currentRuleName, id
1714:                                        .getToken(), el);
1715:                            }
1716:
1717:                        }
1718:                        break;
1719:                    }
1720:                    case PLUS_ASSIGN: {
1721:                        AST __t95 = _t;
1722:                        GrammarAST tmp41_AST_in = (GrammarAST) _t;
1723:                        match(_t, PLUS_ASSIGN);
1724:                        _t = _t.getFirstChild();
1725:                        id2 = (GrammarAST) _t;
1726:                        match(_t, ID);
1727:                        _t = _t.getNextSibling();
1728:                        a2 = _t == ASTNULL ? null : (GrammarAST) _t;
1729:                        element(_t);
1730:                        _t = _retTree;
1731:                        if (inputState.guessing == 0) {
1732:
1733:                            if (a2.getType() == ANTLRParser.ROOT
1734:                                    || a2.getType() == ANTLRParser.BANG) {
1735:                                a2 = (GrammarAST) a2.getFirstChild();
1736:                            }
1737:                            if (a2.getType() == RULE_REF) {
1738:                                grammar.defineRuleListLabel(currentRuleName,
1739:                                        id2.getToken(), a2);
1740:                            } else {
1741:                                grammar.defineTokenListLabel(currentRuleName,
1742:                                        id2.getToken(), a2);
1743:                            }
1744:
1745:                        }
1746:                        _t = __t95;
1747:                        _t = _t.getNextSibling();
1748:                        break;
1749:                    }
1750:                    case BLOCK:
1751:                    case OPTIONAL:
1752:                    case CLOSURE:
1753:                    case POSITIVE_CLOSURE: {
1754:                        ebnf(_t);
1755:                        _t = _retTree;
1756:                        break;
1757:                    }
1758:                    case TREE_BEGIN: {
1759:                        tree(_t);
1760:                        _t = _retTree;
1761:                        break;
1762:                    }
1763:                    case SYNPRED: {
1764:                        AST __t96 = _t;
1765:                        GrammarAST tmp42_AST_in = (GrammarAST) _t;
1766:                        match(_t, SYNPRED);
1767:                        _t = _t.getFirstChild();
1768:                        block(_t);
1769:                        _t = _retTree;
1770:                        _t = __t96;
1771:                        _t = _t.getNextSibling();
1772:                        break;
1773:                    }
1774:                    case ACTION: {
1775:                        act = (GrammarAST) _t;
1776:                        match(_t, ACTION);
1777:                        _t = _t.getNextSibling();
1778:                        if (inputState.guessing == 0) {
1779:
1780:                            act.outerAltNum = this .outerAltNum;
1781:                            trackInlineAction(act);
1782:
1783:                        }
1784:                        break;
1785:                    }
1786:                    case SEMPRED: {
1787:                        GrammarAST tmp43_AST_in = (GrammarAST) _t;
1788:                        match(_t, SEMPRED);
1789:                        _t = _t.getNextSibling();
1790:                        if (inputState.guessing == 0) {
1791:
1792:                            tmp43_AST_in.outerAltNum = this .outerAltNum;
1793:                            trackInlineAction(tmp43_AST_in);
1794:
1795:                        }
1796:                        break;
1797:                    }
1798:                    case SYN_SEMPRED: {
1799:                        GrammarAST tmp44_AST_in = (GrammarAST) _t;
1800:                        match(_t, SYN_SEMPRED);
1801:                        _t = _t.getNextSibling();
1802:                        break;
1803:                    }
1804:                    case BACKTRACK_SEMPRED: {
1805:                        GrammarAST tmp45_AST_in = (GrammarAST) _t;
1806:                        match(_t, BACKTRACK_SEMPRED);
1807:                        _t = _t.getNextSibling();
1808:                        break;
1809:                    }
1810:                    case GATED_SEMPRED: {
1811:                        GrammarAST tmp46_AST_in = (GrammarAST) _t;
1812:                        match(_t, GATED_SEMPRED);
1813:                        _t = _t.getNextSibling();
1814:                        if (inputState.guessing == 0) {
1815:
1816:                            tmp46_AST_in.outerAltNum = this .outerAltNum;
1817:                            trackInlineAction(tmp46_AST_in);
1818:
1819:                        }
1820:                        break;
1821:                    }
1822:                    case EPSILON: {
1823:                        GrammarAST tmp47_AST_in = (GrammarAST) _t;
1824:                        match(_t, EPSILON);
1825:                        _t = _t.getNextSibling();
1826:                        break;
1827:                    }
1828:                    default: {
1829:                        throw new NoViableAltException(_t);
1830:                    }
1831:                    }
1832:                } catch (RecognitionException ex) {
1833:                    if (inputState.guessing == 0) {
1834:                        reportError(ex);
1835:                        if (_t != null) {
1836:                            _t = _t.getNextSibling();
1837:                        }
1838:                    } else {
1839:                        throw ex;
1840:                    }
1841:                }
1842:                _retTree = _t;
1843:            }
1844:
1845:            public final void exceptionHandler(AST _t)
1846:                    throws RecognitionException {
1847:
1848:                GrammarAST exceptionHandler_AST_in = (_t == ASTNULL) ? null
1849:                        : (GrammarAST) _t;
1850:
1851:                try { // for error handling
1852:                    AST __t85 = _t;
1853:                    GrammarAST tmp48_AST_in = (GrammarAST) _t;
1854:                    match(_t, LITERAL_catch);
1855:                    _t = _t.getFirstChild();
1856:                    GrammarAST tmp49_AST_in = (GrammarAST) _t;
1857:                    match(_t, ARG_ACTION);
1858:                    _t = _t.getNextSibling();
1859:                    GrammarAST tmp50_AST_in = (GrammarAST) _t;
1860:                    match(_t, ACTION);
1861:                    _t = _t.getNextSibling();
1862:                    _t = __t85;
1863:                    _t = _t.getNextSibling();
1864:                    if (inputState.guessing == 0) {
1865:                        trackInlineAction(tmp50_AST_in);
1866:                    }
1867:                } catch (RecognitionException ex) {
1868:                    if (inputState.guessing == 0) {
1869:                        reportError(ex);
1870:                        if (_t != null) {
1871:                            _t = _t.getNextSibling();
1872:                        }
1873:                    } else {
1874:                        throw ex;
1875:                    }
1876:                }
1877:                _retTree = _t;
1878:            }
1879:
1880:            public final void finallyClause(AST _t) throws RecognitionException {
1881:
1882:                GrammarAST finallyClause_AST_in = (_t == ASTNULL) ? null
1883:                        : (GrammarAST) _t;
1884:
1885:                try { // for error handling
1886:                    AST __t87 = _t;
1887:                    GrammarAST tmp51_AST_in = (GrammarAST) _t;
1888:                    match(_t, LITERAL_finally);
1889:                    _t = _t.getFirstChild();
1890:                    GrammarAST tmp52_AST_in = (GrammarAST) _t;
1891:                    match(_t, ACTION);
1892:                    _t = _t.getNextSibling();
1893:                    _t = __t87;
1894:                    _t = _t.getNextSibling();
1895:                    if (inputState.guessing == 0) {
1896:                        trackInlineAction(tmp52_AST_in);
1897:                    }
1898:                } catch (RecognitionException ex) {
1899:                    if (inputState.guessing == 0) {
1900:                        reportError(ex);
1901:                        if (_t != null) {
1902:                            _t = _t.getNextSibling();
1903:                        }
1904:                    } else {
1905:                        throw ex;
1906:                    }
1907:                }
1908:                _retTree = _t;
1909:            }
1910:
1911:            public final void atom(AST _t) throws RecognitionException {
1912:
1913:                GrammarAST atom_AST_in = (_t == ASTNULL) ? null
1914:                        : (GrammarAST) _t;
1915:                GrammarAST rr = null;
1916:                GrammarAST rarg = null;
1917:                GrammarAST t = null;
1918:                GrammarAST targ = null;
1919:                GrammarAST c = null;
1920:                GrammarAST s = null;
1921:
1922:                try { // for error handling
1923:                    if (_t == null)
1924:                        _t = ASTNULL;
1925:                    switch (_t.getType()) {
1926:                    case RULE_REF: {
1927:                        AST __t115 = _t;
1928:                        rr = _t == ASTNULL ? null : (GrammarAST) _t;
1929:                        match(_t, RULE_REF);
1930:                        _t = _t.getFirstChild();
1931:                        {
1932:                            if (_t == null)
1933:                                _t = ASTNULL;
1934:                            switch (_t.getType()) {
1935:                            case ARG_ACTION: {
1936:                                rarg = (GrammarAST) _t;
1937:                                match(_t, ARG_ACTION);
1938:                                _t = _t.getNextSibling();
1939:                                break;
1940:                            }
1941:                            case 3: {
1942:                                break;
1943:                            }
1944:                            default: {
1945:                                throw new NoViableAltException(_t);
1946:                            }
1947:                            }
1948:                        }
1949:                        _t = __t115;
1950:                        _t = _t.getNextSibling();
1951:                        if (inputState.guessing == 0) {
1952:
1953:                            grammar.altReferencesRule(currentRuleName, rr,
1954:                                    this .outerAltNum);
1955:                            if (rarg != null) {
1956:                                rarg.outerAltNum = this .outerAltNum;
1957:                                trackInlineAction(rarg);
1958:                            }
1959:
1960:                        }
1961:                        break;
1962:                    }
1963:                    case TOKEN_REF: {
1964:                        AST __t117 = _t;
1965:                        t = _t == ASTNULL ? null : (GrammarAST) _t;
1966:                        match(_t, TOKEN_REF);
1967:                        _t = _t.getFirstChild();
1968:                        {
1969:                            if (_t == null)
1970:                                _t = ASTNULL;
1971:                            switch (_t.getType()) {
1972:                            case ARG_ACTION: {
1973:                                targ = (GrammarAST) _t;
1974:                                match(_t, ARG_ACTION);
1975:                                _t = _t.getNextSibling();
1976:                                break;
1977:                            }
1978:                            case 3: {
1979:                                break;
1980:                            }
1981:                            default: {
1982:                                throw new NoViableAltException(_t);
1983:                            }
1984:                            }
1985:                        }
1986:                        _t = __t117;
1987:                        _t = _t.getNextSibling();
1988:                        if (inputState.guessing == 0) {
1989:
1990:                            if (targ != null) {
1991:                                targ.outerAltNum = this .outerAltNum;
1992:                                trackInlineAction(targ);
1993:                            }
1994:                            if (grammar.type == Grammar.LEXER) {
1995:                                grammar.altReferencesRule(currentRuleName, t,
1996:                                        this .outerAltNum);
1997:                            } else {
1998:                                grammar.altReferencesTokenID(currentRuleName,
1999:                                        t, this .outerAltNum);
2000:                            }
2001:
2002:                        }
2003:                        break;
2004:                    }
2005:                    case CHAR_LITERAL: {
2006:                        c = (GrammarAST) _t;
2007:                        match(_t, CHAR_LITERAL);
2008:                        _t = _t.getNextSibling();
2009:                        if (inputState.guessing == 0) {
2010:
2011:                            if (grammar.type != Grammar.LEXER) {
2012:                                Rule rule = grammar.getRule(currentRuleName);
2013:                                if (rule != null) {
2014:                                    rule.trackTokenReferenceInAlt(c,
2015:                                            outerAltNum);
2016:                                }
2017:                            }
2018:
2019:                        }
2020:                        break;
2021:                    }
2022:                    case STRING_LITERAL: {
2023:                        s = (GrammarAST) _t;
2024:                        match(_t, STRING_LITERAL);
2025:                        _t = _t.getNextSibling();
2026:                        if (inputState.guessing == 0) {
2027:
2028:                            if (grammar.type != Grammar.LEXER) {
2029:                                Rule rule = grammar.getRule(currentRuleName);
2030:                                if (rule != null) {
2031:                                    rule.trackTokenReferenceInAlt(s,
2032:                                            outerAltNum);
2033:                                }
2034:                            }
2035:
2036:                        }
2037:                        break;
2038:                    }
2039:                    case WILDCARD: {
2040:                        GrammarAST tmp53_AST_in = (GrammarAST) _t;
2041:                        match(_t, WILDCARD);
2042:                        _t = _t.getNextSibling();
2043:                        break;
2044:                    }
2045:                    default: {
2046:                        throw new NoViableAltException(_t);
2047:                    }
2048:                    }
2049:                } catch (RecognitionException ex) {
2050:                    if (inputState.guessing == 0) {
2051:                        reportError(ex);
2052:                        if (_t != null) {
2053:                            _t = _t.getNextSibling();
2054:                        }
2055:                    } else {
2056:                        throw ex;
2057:                    }
2058:                }
2059:                _retTree = _t;
2060:            }
2061:
2062:            public final void ebnf(AST _t) throws RecognitionException {
2063:
2064:                GrammarAST ebnf_AST_in = (_t == ASTNULL) ? null
2065:                        : (GrammarAST) _t;
2066:
2067:                try { // for error handling
2068:                    if (_t == null)
2069:                        _t = ASTNULL;
2070:                    switch (_t.getType()) {
2071:                    case BLOCK: {
2072:                        block(_t);
2073:                        _t = _retTree;
2074:                        break;
2075:                    }
2076:                    case OPTIONAL: {
2077:                        AST __t100 = _t;
2078:                        GrammarAST tmp54_AST_in = (GrammarAST) _t;
2079:                        match(_t, OPTIONAL);
2080:                        _t = _t.getFirstChild();
2081:                        block(_t);
2082:                        _t = _retTree;
2083:                        _t = __t100;
2084:                        _t = _t.getNextSibling();
2085:                        break;
2086:                    }
2087:                    default:
2088:                        boolean synPredMatched99 = false;
2089:                        if (_t == null)
2090:                            _t = ASTNULL;
2091:                        if (((_t.getType() == CLOSURE || _t.getType() == POSITIVE_CLOSURE))) {
2092:                            AST __t99 = _t;
2093:                            synPredMatched99 = true;
2094:                            inputState.guessing++;
2095:                            try {
2096:                                {
2097:                                    dotLoop(_t);
2098:                                    _t = _retTree;
2099:                                }
2100:                            } catch (RecognitionException pe) {
2101:                                synPredMatched99 = false;
2102:                            }
2103:                            _t = __t99;
2104:                            inputState.guessing--;
2105:                        }
2106:                        if (synPredMatched99) {
2107:                            dotLoop(_t);
2108:                            _t = _retTree;
2109:                        } else if ((_t.getType() == CLOSURE)) {
2110:                            AST __t101 = _t;
2111:                            GrammarAST tmp55_AST_in = (GrammarAST) _t;
2112:                            match(_t, CLOSURE);
2113:                            _t = _t.getFirstChild();
2114:                            block(_t);
2115:                            _t = _retTree;
2116:                            _t = __t101;
2117:                            _t = _t.getNextSibling();
2118:                        } else if ((_t.getType() == POSITIVE_CLOSURE)) {
2119:                            AST __t102 = _t;
2120:                            GrammarAST tmp56_AST_in = (GrammarAST) _t;
2121:                            match(_t, POSITIVE_CLOSURE);
2122:                            _t = _t.getFirstChild();
2123:                            block(_t);
2124:                            _t = _retTree;
2125:                            _t = __t102;
2126:                            _t = _t.getNextSibling();
2127:                        } else {
2128:                            throw new NoViableAltException(_t);
2129:                        }
2130:                    }
2131:                } catch (RecognitionException ex) {
2132:                    if (inputState.guessing == 0) {
2133:                        reportError(ex);
2134:                        if (_t != null) {
2135:                            _t = _t.getNextSibling();
2136:                        }
2137:                    } else {
2138:                        throw ex;
2139:                    }
2140:                }
2141:                _retTree = _t;
2142:            }
2143:
2144:            public final void tree(AST _t) throws RecognitionException {
2145:
2146:                GrammarAST tree_AST_in = (_t == ASTNULL) ? null
2147:                        : (GrammarAST) _t;
2148:
2149:                try { // for error handling
2150:                    AST __t111 = _t;
2151:                    GrammarAST tmp57_AST_in = (GrammarAST) _t;
2152:                    match(_t, TREE_BEGIN);
2153:                    _t = _t.getFirstChild();
2154:                    element(_t);
2155:                    _t = _retTree;
2156:                    {
2157:                        _loop113: do {
2158:                            if (_t == null)
2159:                                _t = ASTNULL;
2160:                            if ((_t.getType() == BLOCK
2161:                                    || _t.getType() == OPTIONAL
2162:                                    || _t.getType() == CLOSURE
2163:                                    || _t.getType() == POSITIVE_CLOSURE
2164:                                    || _t.getType() == SYNPRED
2165:                                    || _t.getType() == RANGE
2166:                                    || _t.getType() == CHAR_RANGE
2167:                                    || _t.getType() == EPSILON
2168:                                    || _t.getType() == GATED_SEMPRED
2169:                                    || _t.getType() == SYN_SEMPRED
2170:                                    || _t.getType() == BACKTRACK_SEMPRED
2171:                                    || _t.getType() == ACTION
2172:                                    || _t.getType() == ASSIGN
2173:                                    || _t.getType() == STRING_LITERAL
2174:                                    || _t.getType() == CHAR_LITERAL
2175:                                    || _t.getType() == TOKEN_REF
2176:                                    || _t.getType() == BANG
2177:                                    || _t.getType() == PLUS_ASSIGN
2178:                                    || _t.getType() == SEMPRED
2179:                                    || _t.getType() == ROOT
2180:                                    || _t.getType() == RULE_REF
2181:                                    || _t.getType() == NOT
2182:                                    || _t.getType() == TREE_BEGIN || _t
2183:                                    .getType() == WILDCARD)) {
2184:                                element(_t);
2185:                                _t = _retTree;
2186:                            } else {
2187:                                break _loop113;
2188:                            }
2189:
2190:                        } while (true);
2191:                    }
2192:                    _t = __t111;
2193:                    _t = _t.getNextSibling();
2194:                } catch (RecognitionException ex) {
2195:                    if (inputState.guessing == 0) {
2196:                        reportError(ex);
2197:                        if (_t != null) {
2198:                            _t = _t.getNextSibling();
2199:                        }
2200:                    } else {
2201:                        throw ex;
2202:                    }
2203:                }
2204:                _retTree = _t;
2205:            }
2206:
2207:            /** Track the .* and .+ idioms and make them nongreedy by default.
2208:             */
2209:            public final void dotLoop(AST _t) throws RecognitionException {
2210:
2211:                GrammarAST dotLoop_AST_in = (_t == ASTNULL) ? null
2212:                        : (GrammarAST) _t;
2213:
2214:                GrammarAST block = (GrammarAST) dotLoop_AST_in.getFirstChild();
2215:
2216:                try { // for error handling
2217:                    {
2218:                        if (_t == null)
2219:                            _t = ASTNULL;
2220:                        switch (_t.getType()) {
2221:                        case CLOSURE: {
2222:                            AST __t105 = _t;
2223:                            GrammarAST tmp58_AST_in = (GrammarAST) _t;
2224:                            match(_t, CLOSURE);
2225:                            _t = _t.getFirstChild();
2226:                            dotBlock(_t);
2227:                            _t = _retTree;
2228:                            _t = __t105;
2229:                            _t = _t.getNextSibling();
2230:                            break;
2231:                        }
2232:                        case POSITIVE_CLOSURE: {
2233:                            AST __t106 = _t;
2234:                            GrammarAST tmp59_AST_in = (GrammarAST) _t;
2235:                            match(_t, POSITIVE_CLOSURE);
2236:                            _t = _t.getFirstChild();
2237:                            dotBlock(_t);
2238:                            _t = _retTree;
2239:                            _t = __t106;
2240:                            _t = _t.getNextSibling();
2241:                            break;
2242:                        }
2243:                        default: {
2244:                            throw new NoViableAltException(_t);
2245:                        }
2246:                        }
2247:                    }
2248:                    if (inputState.guessing == 0) {
2249:
2250:                        Map opts = new HashMap();
2251:                        opts.put("greedy", "false");
2252:                        if (grammar.type != Grammar.LEXER) {
2253:                            // parser grammars assume k=1 for .* loops
2254:                            // otherwise they (analysis?) look til EOF!
2255:                            opts.put("k", Utils.integer(1));
2256:                        }
2257:                        block.setOptions(grammar, opts);
2258:
2259:                    }
2260:                } catch (RecognitionException ex) {
2261:                    if (inputState.guessing == 0) {
2262:                        reportError(ex);
2263:                        if (_t != null) {
2264:                            _t = _t.getNextSibling();
2265:                        }
2266:                    } else {
2267:                        throw ex;
2268:                    }
2269:                }
2270:                _retTree = _t;
2271:            }
2272:
2273:            public final void dotBlock(AST _t) throws RecognitionException {
2274:
2275:                GrammarAST dotBlock_AST_in = (_t == ASTNULL) ? null
2276:                        : (GrammarAST) _t;
2277:
2278:                try { // for error handling
2279:                    AST __t108 = _t;
2280:                    GrammarAST tmp60_AST_in = (GrammarAST) _t;
2281:                    match(_t, BLOCK);
2282:                    _t = _t.getFirstChild();
2283:                    AST __t109 = _t;
2284:                    GrammarAST tmp61_AST_in = (GrammarAST) _t;
2285:                    match(_t, ALT);
2286:                    _t = _t.getFirstChild();
2287:                    GrammarAST tmp62_AST_in = (GrammarAST) _t;
2288:                    match(_t, WILDCARD);
2289:                    _t = _t.getNextSibling();
2290:                    GrammarAST tmp63_AST_in = (GrammarAST) _t;
2291:                    match(_t, EOA);
2292:                    _t = _t.getNextSibling();
2293:                    _t = __t109;
2294:                    _t = _t.getNextSibling();
2295:                    GrammarAST tmp64_AST_in = (GrammarAST) _t;
2296:                    match(_t, EOB);
2297:                    _t = _t.getNextSibling();
2298:                    _t = __t108;
2299:                    _t = _t.getNextSibling();
2300:                } catch (RecognitionException ex) {
2301:                    if (inputState.guessing == 0) {
2302:                        reportError(ex);
2303:                        if (_t != null) {
2304:                            _t = _t.getNextSibling();
2305:                        }
2306:                    } else {
2307:                        throw ex;
2308:                    }
2309:                }
2310:                _retTree = _t;
2311:            }
2312:
2313:            public final void ast_suffix(AST _t) throws RecognitionException {
2314:
2315:                GrammarAST ast_suffix_AST_in = (_t == ASTNULL) ? null
2316:                        : (GrammarAST) _t;
2317:
2318:                try { // for error handling
2319:                    if (_t == null)
2320:                        _t = ASTNULL;
2321:                    switch (_t.getType()) {
2322:                    case ROOT: {
2323:                        GrammarAST tmp65_AST_in = (GrammarAST) _t;
2324:                        match(_t, ROOT);
2325:                        _t = _t.getNextSibling();
2326:                        break;
2327:                    }
2328:                    case BANG: {
2329:                        GrammarAST tmp66_AST_in = (GrammarAST) _t;
2330:                        match(_t, BANG);
2331:                        _t = _t.getNextSibling();
2332:                        break;
2333:                    }
2334:                    default: {
2335:                        throw new NoViableAltException(_t);
2336:                    }
2337:                    }
2338:                } catch (RecognitionException ex) {
2339:                    if (inputState.guessing == 0) {
2340:                        reportError(ex);
2341:                        if (_t != null) {
2342:                            _t = _t.getNextSibling();
2343:                        }
2344:                    } else {
2345:                        throw ex;
2346:                    }
2347:                }
2348:                _retTree = _t;
2349:            }
2350:
2351:            public final void rewrite_alternative(AST _t)
2352:                    throws RecognitionException {
2353:
2354:                GrammarAST rewrite_alternative_AST_in = (_t == ASTNULL) ? null
2355:                        : (GrammarAST) _t;
2356:                GrammarAST a = null;
2357:
2358:                try { // for error handling
2359:                    if (_t == null)
2360:                        _t = ASTNULL;
2361:                    if (((_t.getType() == ALT)) && (grammar.buildAST())) {
2362:                        AST __t128 = _t;
2363:                        a = _t == ASTNULL ? null : (GrammarAST) _t;
2364:                        match(_t, ALT);
2365:                        _t = _t.getFirstChild();
2366:                        {
2367:                            if (_t == null)
2368:                                _t = ASTNULL;
2369:                            switch (_t.getType()) {
2370:                            case OPTIONAL:
2371:                            case CLOSURE:
2372:                            case POSITIVE_CLOSURE:
2373:                            case LABEL:
2374:                            case ACTION:
2375:                            case STRING_LITERAL:
2376:                            case CHAR_LITERAL:
2377:                            case TOKEN_REF:
2378:                            case RULE_REF:
2379:                            case TREE_BEGIN: {
2380:                                {
2381:                                    int _cnt131 = 0;
2382:                                    _loop131: do {
2383:                                        if (_t == null)
2384:                                            _t = ASTNULL;
2385:                                        if ((_t.getType() == OPTIONAL
2386:                                                || _t.getType() == CLOSURE
2387:                                                || _t.getType() == POSITIVE_CLOSURE
2388:                                                || _t.getType() == LABEL
2389:                                                || _t.getType() == ACTION
2390:                                                || _t.getType() == STRING_LITERAL
2391:                                                || _t.getType() == CHAR_LITERAL
2392:                                                || _t.getType() == TOKEN_REF
2393:                                                || _t.getType() == RULE_REF || _t
2394:                                                .getType() == TREE_BEGIN)) {
2395:                                            rewrite_element(_t);
2396:                                            _t = _retTree;
2397:                                        } else {
2398:                                            if (_cnt131 >= 1) {
2399:                                                break _loop131;
2400:                                            } else {
2401:                                                throw new NoViableAltException(
2402:                                                        _t);
2403:                                            }
2404:                                        }
2405:
2406:                                        _cnt131++;
2407:                                    } while (true);
2408:                                }
2409:                                break;
2410:                            }
2411:                            case EPSILON: {
2412:                                GrammarAST tmp67_AST_in = (GrammarAST) _t;
2413:                                match(_t, EPSILON);
2414:                                _t = _t.getNextSibling();
2415:                                break;
2416:                            }
2417:                            default: {
2418:                                throw new NoViableAltException(_t);
2419:                            }
2420:                            }
2421:                        }
2422:                        GrammarAST tmp68_AST_in = (GrammarAST) _t;
2423:                        match(_t, EOA);
2424:                        _t = _t.getNextSibling();
2425:                        _t = __t128;
2426:                        _t = _t.getNextSibling();
2427:                    } else if (((_t.getType() == ALT
2428:                            || _t.getType() == TEMPLATE || _t.getType() == ACTION))
2429:                            && (grammar.buildTemplate())) {
2430:                        rewrite_template(_t);
2431:                        _t = _retTree;
2432:                    } else {
2433:                        throw new NoViableAltException(_t);
2434:                    }
2435:
2436:                } catch (RecognitionException ex) {
2437:                    if (inputState.guessing == 0) {
2438:                        reportError(ex);
2439:                        if (_t != null) {
2440:                            _t = _t.getNextSibling();
2441:                        }
2442:                    } else {
2443:                        throw ex;
2444:                    }
2445:                }
2446:                _retTree = _t;
2447:            }
2448:
2449:            public final void rewrite_block(AST _t) throws RecognitionException {
2450:
2451:                GrammarAST rewrite_block_AST_in = (_t == ASTNULL) ? null
2452:                        : (GrammarAST) _t;
2453:
2454:                GrammarAST enclosingBlock = currentRewriteBlock;
2455:                if (inputState.guessing == 0) { // don't do if guessing
2456:                    currentRewriteBlock = rewrite_block_AST_in; // pts to BLOCK node
2457:                    currentRewriteBlock.rewriteRefsShallow = new HashSet<GrammarAST>();
2458:                    currentRewriteBlock.rewriteRefsDeep = new HashSet<GrammarAST>();
2459:                }
2460:
2461:                try { // for error handling
2462:                    AST __t126 = _t;
2463:                    GrammarAST tmp69_AST_in = (GrammarAST) _t;
2464:                    match(_t, BLOCK);
2465:                    _t = _t.getFirstChild();
2466:                    rewrite_alternative(_t);
2467:                    _t = _retTree;
2468:                    GrammarAST tmp70_AST_in = (GrammarAST) _t;
2469:                    match(_t, EOB);
2470:                    _t = _t.getNextSibling();
2471:                    _t = __t126;
2472:                    _t = _t.getNextSibling();
2473:                    if (inputState.guessing == 0) {
2474:
2475:                        // copy the element refs in this block to the surrounding block
2476:                        if (enclosingBlock != null) {
2477:                            enclosingBlock.rewriteRefsDeep
2478:                                    .addAll(currentRewriteBlock.rewriteRefsShallow);
2479:                        }
2480:                        currentRewriteBlock = enclosingBlock; // restore old BLOCK ptr
2481:
2482:                    }
2483:                } catch (RecognitionException ex) {
2484:                    if (inputState.guessing == 0) {
2485:                        reportError(ex);
2486:                        if (_t != null) {
2487:                            _t = _t.getNextSibling();
2488:                        }
2489:                    } else {
2490:                        throw ex;
2491:                    }
2492:                }
2493:                _retTree = _t;
2494:            }
2495:
2496:            public final void rewrite_element(AST _t)
2497:                    throws RecognitionException {
2498:
2499:                GrammarAST rewrite_element_AST_in = (_t == ASTNULL) ? null
2500:                        : (GrammarAST) _t;
2501:
2502:                try { // for error handling
2503:                    if (_t == null)
2504:                        _t = ASTNULL;
2505:                    switch (_t.getType()) {
2506:                    case LABEL:
2507:                    case ACTION:
2508:                    case STRING_LITERAL:
2509:                    case CHAR_LITERAL:
2510:                    case TOKEN_REF:
2511:                    case RULE_REF: {
2512:                        rewrite_atom(_t);
2513:                        _t = _retTree;
2514:                        break;
2515:                    }
2516:                    case OPTIONAL:
2517:                    case CLOSURE:
2518:                    case POSITIVE_CLOSURE: {
2519:                        rewrite_ebnf(_t);
2520:                        _t = _retTree;
2521:                        break;
2522:                    }
2523:                    case TREE_BEGIN: {
2524:                        rewrite_tree(_t);
2525:                        _t = _retTree;
2526:                        break;
2527:                    }
2528:                    default: {
2529:                        throw new NoViableAltException(_t);
2530:                    }
2531:                    }
2532:                } catch (RecognitionException ex) {
2533:                    if (inputState.guessing == 0) {
2534:                        reportError(ex);
2535:                        if (_t != null) {
2536:                            _t = _t.getNextSibling();
2537:                        }
2538:                    } else {
2539:                        throw ex;
2540:                    }
2541:                }
2542:                _retTree = _t;
2543:            }
2544:
2545:            public final void rewrite_template(AST _t)
2546:                    throws RecognitionException {
2547:
2548:                GrammarAST rewrite_template_AST_in = (_t == ASTNULL) ? null
2549:                        : (GrammarAST) _t;
2550:                GrammarAST id = null;
2551:                GrammarAST ind = null;
2552:                GrammarAST arg = null;
2553:                GrammarAST a = null;
2554:                GrammarAST act = null;
2555:
2556:                try { // for error handling
2557:                    if (_t == null)
2558:                        _t = ASTNULL;
2559:                    switch (_t.getType()) {
2560:                    case ALT: {
2561:                        AST __t146 = _t;
2562:                        GrammarAST tmp71_AST_in = (GrammarAST) _t;
2563:                        match(_t, ALT);
2564:                        _t = _t.getFirstChild();
2565:                        GrammarAST tmp72_AST_in = (GrammarAST) _t;
2566:                        match(_t, EPSILON);
2567:                        _t = _t.getNextSibling();
2568:                        GrammarAST tmp73_AST_in = (GrammarAST) _t;
2569:                        match(_t, EOA);
2570:                        _t = _t.getNextSibling();
2571:                        _t = __t146;
2572:                        _t = _t.getNextSibling();
2573:                        break;
2574:                    }
2575:                    case TEMPLATE: {
2576:                        AST __t147 = _t;
2577:                        GrammarAST tmp74_AST_in = (GrammarAST) _t;
2578:                        match(_t, TEMPLATE);
2579:                        _t = _t.getFirstChild();
2580:                        {
2581:                            if (_t == null)
2582:                                _t = ASTNULL;
2583:                            switch (_t.getType()) {
2584:                            case ID: {
2585:                                id = (GrammarAST) _t;
2586:                                match(_t, ID);
2587:                                _t = _t.getNextSibling();
2588:                                break;
2589:                            }
2590:                            case ACTION: {
2591:                                ind = (GrammarAST) _t;
2592:                                match(_t, ACTION);
2593:                                _t = _t.getNextSibling();
2594:                                break;
2595:                            }
2596:                            default: {
2597:                                throw new NoViableAltException(_t);
2598:                            }
2599:                            }
2600:                        }
2601:                        AST __t149 = _t;
2602:                        GrammarAST tmp75_AST_in = (GrammarAST) _t;
2603:                        match(_t, ARGLIST);
2604:                        _t = _t.getFirstChild();
2605:                        {
2606:                            _loop152: do {
2607:                                if (_t == null)
2608:                                    _t = ASTNULL;
2609:                                if ((_t.getType() == ARG)) {
2610:                                    AST __t151 = _t;
2611:                                    GrammarAST tmp76_AST_in = (GrammarAST) _t;
2612:                                    match(_t, ARG);
2613:                                    _t = _t.getFirstChild();
2614:                                    arg = (GrammarAST) _t;
2615:                                    match(_t, ID);
2616:                                    _t = _t.getNextSibling();
2617:                                    a = (GrammarAST) _t;
2618:                                    match(_t, ACTION);
2619:                                    _t = _t.getNextSibling();
2620:                                    _t = __t151;
2621:                                    _t = _t.getNextSibling();
2622:                                    if (inputState.guessing == 0) {
2623:
2624:                                        a.outerAltNum = this .outerAltNum;
2625:                                        trackInlineAction(a);
2626:
2627:                                    }
2628:                                } else {
2629:                                    break _loop152;
2630:                                }
2631:
2632:                            } while (true);
2633:                        }
2634:                        _t = __t149;
2635:                        _t = _t.getNextSibling();
2636:                        if (inputState.guessing == 0) {
2637:
2638:                            if (ind != null) {
2639:                                ind.outerAltNum = this .outerAltNum;
2640:                                trackInlineAction(ind);
2641:                            }
2642:
2643:                        }
2644:                        {
2645:                            if (_t == null)
2646:                                _t = ASTNULL;
2647:                            switch (_t.getType()) {
2648:                            case DOUBLE_QUOTE_STRING_LITERAL: {
2649:                                GrammarAST tmp77_AST_in = (GrammarAST) _t;
2650:                                match(_t, DOUBLE_QUOTE_STRING_LITERAL);
2651:                                _t = _t.getNextSibling();
2652:                                break;
2653:                            }
2654:                            case DOUBLE_ANGLE_STRING_LITERAL: {
2655:                                GrammarAST tmp78_AST_in = (GrammarAST) _t;
2656:                                match(_t, DOUBLE_ANGLE_STRING_LITERAL);
2657:                                _t = _t.getNextSibling();
2658:                                break;
2659:                            }
2660:                            case 3: {
2661:                                break;
2662:                            }
2663:                            default: {
2664:                                throw new NoViableAltException(_t);
2665:                            }
2666:                            }
2667:                        }
2668:                        _t = __t147;
2669:                        _t = _t.getNextSibling();
2670:                        break;
2671:                    }
2672:                    case ACTION: {
2673:                        act = (GrammarAST) _t;
2674:                        match(_t, ACTION);
2675:                        _t = _t.getNextSibling();
2676:                        if (inputState.guessing == 0) {
2677:
2678:                            act.outerAltNum = this .outerAltNum;
2679:                            trackInlineAction(act);
2680:
2681:                        }
2682:                        break;
2683:                    }
2684:                    default: {
2685:                        throw new NoViableAltException(_t);
2686:                    }
2687:                    }
2688:                } catch (RecognitionException ex) {
2689:                    if (inputState.guessing == 0) {
2690:                        reportError(ex);
2691:                        if (_t != null) {
2692:                            _t = _t.getNextSibling();
2693:                        }
2694:                    } else {
2695:                        throw ex;
2696:                    }
2697:                }
2698:                _retTree = _t;
2699:            }
2700:
2701:            public final void rewrite_atom(AST _t) throws RecognitionException {
2702:
2703:                GrammarAST rewrite_atom_AST_in = (_t == ASTNULL) ? null
2704:                        : (GrammarAST) _t;
2705:                GrammarAST arg = null;
2706:
2707:                Rule r = grammar.getRule(currentRuleName);
2708:                Set tokenRefsInAlt = r.getTokenRefsInAlt(outerAltNum);
2709:                boolean imaginary = rewrite_atom_AST_in.getType() == TOKEN_REF
2710:                        && !tokenRefsInAlt.contains(rewrite_atom_AST_in
2711:                                .getText());
2712:                if (!imaginary
2713:                        && grammar.buildAST()
2714:                        && (rewrite_atom_AST_in.getType() == RULE_REF
2715:                                || rewrite_atom_AST_in.getType() == LABEL
2716:                                || rewrite_atom_AST_in.getType() == TOKEN_REF
2717:                                || rewrite_atom_AST_in.getType() == CHAR_LITERAL || rewrite_atom_AST_in
2718:                                .getType() == STRING_LITERAL)) {
2719:                    // track per block and for entire rewrite rule
2720:                    if (currentRewriteBlock != null) {
2721:                        currentRewriteBlock.rewriteRefsShallow
2722:                                .add(rewrite_atom_AST_in);
2723:                        currentRewriteBlock.rewriteRefsDeep
2724:                                .add(rewrite_atom_AST_in);
2725:                    }
2726:                    currentRewriteRule.rewriteRefsDeep.add(rewrite_atom_AST_in);
2727:                }
2728:
2729:                try { // for error handling
2730:                    if (_t == null)
2731:                        _t = ASTNULL;
2732:                    switch (_t.getType()) {
2733:                    case RULE_REF: {
2734:                        GrammarAST tmp79_AST_in = (GrammarAST) _t;
2735:                        match(_t, RULE_REF);
2736:                        _t = _t.getNextSibling();
2737:                        break;
2738:                    }
2739:                    case STRING_LITERAL:
2740:                    case CHAR_LITERAL:
2741:                    case TOKEN_REF: {
2742:                        {
2743:                            if (_t == null)
2744:                                _t = ASTNULL;
2745:                            switch (_t.getType()) {
2746:                            case TOKEN_REF: {
2747:                                AST __t143 = _t;
2748:                                GrammarAST tmp80_AST_in = (GrammarAST) _t;
2749:                                match(_t, TOKEN_REF);
2750:                                _t = _t.getFirstChild();
2751:                                {
2752:                                    if (_t == null)
2753:                                        _t = ASTNULL;
2754:                                    switch (_t.getType()) {
2755:                                    case ARG_ACTION: {
2756:                                        arg = (GrammarAST) _t;
2757:                                        match(_t, ARG_ACTION);
2758:                                        _t = _t.getNextSibling();
2759:                                        break;
2760:                                    }
2761:                                    case 3: {
2762:                                        break;
2763:                                    }
2764:                                    default: {
2765:                                        throw new NoViableAltException(_t);
2766:                                    }
2767:                                    }
2768:                                }
2769:                                _t = __t143;
2770:                                _t = _t.getNextSibling();
2771:                                break;
2772:                            }
2773:                            case CHAR_LITERAL: {
2774:                                GrammarAST tmp81_AST_in = (GrammarAST) _t;
2775:                                match(_t, CHAR_LITERAL);
2776:                                _t = _t.getNextSibling();
2777:                                break;
2778:                            }
2779:                            case STRING_LITERAL: {
2780:                                GrammarAST tmp82_AST_in = (GrammarAST) _t;
2781:                                match(_t, STRING_LITERAL);
2782:                                _t = _t.getNextSibling();
2783:                                break;
2784:                            }
2785:                            default: {
2786:                                throw new NoViableAltException(_t);
2787:                            }
2788:                            }
2789:                        }
2790:                        if (inputState.guessing == 0) {
2791:
2792:                            if (arg != null) {
2793:                                arg.outerAltNum = this .outerAltNum;
2794:                                trackInlineAction(arg);
2795:                            }
2796:
2797:                        }
2798:                        break;
2799:                    }
2800:                    case LABEL: {
2801:                        GrammarAST tmp83_AST_in = (GrammarAST) _t;
2802:                        match(_t, LABEL);
2803:                        _t = _t.getNextSibling();
2804:                        break;
2805:                    }
2806:                    case ACTION: {
2807:                        GrammarAST tmp84_AST_in = (GrammarAST) _t;
2808:                        match(_t, ACTION);
2809:                        _t = _t.getNextSibling();
2810:                        if (inputState.guessing == 0) {
2811:
2812:                            tmp84_AST_in.outerAltNum = this .outerAltNum;
2813:                            trackInlineAction(tmp84_AST_in);
2814:
2815:                        }
2816:                        break;
2817:                    }
2818:                    default: {
2819:                        throw new NoViableAltException(_t);
2820:                    }
2821:                    }
2822:                } catch (RecognitionException ex) {
2823:                    if (inputState.guessing == 0) {
2824:                        reportError(ex);
2825:                        if (_t != null) {
2826:                            _t = _t.getNextSibling();
2827:                        }
2828:                    } else {
2829:                        throw ex;
2830:                    }
2831:                }
2832:                _retTree = _t;
2833:            }
2834:
2835:            public final void rewrite_ebnf(AST _t) throws RecognitionException {
2836:
2837:                GrammarAST rewrite_ebnf_AST_in = (_t == ASTNULL) ? null
2838:                        : (GrammarAST) _t;
2839:
2840:                try { // for error handling
2841:                    if (_t == null)
2842:                        _t = ASTNULL;
2843:                    switch (_t.getType()) {
2844:                    case OPTIONAL: {
2845:                        AST __t134 = _t;
2846:                        GrammarAST tmp85_AST_in = (GrammarAST) _t;
2847:                        match(_t, OPTIONAL);
2848:                        _t = _t.getFirstChild();
2849:                        rewrite_block(_t);
2850:                        _t = _retTree;
2851:                        _t = __t134;
2852:                        _t = _t.getNextSibling();
2853:                        break;
2854:                    }
2855:                    case CLOSURE: {
2856:                        AST __t135 = _t;
2857:                        GrammarAST tmp86_AST_in = (GrammarAST) _t;
2858:                        match(_t, CLOSURE);
2859:                        _t = _t.getFirstChild();
2860:                        rewrite_block(_t);
2861:                        _t = _retTree;
2862:                        _t = __t135;
2863:                        _t = _t.getNextSibling();
2864:                        break;
2865:                    }
2866:                    case POSITIVE_CLOSURE: {
2867:                        AST __t136 = _t;
2868:                        GrammarAST tmp87_AST_in = (GrammarAST) _t;
2869:                        match(_t, POSITIVE_CLOSURE);
2870:                        _t = _t.getFirstChild();
2871:                        rewrite_block(_t);
2872:                        _t = _retTree;
2873:                        _t = __t136;
2874:                        _t = _t.getNextSibling();
2875:                        break;
2876:                    }
2877:                    default: {
2878:                        throw new NoViableAltException(_t);
2879:                    }
2880:                    }
2881:                } catch (RecognitionException ex) {
2882:                    if (inputState.guessing == 0) {
2883:                        reportError(ex);
2884:                        if (_t != null) {
2885:                            _t = _t.getNextSibling();
2886:                        }
2887:                    } else {
2888:                        throw ex;
2889:                    }
2890:                }
2891:                _retTree = _t;
2892:            }
2893:
2894:            public final void rewrite_tree(AST _t) throws RecognitionException {
2895:
2896:                GrammarAST rewrite_tree_AST_in = (_t == ASTNULL) ? null
2897:                        : (GrammarAST) _t;
2898:
2899:                try { // for error handling
2900:                    AST __t138 = _t;
2901:                    GrammarAST tmp88_AST_in = (GrammarAST) _t;
2902:                    match(_t, TREE_BEGIN);
2903:                    _t = _t.getFirstChild();
2904:                    rewrite_atom(_t);
2905:                    _t = _retTree;
2906:                    {
2907:                        _loop140: do {
2908:                            if (_t == null)
2909:                                _t = ASTNULL;
2910:                            if ((_t.getType() == OPTIONAL
2911:                                    || _t.getType() == CLOSURE
2912:                                    || _t.getType() == POSITIVE_CLOSURE
2913:                                    || _t.getType() == LABEL
2914:                                    || _t.getType() == ACTION
2915:                                    || _t.getType() == STRING_LITERAL
2916:                                    || _t.getType() == CHAR_LITERAL
2917:                                    || _t.getType() == TOKEN_REF
2918:                                    || _t.getType() == RULE_REF || _t.getType() == TREE_BEGIN)) {
2919:                                rewrite_element(_t);
2920:                                _t = _retTree;
2921:                            } else {
2922:                                break _loop140;
2923:                            }
2924:
2925:                        } while (true);
2926:                    }
2927:                    _t = __t138;
2928:                    _t = _t.getNextSibling();
2929:                } catch (RecognitionException ex) {
2930:                    if (inputState.guessing == 0) {
2931:                        reportError(ex);
2932:                        if (_t != null) {
2933:                            _t = _t.getNextSibling();
2934:                        }
2935:                    } else {
2936:                        throw ex;
2937:                    }
2938:                }
2939:                _retTree = _t;
2940:            }
2941:
2942:            public static final String[] _tokenNames = { "<0>", "EOF", "<2>",
2943:                    "NULL_TREE_LOOKAHEAD", "\"options\"", "\"tokens\"",
2944:                    "\"parser\"", "LEXER", "RULE", "BLOCK", "OPTIONAL",
2945:                    "CLOSURE", "POSITIVE_CLOSURE", "SYNPRED", "RANGE",
2946:                    "CHAR_RANGE", "EPSILON", "ALT", "EOR", "EOB", "EOA", "ID",
2947:                    "ARG", "ARGLIST", "RET", "LEXER_GRAMMAR", "PARSER_GRAMMAR",
2948:                    "TREE_GRAMMAR", "COMBINED_GRAMMAR", "INITACTION", "LABEL",
2949:                    "TEMPLATE", "\"scope\"", "GATED_SEMPRED", "SYN_SEMPRED",
2950:                    "BACKTRACK_SEMPRED", "\"fragment\"", "ACTION",
2951:                    "DOC_COMMENT", "SEMI", "\"lexer\"", "\"tree\"",
2952:                    "\"grammar\"", "AMPERSAND", "COLON", "RCURLY", "ASSIGN",
2953:                    "STRING_LITERAL", "CHAR_LITERAL", "INT", "STAR",
2954:                    "TOKEN_REF", "\"protected\"", "\"public\"", "\"private\"",
2955:                    "BANG", "ARG_ACTION", "\"returns\"", "\"throws\"", "COMMA",
2956:                    "LPAREN", "OR", "RPAREN", "\"catch\"", "\"finally\"",
2957:                    "PLUS_ASSIGN", "SEMPRED", "IMPLIES", "ROOT", "RULE_REF",
2958:                    "NOT", "TREE_BEGIN", "QUESTION", "PLUS", "WILDCARD",
2959:                    "REWRITE", "DOLLAR", "DOUBLE_QUOTE_STRING_LITERAL",
2960:                    "DOUBLE_ANGLE_STRING_LITERAL", "WS", "COMMENT",
2961:                    "SL_COMMENT", "ML_COMMENT", "OPEN_ELEMENT_OPTION",
2962:                    "CLOSE_ELEMENT_OPTION", "ESC", "DIGIT", "XDIGIT",
2963:                    "NESTED_ARG_ACTION", "NESTED_ACTION",
2964:                    "ACTION_CHAR_LITERAL", "ACTION_STRING_LITERAL",
2965:                    "ACTION_ESC", "WS_LOOP", "INTERNAL_RULE_REF", "WS_OPT",
2966:                    "SRC" };
2967:
2968:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.