Java Doc for DFAState.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.State
      org.antlr.analysis.DFAState

DFAState
public class DFAState extends State (Code)
A DFA state represents a set of possible NFA configurations. As Aho, Sethi, Ullman p. 117 says "The DFA uses its state to keep track of all possible states the NFA can be in after reading each input symbol. That is to say, after reading input a1a2..an, the DFA is in a state that represents the subset T of the states of the NFA that are reachable from the NFA's start state along some path labeled a1a2..an." In conventional NFA->DFA conversion, therefore, the subset T would be a bitset representing the set of states the NFA could be in. We need to track the alt predicted by each state as well, however. More importantly, we need to maintain a stack of states, tracking the closure operations as they jump from rule to rule, emulating rule invocations (method calls). Recall that NFAs do not normally have a stack like a pushdown-machine so I have to add one to simulate the proper lookahead sequences for the underlying LL grammar from which the NFA was derived. I use a list of NFAConfiguration objects. An NFAConfiguration is both a state (ala normal conversion) and an NFAContext describing the chain of rules (if any) followed to arrive at that state. There is also the semantic context, which is the "set" of predicates found on the path to this configuration. A DFA state may have multiple references to a particular state, but with different NFAContexts (with same or different alts) meaning that state was reached via a different set of rule invocations.


Field Summary
final public static  intINITIAL_NUM_TRANSITIONS
    
final public static  intPREDICTED_ALT_UNSET
    
protected  booleanabortedDueToMultipleRecursiveAlts
     If we detect recursion on more than one alt, decision is non-LL(*), but try to isolate it to only those states whose closure operations detect recursion.
protected  booleanabortedDueToRecursionOverflow
     If a closure operation finds that we tried to invoke the same rule too many times (stack would grow beyond a threshold), it marks the state has aborted and notifies the DecisionProbe.
protected  intacceptStateReachable
     The NFA->DFA algorithm may terminate leaving some states without a path to an accept state, implying that upon certain input, the decision is not deterministic--no decision about predicting a unique alternative can be made.
protected  intcachedHashCode
     Build up the hash code for this state as NFA configurations are added as it's monotonically increasing list of configurations.
protected  intcachedUniquelyPredicatedAlt
    
protected  SetclosureBusy
     Used to prevent the closure operation from looping to itself and hence looping forever.
public  DFAdfa
     We are part of what DFA? Use this ref to get access to the context trees for an alt.
protected  intk
     When doing an acyclic DFA, this is the number of lookahead symbols consumed to reach this state.
protected  SetnfaConfigurations
    
protected  OrderedHashSetreachableLabels
     As this state is constructed (i.e., as NFA states are added), we can easily check for non-epsilon transitions because the only transition that could be a valid label is transition(0).
protected  booleanresolvedWithPredicates
     Rather than recheck every NFA configuration in a DFA state (after resolving) in findNewDFAStatesAndAddDFATransitions just check this boolean.
protected  Listtransitions
     Track the transitions emanating from this DFA state.

Constructor Summary
public  DFAState(DFA dfa)
    

Method Summary
public  voidaddNFAConfiguration(NFAState state, NFAConfiguration c)
     Add an NFA configuration to this DFA node.
public  voidaddNFAConfiguration(NFAState state, int alt, NFAContext context, SemanticContext semanticContext)
    
protected  voidaddReachableLabel(Label label)
     Add label uniquely and disjointly; intersection with another set or int/char forces breaking up the set(s). Example, if reachable list of labels is [a..z, {k,9}, 0..9], the disjoint list will be [{a..j,l..z}, k, 9, 0..8]. As we add NFA configurations to a DFA state, we might as well track the set of all possible transition labels to make the DFA conversion more efficient.
public  voidaddTransition(Transition t)
    
public  intaddTransition(DFAState target, Label label)
     Add a transition from this state to target with label.
public  booleanequals(Object o)
     Two DFAStates are equal if their NFA configuration sets are the same.
public  intgetAcceptStateReachable()
    
public  SetgetAltSet()
     Get the set of all alts mentioned by all NFA configurations in this DFA state.
protected  SetgetConflictingAlts()
     Walk each NFA configuration in this DFA state looking for a conflict where (s|i|ctx) and (s|j|ctx) exist, indicating that state s with context conflicting ctx predicts alts i and j.
public  SetgetDisabledAlternatives()
     When more than one alternative can match the same input, the first alternative is chosen to resolve the conflict.
