Source Code Cross Referenced for TreeParser.java in  » IDE-Netbeans » cnd » antlr » 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 » IDE Netbeans » cnd » antlr 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package antlr;
002:
003:        /* ANTLR Translator Generator
004:         * Project led by Terence Parr at http://www.cs.usfca.edu
005:         * Software rights: http://www.antlr.org/license.html
006:         */
007:
008:        import antlr.collections.AST;
009:        import antlr.collections.impl.BitSet;
010:
011:        public class TreeParser extends MatchExceptionState {
012:            /** The AST Null object; the parsing cursor is set to this when
013:             *  it is found to be null.  This way, we can test the
014:             *  token type of a node without having to have tests for null
015:             *  everywhere.
016:             */
017:            public static ASTNULLType ASTNULL = new ASTNULLType();
018:
019:            /** Where did this rule leave off parsing; avoids a return parameter */
020:            protected AST _retTree;
021:
022:            /** guessing nesting level; guessing==0 implies not guessing */
023:            // protected int guessing = 0;
024:            /** Nesting level of registered handlers */
025:            // protected int exceptionLevel = 0;
026:            protected TreeParserSharedInputState inputState;
027:
028:            /** Table of token type to token names */
029:            protected String[] tokenNames;
030:
031:            /** AST return value for a rule is squirreled away here */
032:            protected AST returnAST;
033:
034:            /** AST support code; parser and treeparser delegate to this object */
035:            protected ASTFactory astFactory = new ASTFactory();
036:
037:            /** Used to keep track of indentdepth for traceIn/Out */
038:            protected int traceDepth = 0;
039:
040:            public TreeParser() {
041:                inputState = new TreeParserSharedInputState();
042:            }
043:
044:            /** Get the AST return value squirreled away in the parser */
045:            public AST getAST() {
046:                return returnAST;
047:            }
048:
049:            public ASTFactory getASTFactory() {
050:                return astFactory;
051:            }
052:
053:            public String getTokenName(int num) {
054:                return tokenNames[num];
055:            }
056:
057:            public String[] getTokenNames() {
058:                return tokenNames;
059:            }
060:
061:            protected void match(AST t, int ttype)
062:                    throws MismatchedTokenException {
063:                //System.out.println("match("+ttype+"); cursor is "+t);
064:                if (t == null || t == ASTNULL || t.getType() != ttype) {
065:                    throw new MismatchedTokenException(getTokenNames(), t,
066:                            ttype, false);
067:                }
068:            }
069:
070:            /**Make sure current lookahead symbol matches the given set
071:             * Throw an exception upon mismatch, which is catch by either the
072:             * error handler or by the syntactic predicate.
073:             */
074:            public void match(AST t, BitSet b) throws MismatchedTokenException {
075:                if (t == null || t == ASTNULL || !b.member(t.getType())) {
076:                    throw new MismatchedTokenException(getTokenNames(), t, b,
077:                            false);
078:                }
079:            }
080:
081:            protected void matchNot(AST t, int ttype)
082:                    throws MismatchedTokenException {
083:                //System.out.println("match("+ttype+"); cursor is "+t);
084:                if (t == null || t == ASTNULL || t.getType() == ttype) {
085:                    throw new MismatchedTokenException(getTokenNames(), t,
086:                            ttype, true);
087:                }
088:            }
089:
090:            /** @deprecated as of 2.7.2. This method calls System.exit() and writes
091:             *  directly to stderr, which is usually not appropriate when
092:             *  a parser is embedded into a larger application. Since the method is 
093:             *  <code>static</code>, it cannot be overridden to avoid these problems.
094:             *  ANTLR no longer uses this method internally or in generated code.
095:             */
096:            public static void panic() {
097:                System.err.println("TreeWalker: panic");
098:                Utils.error("");
099:            }
100:
101:            /** Parser error-reporting function can be overridden in subclass */
102:            public void reportError(RecognitionException ex) {
103:                System.err.println(ex.toString());
104:            }
105:
106:            /** Parser error-reporting function can be overridden in subclass */
107:            public void reportError(String s) {
108:                System.err.println("error: " + s);
109:            }
110:
111:            /** Parser warning-reporting function can be overridden in subclass */
112:            public void reportWarning(String s) {
113:                System.err.println("warning: " + s);
114:            }
115:
116:            /** Specify an object with support code (shared by
117:             *  Parser and TreeParser.  Normally, the programmer
118:             *  does not play with this, using setASTNodeType instead.
119:             */
120:            public void setASTFactory(ASTFactory f) {
121:                astFactory = f;
122:            }
123:
124:            /** Specify the type of node to create during tree building.
125:             * 	@deprecated since 2.7.2
126:             */
127:            public void setASTNodeType(String nodeType) {
128:                setASTNodeClass(nodeType);
129:            }
130:
131:            /** Specify the type of node to create during tree building */
132:            public void setASTNodeClass(String nodeType) {
133:                astFactory.setASTNodeClass(nodeType);
134:            }
135:
136:            public void traceIndent() {
137:                for (int i = 0; i < traceDepth; i++)
138:                    System.out.print(" ");
139:            }
140:
141:            public void traceIn(String rname, AST t) {
142:                traceDepth += 1;
143:                traceIndent();
144:                System.out.println("> " + rname + "("
145:                        + (t != null ? t.toString() : "null") + ")"
146:                        + ((inputState.guessing > 0) ? " [guessing]" : ""));
147:            }
148:
149:            public void traceOut(String rname, AST t) {
150:                traceIndent();
151:                System.out.println("< " + rname + "("
152:                        + (t != null ? t.toString() : "null") + ")"
153:                        + ((inputState.guessing > 0) ? " [guessing]" : ""));
154:                traceDepth--;
155:            }
156:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.