Source Code Cross Referenced for ParseTreeDebugParser.java in  » Database-ORM » toplink » persistence » antlr » debug » 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 » Database ORM » toplink » persistence.antlr.debug 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package persistence.antlr.debug;
002:
003:        /* ANTLR Translator Generator
004:         * Project led by Terence Parr at http://www.jGuru.com
005:         * Software rights: http://www.antlr.org/license.html
006:         */
007:
008:        import persistence.antlr.*;
009:        import persistence.antlr.collections.impl.BitSet;
010:
011:        import java.util.Stack;
012:
013:        /** Override the standard matching and rule entry/exit routines
014:         *  to build parse trees.  This class is useful for 2.7.3 where
015:         *  you can specify a superclass like
016:         *
017:         *   class TinyCParser extends Parser(ParseTreeDebugParser);
018:         */
019:        public class ParseTreeDebugParser extends LLkParser {
020:            /** Each new rule invocation must have it's own subtree.  Tokens
021:             *  are added to the current root so we must have a stack of subtree roots.
022:             */
023:            protected Stack currentParseTreeRoot = new Stack();
024:
025:            /** Track most recently created parse subtree so that when parsing
026:             *  is finished, we can get to the root.
027:             */
028:            protected ParseTreeRule mostRecentParseTreeRoot = null;
029:
030:            /** For every rule replacement with a production, we bump up count. */
031:            protected int numberOfDerivationSteps = 1; // n replacements plus step 0
032:
033:            public ParseTreeDebugParser(int k_) {
034:                super (k_);
035:            }
036:
037:            public ParseTreeDebugParser(ParserSharedInputState state, int k_) {
038:                super (state, k_);
039:            }
040:
041:            public ParseTreeDebugParser(TokenBuffer tokenBuf, int k_) {
042:                super (tokenBuf, k_);
043:            }
044:
045:            public ParseTreeDebugParser(TokenStream lexer, int k_) {
046:                super (lexer, k_);
047:            }
048:
049:            public ParseTree getParseTree() {
050:                return mostRecentParseTreeRoot;
051:            }
052:
053:            public int getNumberOfDerivationSteps() {
054:                return numberOfDerivationSteps;
055:            }
056:
057:            public void match(int i) throws MismatchedTokenException,
058:                    TokenStreamException {
059:                addCurrentTokenToParseTree();
060:                super .match(i);
061:            }
062:
063:            public void match(BitSet bitSet) throws MismatchedTokenException,
064:                    TokenStreamException {
065:                addCurrentTokenToParseTree();
066:                super .match(bitSet);
067:            }
068:
069:            public void matchNot(int i) throws MismatchedTokenException,
070:                    TokenStreamException {
071:                addCurrentTokenToParseTree();
072:                super .matchNot(i);
073:            }
074:
075:            /** This adds LT(1) to the current parse subtree.  Note that the match()
076:             *  routines add the node before checking for correct match.  This means
077:             *  that, upon mismatched token, there will a token node in the tree
078:             *  corresponding to where that token was expected.  For no viable
079:             *  alternative errors, no node will be in the tree as nothing was
080:             *  matched() (the lookahead failed to predict an alternative).
081:             */
082:            protected void addCurrentTokenToParseTree()
083:                    throws TokenStreamException {
084:                if (inputState.guessing > 0) {
085:                    return;
086:                }
087:                ParseTreeRule root = (ParseTreeRule) currentParseTreeRoot
088:                        .peek();
089:                ParseTreeToken tokenNode = null;
090:                if (LA(1) == Token.EOF_TYPE) {
091:                    tokenNode = new ParseTreeToken(
092:                            new persistence.antlr.CommonToken("EOF"));
093:                } else {
094:                    tokenNode = new ParseTreeToken(LT(1));
095:                }
096:                root.addChild(tokenNode);
097:            }
098:
099:            /** Create a rule node, add to current tree, and make it current root */
100:            public void traceIn(String s) throws TokenStreamException {
101:                if (inputState.guessing > 0) {
102:                    return;
103:                }
104:                ParseTreeRule subRoot = new ParseTreeRule(s);
105:                if (currentParseTreeRoot.size() > 0) {
106:                    ParseTreeRule oldRoot = (ParseTreeRule) currentParseTreeRoot
107:                            .peek();
108:                    oldRoot.addChild(subRoot);
109:                }
110:                currentParseTreeRoot.push(subRoot);
111:                numberOfDerivationSteps++;
112:            }
113:
114:            /** Pop current root; back to adding to old root */
115:            public void traceOut(String s) throws TokenStreamException {
116:                if (inputState.guessing > 0) {
117:                    return;
118:                }
119:                mostRecentParseTreeRoot = (ParseTreeRule) currentParseTreeRoot
120:                        .pop();
121:            }
122:
123:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.