public  SemanticContextgetGatedPredicatesInNFAConfigurations()
     For gated productions, we need an OR'd list of all predicates for the target of an edge so we can gate the edge based upon the predicates associated with taking that path (if any). For syntactic predicates, we only want to generate predicate evaluations as it transitions to an accept state; waste to do it earlier.
public  intgetLookaheadDepth()
    
public  SetgetNFAConfigurations()
    
public  SetgetNFAStatesForAlt(int alt)
     Get the set of all states mentioned by all NFA configurations in this DFA state associated with alt.
protected  SetgetNonDeterministicAlts()
    
public  intgetNumberOfTransitions()
    
public  OrderedHashSetgetReachableLabels()
    
public  SetgetSyntacticPredicatesInNFAConfigurations()
     For gated productions, we need a list of all predicates for the target of an edge so we can gate the edge based upon the predicates associated with taking that path (if any).
public  TransitiongetTransition(int trans)
    
public  intgetUniqueAlt()
     Return the uniquely mentioned alt from the NFA configurations; Ignore the resolved bit etc...
public  intgetUniquelyPredictedAlt()
     Walk each configuration and if they are all the same alt, return that alt else return NFA.INVALID_ALT_NUMBER.
public  inthashCode()
     A decent hash for a DFA state is the sum of the NFA state/alt pairs. This is used when we add DFAState objects to the DFA.states Map and when we compare DFA states.
public  booleanisResolvedWithPredicates()
    
public  voidremoveTransition(int trans)
    
public  voidsetAcceptStateReachable(int acceptStateReachable)
    
public  voidsetLookaheadDepth(int k)
    
public  voidsetNFAConfigurations(Set configs)
    
public  StringtoString()
    
public  Transitiontransition(int i)
    

Field Detail
INITIAL_NUM_TRANSITIONS
final public static int INITIAL_NUM_TRANSITIONS(Code)



PREDICTED_ALT_UNSET
final public static int PREDICTED_ALT_UNSET(Code)



abortedDueToMultipleRecursiveAlts
protected boolean abortedDueToMultipleRecursiveAlts(Code)
If we detect recursion on more than one alt, decision is non-LL(*), but try to isolate it to only those states whose closure operations detect recursion. There may be other alts that are cool: a : recur '.' | recur ';' | X Y // LL(2) decision; don't abort and use k=1 plus backtracking | X Z ;



abortedDueToRecursionOverflow
protected boolean abortedDueToRecursionOverflow(Code)
If a closure operation finds that we tried to invoke the same rule too many times (stack would grow beyond a threshold), it marks the state has aborted and notifies the DecisionProbe.



acceptStateReachable
protected int acceptStateReachable(Code)
The NFA->DFA algorithm may terminate leaving some states without a path to an accept state, implying that upon certain input, the decision is not deterministic--no decision about predicting a unique alternative can be made. Recall that an accept state is one in which a unique alternative is predicted.



cachedHashCode
protected int cachedHashCode(Code)
Build up the hash code for this state as NFA configurations are added as it's monotonically increasing list of configurations.



cachedUniquelyPredicatedAlt
protected int cachedUniquelyPredicatedAlt(Code)



closureBusy
protected Set closureBusy(Code)
Used to prevent the closure operation from looping to itself and hence looping forever. Sensitive to the NFA state, the alt, and the context. This just the nfa config set because we want to prevent closures only on states contributed by closure not reach operations.



dfa
public DFA dfa(Code)
We are part of what DFA? Use this ref to get access to the context trees for an alt.



k
protected int k(Code)
When doing an acyclic DFA, this is the number of lookahead symbols consumed to reach this state. This value may be nonzero for most dfa states, but it is only a valid value if the user has specified a max fixed lookahead.



nfaConfigurations
protected Set nfaConfigurations(Code)
The set of NFA configurations (state,alt,context) for this DFA state



reachableLabels
protected OrderedHashSet reachableLabels(Code)
As this state is constructed (i.e., as NFA states are added), we can easily check for non-epsilon transitions because the only transition that could be a valid label is transition(0). When we process this node eventually, we'll have to walk all states looking for all possible transitions. That is of the order: size(label space) times size(nfa states), which can be pretty damn big. It's better to simply track possible labels. This is type List



resolvedWithPredicates
protected boolean resolvedWithPredicates(Code)
Rather than recheck every NFA configuration in a DFA state (after resolving) in findNewDFAStatesAndAddDFATransitions just check this boolean. Saves a linear walk perhaps DFA state creation. Every little bit helps.



transitions
protected List transitions(Code)
Track the transitions emanating from this DFA state. The List elements are Transition objects.




