Java Doc for NFAContext.java in  » Parser » antlr-3.0.1 » org » antlr » analysis » 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.analysis 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.antlr.analysis.NFAContext

NFAContext
public class NFAContext (Code)
A tree node for tracking the call chains for NFAs that invoke other NFAs. These trees only have to point upwards to their parents so we can walk back up the tree (i.e., pop stuff off the stack). We never walk from stack down down through the children. Each alt predicted in a decision has its own context tree, representing all possible return nodes. The initial stack has EOF ("$") in it. So, for m alternative productions, the lookahead DFA will have m NFAContext trees. To "push" a new context, just do "new NFAContext(context-parent, state)" which will add itself to the parent. The root is NFAContext(null, null). The complete context for an NFA configuration is the set of invoking states on the path from this node thru the parent pointers to the root.


Field Summary
public static  intMAX_SAME_RULE_INVOCATIONS_PER_NFA_CONFIG_STACK
     This is similar to Bermudez's m constant in his LAR(m) where you bound the stack so your states don't explode.
protected  intcachedHashCode
     Computing the hashCode is very expensive and closureBusy() uses it to track when it's seen a state|ctx before to avoid infinite loops.
public  NFAStateinvokingState
     The NFA state that invoked another rule's start state is recorded on the rule invocation context stack.
public  NFAContextparent
    

Constructor Summary
public  NFAContext(NFAContext parent, NFAState invokingState)
    

Method Summary
public  booleanconflictsWith(NFAContext other)
     Two contexts conflict() if they are equals() or one is a stack suffix of the other.
public  booleanequals(Object o)
     Two contexts are equals() if both have same call stack; walk upwards to the root. Recall that the root sentinel node has no invokingStates and no parent. Note that you may be comparing contexts in different alt trees. The hashCode is now cheap as it's computed once upon each context push on the stack.
public  inthashCode()
    
public  booleanisEmpty()
     A context is empty if there is no parent; meaning nobody pushed anything on the call stack.
public  intrecursionDepthEmanatingFromState(int state)
     Given an NFA state number, how many times has the NFA-to-DFA conversion pushed that state on the stack? In other words, the NFA state must be a rule invocation state and this method tells you how many times you've been to this state.
protected  booleansuffix(NFAContext other)
     [$] suffix any context [21 $] suffix [21 12 $] [21 12 $] suffix [21 $] [21 18 $] suffix [21 18 12 9 $] [21 18 12 9 $] suffix [21 18 $] [21 12 $] not suffix [21 9 $] Example "[21 $] suffix [21 12 $]" means: rule r invoked current rule from state 21.
public  StringtoString()
    

Field Detail
MAX_SAME_RULE_INVOCATIONS_PER_NFA_CONFIG_STACK
public static int MAX_SAME_RULE_INVOCATIONS_PER_NFA_CONFIG_STACK(Code)
This is similar to Bermudez's m constant in his LAR(m) where you bound the stack so your states don't explode. The main difference is that I bound only recursion on the stack, not the simple stack size. This looser constraint will let the conversion roam further to find lookahead to resolve a decision. Bermudez's m operates differently as it is his LR stack depth I'm pretty sure it therefore includes all stack symbols. Here I restrict the size of an NFA configuration to be finite because a stack component may mention the same NFA invocation state at most m times. Hence, the number of DFA states will not grow forever. With recursive rules like e : '(' e ')' | INT ; you could chase your tail forever if somebody said "s : e '.' | e ';' ;" This constant prevents new states from being created after a stack gets "too big". Imagine doing a depth-first search on the DFA...as you chase an input sequence you can recurse to same rule such as e above. You'd have a chain of ((((. When you get do some point, you have to give up. The states in the chain will have longer and longer NFA config stacks. Must limit size. TODO: i wonder if we can recognize recursive loops and use a simple cycle? max=0 implies you cannot ever jump to another rule during closure. max=1 implies you can make as many calls as you want--you just can't ever visit a state that is on your rule invocation stack. I.e., you cannot ever recurse. max=2 implies you are able to recurse once (i.e., call a rule twice from the same place). This tracks recursion to a rule specific to an invocation site! It does not detect multiple calls to a rule from different rule invocation states. We are guaranteed to terminate because the stack can only grow as big as the number of NFA states * max. I noticed that the Java grammar didn't work with max=1, but did with max=4. Let's set to 4. Recursion is sometimes needed to resolve some fixed lookahead decisions.