Constructor Detail
DFAState
public DFAState(DFA dfa)(Code)




Method Detail
addNFAConfiguration
public void addNFAConfiguration(NFAState state, NFAConfiguration c)(Code)
Add an NFA configuration to this DFA node. Add uniquely an NFA state/alt/syntactic&semantic context (chain of invoking state(s) and semantic predicate contexts). I don't see how there could be two configurations with same state|alt|synCtx and different semantic contexts because the semantic contexts are computed along the path to a particular state so those two configurations would have to have the same predicate. Nonetheless, the addition of configurations is unique on all configuration info. I guess I'm saying that syntactic context implies semantic context as the latter is computed according to the former. As we add configurations to this DFA state, track the set of all possible transition labels so we can simply walk it later rather than doing a loop over all possible labels in the NFA.



addNFAConfiguration
public void addNFAConfiguration(NFAState state, int alt, NFAContext context, SemanticContext semanticContext)(Code)



addReachableLabel
protected void addReachableLabel(Label label)(Code)
Add label uniquely and disjointly; intersection with another set or int/char forces breaking up the set(s). Example, if reachable list of labels is [a..z, {k,9}, 0..9], the disjoint list will be [{a..j,l..z}, k, 9, 0..8]. As we add NFA configurations to a DFA state, we might as well track the set of all possible transition labels to make the DFA conversion more efficient. W/o the reachable labels, we'd need to check the whole vocabulary space (could be 0..\uFFFF)! The problem is that labels can be sets, which may overlap with int labels or other sets. As we need a deterministic set of transitions from any state in the DFA, we must make the reachable labels set disjoint. This operation amounts to finding the character classes for this DFA state whereas with tools like flex, that need to generate a homogeneous DFA, must compute char classes across all states. We are going to generate DFAs with heterogeneous states so we only care that the set of transitions out of a single state are unique. :) The idea for adding a new set, t, is to look for overlap with the elements of existing list s. Upon overlap, replace existing set s[i] with two new disjoint sets, s[i]-t and s[i]&t. (if s[i]-t is nil, don't add). The remainder is t-s[i], which is what you want to add to the set minus what was already there. The remainder must then be compared against the i+1..n elements in s looking for another collision. Each collision results in a smaller and smaller remainder. Stop when you run out of s elements or remainder goes to nil. If remainder is non nil when you run out of s elements, then add remainder to the end. Single element labels are treated as sets to make the code uniform.



addTransition
public void addTransition(Transition t)(Code)



addTransition
public int addTransition(DFAState target, Label label)(Code)
Add a transition from this state to target with label. Return the transition number from 0..n-1.



equals
public boolean equals(Object o)(Code)
Two DFAStates are equal if their NFA configuration sets are the same. This method is used to see if a DFA state already exists. Because the number of alternatives and number of NFA configurations are finite, there is a finite number of DFA states that can be processed. This is necessary to show that the algorithm terminates. Cannot test the state numbers here because in DFA.addState we need to know if any other state exists that has this exact set of NFA configurations. The DFAState state number is irrelevant.



getAcceptStateReachable
public int getAcceptStateReachable()(Code)
Is an accept state reachable from this state?



getAltSet
public Set getAltSet()(Code)
Get the set of all alts mentioned by all NFA configurations in this DFA state.



getConflictingAlts
protected Set getConflictingAlts()(Code)
Walk each NFA configuration in this DFA state looking for a conflict where (s|i|ctx) and (s|j|ctx) exist, indicating that state s with context conflicting ctx predicts alts i and j. Return an Integer set of the alternative numbers that conflict. Two contexts conflict if they are equal or one is a stack suffix of the other or one is the empty context. Use a hash table to record the lists of configs for each state as they are encountered. We need only consider states for which there is more than one configuration. The configurations' predicted alt must be different or must have different contexts to avoid a conflict. Don't report conflicts for DFA states that have conflicting Tokens rule NFA states; they will be resolved in favor of the first rule.



getDisabledAlternatives
public Set getDisabledAlternatives()(Code)
When more than one alternative can match the same input, the first alternative is chosen to resolve the conflict. The other alts are "turned off" by setting the "resolved" flag in the NFA configurations. Return the set of disabled alternatives. For a : A | A | A ; this method returns {2,3} as disabled. This does not mean that the alternative is totally unreachable, it just means that for this DFA state, that alt is disabled. There may be other accept states for that alt.



getGatedPredicatesInNFAConfigurations
public SemanticContext getGatedPredicatesInNFAConfigurations()(Code)
For gated productions, we need an OR'd list of all predicates for the target of an edge so we can gate the edge based upon the predicates associated with taking that path (if any). For syntactic predicates, we only want to generate predicate evaluations as it transitions to an accept state; waste to do it earlier. So, only add gated preds derived from manually- specified syntactic predicates if this is an accept state. Also, since configurations w/o gated predicates are like true gated predicates, finding a configuration whose alt has no gated predicate implies we should evaluate the predicate to true. This means the whole edge has to be ungated. Consider: X : ('a' | {p}?=> 'a') | 'a' 'b' ; Here, you 'a' gets you from s0 to s1 but you can't test p because plain 'a' is ok. It's also ok for starting alt 2. Hence, you can't test p. Even on the edge going to accept state for alt 1 of X, you can't test p. You can get to the same place with and w/o the context. Therefore, it is never ok to test p in this situation. TODO: cache this as it's called a lot; or at least set bit if >1 present in state



getLookaheadDepth
public int getLookaheadDepth()(Code)



getNFAConfigurations
public Set getNFAConfigurations()(Code)



getNFAStatesForAlt
public Set getNFAStatesForAlt(int alt)(Code)
Get the set of all states mentioned by all NFA configurations in this DFA state associated with alt.



getNonDeterministicAlts
protected Set getNonDeterministicAlts()(Code)
public int getNumberOfEOTNFAStates() { int n = 0; Iterator iter = nfaConfigurations.iterator(); NFAConfiguration configuration; while (iter.hasNext()) { configuration = (NFAConfiguration) iter.next(); NFAState s = dfa.nfa.getState(configuration.state); if ( s.isEOTState() ) { n++; } } return n; }



getNumberOfTransitions
public int getNumberOfTransitions()(Code)



getReachableLabels
public OrderedHashSet getReachableLabels()(Code)



getSyntacticPredicatesInNFAConfigurations
public Set getSyntacticPredicatesInNFAConfigurations()(Code)
For gated productions, we need a list of all predicates for the target of an edge so we can gate the edge based upon the predicates associated with taking that path (if any). experimental 11/29/2005 public Set getGatedPredicatesInNFAConfigurations() { Set preds = new HashSet(); Iterator iter = nfaConfigurations.iterator(); NFAConfiguration configuration; while (iter.hasNext()) { configuration = (NFAConfiguration) iter.next(); if ( configuration.semanticContext.isGated() ) { preds.add(configuration.semanticContext); } } if ( preds.size()==0 ) { return null; } return preds; }



getTransition
public Transition getTransition(int trans)(Code)



getUniqueAlt
public int getUniqueAlt()(Code)
Return the uniquely mentioned alt from the NFA configurations; Ignore the resolved bit etc... Return INVALID_ALT_NUMBER if there is more than one alt mentioned.



getUniquelyPredictedAlt
public int getUniquelyPredictedAlt()(Code)
Walk each configuration and if they are all the same alt, return that alt else return NFA.INVALID_ALT_NUMBER. Ignore resolved configurations, but don't ignore resolveWithPredicate configs because this state should not be an accept state. We need to add this to the work list and then have semantic predicate edges emanating from it.



hashCode
public int hashCode()(Code)
A decent hash for a DFA state is the sum of the NFA state/alt pairs. This is used when we add DFAState objects to the DFA.states Map and when we compare DFA states. Computed in addNFAConfiguration()



isResolvedWithPredicates
public boolean isResolvedWithPredicates()(Code)



removeTransition
public void removeTransition(int trans)(Code)



setAcceptStateReachable
public void setAcceptStateReachable(int acceptStateReachable)(Code)



setLookaheadDepth
public void setLookaheadDepth(int k)(Code)



setNFAConfigurations
public void setNFAConfigurations(Set configs)(Code)



toString
public String toString()(Code)
Print all NFA states plus what alts they predict



transition
public Transition transition(int i)(Code)



Fields inherited from org.antlr.analysis.State
final public static int INVALID_STATE_NUMBER(Code)(Java Doc)
protected boolean acceptState(Code)(Java Doc)
public int stateNumber(Code)(Java Doc)

Methods inherited from org.antlr.analysis.State
abstract public void addTransition(Transition e)(Code)(Java Doc)
abstract public int getNumberOfTransitions()(Code)(Java Doc)
public boolean isAcceptState()(Code)(Java Doc)
public void setAcceptState(boolean acceptState)(Code)(Java Doc)
abstract public Transition transition(int i)(Code)(Java Doc)

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.