cachedHashCode
protected int cachedHashCode(Code)
Computing the hashCode is very expensive and closureBusy() uses it to track when it's seen a state|ctx before to avoid infinite loops. As we add new contexts, record the hash code as this.invokingState + parent.cachedHashCode. Avoids walking up the tree for every hashCode(). Note that this caching works because a context is a monotonically growing tree of context nodes and nothing on the stack is ever modified...ctx just grows or shrinks.



invokingState
public NFAState invokingState(Code)
The NFA state that invoked another rule's start state is recorded on the rule invocation context stack.



parent
public NFAContext parent(Code)




Constructor Detail
NFAContext
public NFAContext(NFAContext parent, NFAState invokingState)(Code)




Method Detail
conflictsWith
public boolean conflictsWith(NFAContext other)(Code)
Two contexts conflict() if they are equals() or one is a stack suffix of the other. For example, contexts [21 12 $] and [21 9 $] do not conflict, but [21 $] and [21 12 $] do conflict. Note that I should probably not show the $ in this case. There is a dummy node for each stack that just means empty; $ is a marker that's all. This is used in relation to checking conflicts associated with a single NFA state's configurations within a single DFA state. If there are configurations s and t within a DFA state such that s.state=t.state && s.alt != t.alt && s.ctx conflicts t.ctx then the DFA state predicts more than a single alt--it's nondeterministic. Two contexts conflict if they are the same or if one is a suffix of the other. When comparing contexts, if one context has a stack and the other does not then they should be considered the same context. The only way for an NFA state p to have an empty context and a nonempty context is the case when closure falls off end of rule without a call stack and re-enters the rule with a context. This resolves the issue I discussed with Sriram Srinivasan Feb 28, 2005 about not terminating fast enough upon nondeterminism.



equals
public boolean equals(Object o)(Code)
Two contexts are equals() if both have same call stack; walk upwards to the root. Recall that the root sentinel node has no invokingStates and no parent. Note that you may be comparing contexts in different alt trees. The hashCode is now cheap as it's computed once upon each context push on the stack. Use it to make equals() more efficient.



hashCode
public int hashCode()(Code)



isEmpty
public boolean isEmpty()(Code)
A context is empty if there is no parent; meaning nobody pushed anything on the call stack.



recursionDepthEmanatingFromState
public int recursionDepthEmanatingFromState(int state)(Code)
Given an NFA state number, how many times has the NFA-to-DFA conversion pushed that state on the stack? In other words, the NFA state must be a rule invocation state and this method tells you how many times you've been to this state. If none, then you have not called the target rule from this state before (though another NFA state could have called that target rule). If n=1, then you've been to this state before during this DFA construction and are going to invoke that rule again. Note that many NFA states can invoke rule r, but we ignore recursion unless you hit the same rule invocation state again.



suffix
protected boolean suffix(NFAContext other)(Code)
[$] suffix any context [21 $] suffix [21 12 $] [21 12 $] suffix [21 $] [21 18 $] suffix [21 18 12 9 $] [21 18 12 9 $] suffix [21 18 $] [21 12 $] not suffix [21 9 $] Example "[21 $] suffix [21 12 $]" means: rule r invoked current rule from state 21. Rule s invoked rule r from state 12 which then invoked current rule also via state 21. While the context prior to state 21 is different, the fact that both contexts emanate from state 21 implies that they are now going to track perfectly together. Once they converged on state 21, there is no way they can separate. In other words, the prior stack state is not consulted when computing where to go in the closure operation. ?$ and ??$ are considered the same stack. If ? is popped off then $ and ?$ remain; they are now an empty and nonempty context comparison. So, if one stack is a suffix of another, then it will still degenerate to the simple empty stack comparison case.



toString
public String toString()(Code)



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.