Java Doc for DFA.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.DFA

DFA
public class DFA (Code)
A DFA (converted from a grammar's NFA). DFAs are used as prediction machine for alternative blocks in all kinds of recognizers (lexers, parsers, tree walkers).


Field Summary
final public static  intMAX_STATES_PER_ALT_IN_DFA
     Prevent explosion of DFA states during conversion.
public static  intMAX_STATE_TRANSITIONS_FOR_TABLE
    
public static  intMAX_TIME_PER_DFA_CREATION
    
final public static  intREACHABLE_BUSY
    
final public static  intREACHABLE_NO
    
final public static  intREACHABLE_UNKNOWN
    
final public static  intREACHABLE_YES
    
public  Vectoraccept
    
protected  DFAState[]altToAcceptState
    
protected  longconversionStartTime
     Track absolute time of the conversion so we can have a failsafe: if it takes too long, then terminate.
protected  booleancyclic
    
public  NFAStatedecisionNFAStartState
    
public  intdecisionNumber
    
public  Stringdescription
    
protected  intedgeTransitionClass
     The unique edge transition class number; every time we see a new set of edges emanating from a state, we number it so we can reuse if it's every seen again for another state.
public  MapedgeTransitionClassMap
     Map an edge transition table to a unique set number; ordered so we can push into the output template as an ordered list of sets and then ref them from within the transition[][] table.
public  Vectoreof
    
public  Vectoreot
    
public  Vectormax
    
protected  intmax_k
    
public  Vectormin
    
protected  intnAlts
    
public  NFAnfa
    
protected  NFAToDFAConverternfaConverter
    
protected  intnumberOfStates
    
public  DecisionProbeprobe
     This probe tells you a lot about a decision and is useful even when there is no error such as when a syntactic nondeterminism is solved via semantic predicates.
protected  IntSetrecursiveAltSet
     Track whether an alt discovers recursion for each alt during NFA to DFA conversion; >1 alt with recursion implies nonregular.
protected  booleanreduced
    
public  Vectorspecial
    
public  ListspecialStateSTs
     List of ST for special states.
public  ListspecialStates
    
public  DFAStatestartState
    
protected  intstateCounter
    
protected  Vectorstates
     Maps the state number to the actual DFAState.
public  Vectortransition
    
public  VectortransitionEdgeTables
     just the Vector indicating which unique edge table is at position i.
protected  intuniqueCompressedSpecialStateNum
    
protected  MapuniqueStates
     A set of all uniquely-numbered DFA states.
protected  ListunreachableAlts
     Each alt in an NFA derived from a grammar must have a DFA state that predicts it lest the parser not know what to do.
protected  intuser_k
     User specified max fixed lookahead.

Constructor Summary
public  DFA(int decisionNumber, NFAState decisionStartState)
    

Method Summary
protected  DFAStateaddState(DFAState d)
     Add a new DFA state to this DFA if not already present. To force an acyclic, fixed maximum depth DFA, just always return the incoming state.
public  booleananalysisAborted()
    
public  booleancanInlineDecision()
    
protected  voidcreateEOTAndEOFTables(DFAState s)
     Set up the EOT and EOF tables; we cannot put -1 min/max values so we need another way to test that in the DFA transition function.
protected  voidcreateMinMaxTables(DFAState s)
    
protected  voidcreateSpecialTable(DFAState s)
    
public  voidcreateStateTables(CodeGenerator generator)
    
protected  voidcreateTransitionTableEntryForState(DFAState s)
    
protected  booleandoesStateReachAcceptState(DFAState d)
     figure out if this state eventually reaches an accept state and modify the instance variable 'reduced' to indicate if we find at least one state that cannot reach an accept state.
public static  StringencodeIntAsCharEscape(int v)
    
public  DFAStategetAcceptState(int alt)
    
public  booleangetAutoBacktrackMode()
    
public  GrammarASTgetDecisionASTNode()
     What GrammarAST node (derived from the grammar) is this DFA associated with? It will point to the start of a block or the loop back of a (...)+ block etc...
public  intgetDecisionNumber()
    
public  StringgetDescription()
    
public  ListgetJavaCompressedAccept()
    
public  ListgetJavaCompressedEOF()
    
public  ListgetJavaCompressedEOT()
    
public  ListgetJavaCompressedMax()
    
public  ListgetJavaCompressedMin()
    
public  ListgetJavaCompressedSpecial()
    
public  ListgetJavaCompressedTransition()
    
public  intgetMaxLookaheadDepth()
    
public  intgetMaxStateNumber()
     What is the max state number ever created? This may be beyond getNumberOfStates().
public  NFAStategetNFADecisionStartState()
    
public  intgetNumberOfAlts()
    
public  intgetNumberOfStates()
    
public  ListgetRunLengthEncoding(List data)
     Compress the incoming data list so that runs of same number are encoded as number,value pair sequences.
public  DFAStategetState(int stateNumber)
    
public  MapgetUniqueStates()
    
public  ListgetUnreachableAlts()
     Return a list of Integer alt numbers for which no lookahead could be computed or for which no single DFA accept state predicts those alts.
public  intgetUserMaxLookahead()
     The user may specify a max, acyclic lookahead for any decision.
protected  voidinitAltRelatedInfo()
    
public  booleanisCyclic()
     Is this DFA cyclic? That is, are there any loops? If not, then the DFA is essentially an LL(k) predictor for some fixed, max k value. We can build a series of nested IF statements to match this.
public  booleanisGreedy()
    
public  booleanisReduced()
     Is the DFA reduced? I.e., does every state have a path to an accept state? If not, don't delete as we need to generate an error indicating which paths are "dead ends".
public  booleanisTokensRuleDecision()
    
public  DFAStatenewState()
    
public  intpredict(IntStream input)
    
public  voidremoveState(DFAState d)
    
public  voidresetStateNumbersToBeContiguous()
     Walk all states and reset their numbers to be a contiguous sequence of integers starting from 0.
public  voidsetAcceptState(int alt, DFAState acceptState)
    
public  voidsetState(int stateNumber, DFAState d)
    
public  voidsetUserMaxLookahead(int k)
    
public  StringtoString()
    
public  voidverify()
     Once this DFA has been built, need to verify that: 1.

Field Detail
MAX_STATES_PER_ALT_IN_DFA
final public static int MAX_STATES_PER_ALT_IN_DFA(Code)
Prevent explosion of DFA states during conversion. The max number of states per alt in a single decision's DFA.



MAX_STATE_TRANSITIONS_FOR_TABLE
public static int MAX_STATE_TRANSITIONS_FOR_TABLE(Code)
How many edges can each DFA state have before a "special" state is created that uses IF expressions instead of a table?



MAX_TIME_PER_DFA_CREATION
public static int MAX_TIME_PER_DFA_CREATION(Code)
Set to 0 to not terminate early



REACHABLE_BUSY
final public static int REACHABLE_BUSY(Code)



REACHABLE_NO
final public static int REACHABLE_NO(Code)



REACHABLE_UNKNOWN
final public static int REACHABLE_UNKNOWN(Code)



REACHABLE_YES
final public static int REACHABLE_YES(Code)



accept
public Vector accept(Code)



altToAcceptState
protected DFAState[] altToAcceptState(Code)
We only want one accept state per predicted alt; track here



conversionStartTime
protected long conversionStartTime(Code)
Track absolute time of the conversion so we can have a failsafe: if it takes too long, then terminate. Assume bugs are in the analysis engine.



cyclic
protected boolean cyclic(Code)
Are there any loops in this DFA? Computed by doesStateReachAcceptState()



decisionNFAStartState
public NFAState decisionNFAStartState(Code)
From what NFAState did we create the DFA?



decisionNumber
public int decisionNumber(Code)
This DFA is being built for which decision?



description
public String description(Code)
The printable grammar fragment associated with this DFA



edgeTransitionClass
protected int edgeTransitionClass(Code)
The unique edge transition class number; every time we see a new set of edges emanating from a state, we number it so we can reuse if it's every seen again for another state. For Java grammar, some of the big edge transition tables are seen about 57 times.



edgeTransitionClassMap
public Map edgeTransitionClassMap(Code)
Map an edge transition table to a unique set number; ordered so we can push into the output template as an ordered list of sets and then ref them from within the transition[][] table. Like this for C# target: public static readonly DFA30_transition0 = new short[] { 46, 46, -1, 46, 46, -1, -1, -1, -1, -1, -1, -1,...}; public static readonly DFA30_transition1 = new short[] { 21 }; public static readonly short[][] DFA30_transition = { DFA30_transition0, DFA30_transition0, DFA30_transition1, ... };



eof
public Vector eof(Code)



eot
public Vector eot(Code)



max
public Vector max(Code)



max_k
protected int max_k(Code)
While building the DFA, track max lookahead depth if not cyclic



min
public Vector min(Code)



nAlts
protected int nAlts(Code)



nfa
public NFA nfa(Code)
Which NFA are we converting (well, which piece of the NFA)?



nfaConverter
protected NFAToDFAConverter nfaConverter(Code)



numberOfStates
protected int numberOfStates(Code)
count only new states not states that were rejected as already present



probe
public DecisionProbe probe(Code)
This probe tells you a lot about a decision and is useful even when there is no error such as when a syntactic nondeterminism is solved via semantic predicates. Perhaps a GUI would want the ability to show that.



recursiveAltSet
protected IntSet recursiveAltSet(Code)
Track whether an alt discovers recursion for each alt during NFA to DFA conversion; >1 alt with recursion implies nonregular.



reduced
protected boolean reduced(Code)
Is this DFA reduced? I.e., can all states lead to an accept state?



special
public Vector special(Code)



specialStateSTs
public List specialStateSTs(Code)
List of ST for special states.



specialStates
public List specialStates(Code)
List of special DFAState objects



startState
public DFAState startState(Code)
What's the start state for this DFA?



stateCounter
protected int stateCounter(Code)
Unique state numbers



states
protected Vector states(Code)
Maps the state number to the actual DFAState. Use a Vector as it grows automatically when I set the ith element. This contains all states, but the states are not unique. s3 might be same as s1 so s3 -> s1 in this table. This is how cycles occur. If fixed k, then these states will all be unique as states[i] always points at state i when no cycles exist. This is managed in parallel with uniqueStates and simply provides a way to go from state number to DFAState rather than via a hash lookup.



transition
public Vector transition(Code)



transitionEdgeTables
public Vector transitionEdgeTables(Code)
just the Vector indicating which unique edge table is at position i.



uniqueCompressedSpecialStateNum
protected int uniqueCompressedSpecialStateNum(Code)



uniqueStates
protected Map uniqueStates(Code)
A set of all uniquely-numbered DFA states. Maps hash of DFAState to the actual DFAState object. We use this to detect existing DFA states. Map. Use Map so we can get old state back (Set only allows you to see if it's there). Not used during fixed k lookahead as it's a waste to fill it with a dup of states array.



unreachableAlts
protected List unreachableAlts(Code)
Each alt in an NFA derived from a grammar must have a DFA state that predicts it lest the parser not know what to do. Nondeterminisms can lead to this situation (assuming no semantic predicates can resolve the problem) and when for some reason, I cannot compute the lookahead (which might arise from an error in the algorithm or from left-recursion etc...). This list starts out with all alts contained and then in method doesStateReachAcceptState() I remove the alts I know to be uniquely predicted.



user_k
protected int user_k(Code)
User specified max fixed lookahead. If 0, nothing specified. -1 implies we have not looked at the options table yet to set k.




Constructor Detail
DFA
public DFA(int decisionNumber, NFAState decisionStartState)(Code)




Method Detail
addState
protected DFAState addState(DFAState d)(Code)
Add a new DFA state to this DFA if not already present. To force an acyclic, fixed maximum depth DFA, just always return the incoming state. By not reusing old states, no cycles can be created. If we're doing fixed k lookahead don't updated uniqueStates, just return incoming state, which indicates it's a new state.



analysisAborted
public boolean analysisAborted()(Code)



canInlineDecision
public boolean canInlineDecision()(Code)



createEOTAndEOFTables
protected void createEOTAndEOFTables(DFAState s)(Code)
Set up the EOT and EOF tables; we cannot put -1 min/max values so we need another way to test that in the DFA transition function.



createMinMaxTables
protected void createMinMaxTables(DFAState s)(Code)



createSpecialTable
protected void createSpecialTable(DFAState s)(Code)



createStateTables
public void createStateTables(CodeGenerator generator)(Code)



createTransitionTableEntryForState
protected void createTransitionTableEntryForState(DFAState s)(Code)



doesStateReachAcceptState
protected boolean doesStateReachAcceptState(DFAState d)(Code)
figure out if this state eventually reaches an accept state and modify the instance variable 'reduced' to indicate if we find at least one state that cannot reach an accept state. This implies that the overall DFA is not reduced. This algorithm should be linear in the number of DFA states. The algorithm also tracks which alternatives have no accept state, indicating a nondeterminism. Also computes whether the DFA is cyclic. TODO: I call getUniquelyPredicatedAlt too much; cache predicted alt



encodeIntAsCharEscape
public static String encodeIntAsCharEscape(int v)(Code)



getAcceptState
public DFAState getAcceptState(int alt)(Code)



getAutoBacktrackMode
public boolean getAutoBacktrackMode()(Code)



getDecisionASTNode
public GrammarAST getDecisionASTNode()(Code)
What GrammarAST node (derived from the grammar) is this DFA associated with? It will point to the start of a block or the loop back of a (...)+ block etc...



getDecisionNumber
public int getDecisionNumber()(Code)



getDescription
public String getDescription()(Code)



getJavaCompressedAccept
public List getJavaCompressedAccept()(Code)



getJavaCompressedEOF
public List getJavaCompressedEOF()(Code)



getJavaCompressedEOT
public List getJavaCompressedEOT()(Code)



getJavaCompressedMax
public List getJavaCompressedMax()(Code)



getJavaCompressedMin
public List getJavaCompressedMin()(Code)



getJavaCompressedSpecial
public List getJavaCompressedSpecial()(Code)



getJavaCompressedTransition
public List getJavaCompressedTransition()(Code)



getMaxLookaheadDepth
public int getMaxLookaheadDepth()(Code)
Return k if decision is LL(k) for some k else return max int



getMaxStateNumber
public int getMaxStateNumber()(Code)
What is the max state number ever created? This may be beyond getNumberOfStates().



getNFADecisionStartState
public NFAState getNFADecisionStartState()(Code)



getNumberOfAlts
public int getNumberOfAlts()(Code)



getNumberOfStates
public int getNumberOfStates()(Code)



getRunLengthEncoding
public List getRunLengthEncoding(List data)(Code)
Compress the incoming data list so that runs of same number are encoded as number,value pair sequences. 3 -1 -1 -1 28 is encoded as 1 3 3 -1 1 28. I am pretty sure this is the lossless compression that GIF files use. Transition tables are heavily compressed by this technique. I got the idea from JFlex http://jflex.de/ Return List where each string is either \xyz for 8bit char and \uFFFF for 16bit. Hideous and specific to Java, but it is the only target bad enough to need it.



getState
public DFAState getState(int stateNumber)(Code)



getUniqueStates
public Map getUniqueStates()(Code)



getUnreachableAlts
public List getUnreachableAlts()(Code)
Return a list of Integer alt numbers for which no lookahead could be computed or for which no single DFA accept state predicts those alts. Must call verify() first before this makes sense.



getUserMaxLookahead
public int getUserMaxLookahead()(Code)
The user may specify a max, acyclic lookahead for any decision. No DFA cycles are created when this value, k, is greater than 0. If this decision has no k lookahead specified, then try the grammar.



initAltRelatedInfo
protected void initAltRelatedInfo()(Code)



isCyclic
public boolean isCyclic()(Code)
Is this DFA cyclic? That is, are there any loops? If not, then the DFA is essentially an LL(k) predictor for some fixed, max k value. We can build a series of nested IF statements to match this. In the presence of cycles, we need to build a general DFA and interpret it to distinguish between alternatives.



isGreedy
public boolean isGreedy()(Code)



isReduced
public boolean isReduced()(Code)
Is the DFA reduced? I.e., does every state have a path to an accept state? If not, don't delete as we need to generate an error indicating which paths are "dead ends". Also tracks list of alts with no accept state in the DFA. Must call verify() first before this makes sense.



isTokensRuleDecision
public boolean isTokensRuleDecision()(Code)
Is this DFA derived from the NFA for the Tokens rule?



newState
public DFAState newState()(Code)



predict
public int predict(IntStream input)(Code)



removeState
public void removeState(DFAState d)(Code)



resetStateNumbersToBeContiguous
public void resetStateNumbersToBeContiguous()(Code)
Walk all states and reset their numbers to be a contiguous sequence of integers starting from 0. Only cyclic DFA can have unused positions in states list. State i might be identical to a previous state j and will result in states[i] == states[j]. We don't want to waste a state number on this. Useful mostly for code generation in tables. At the start of this routine, states[i].stateNumber <= i by definition. If states[50].stateNumber is 50 then a cycle during conversion may try to add state 103, but we find that an identical DFA state, named 50, already exists, hence, states[103]==states[50] and both have stateNumber 50 as they point at same object. Afterwards, the set of state numbers from all states should represent a contiguous range from 0..n-1 where n is the number of unique states.



setAcceptState
public void setAcceptState(int alt, DFAState acceptState)(Code)



setState
public void setState(int stateNumber, DFAState d)(Code)



setUserMaxLookahead
public void setUserMaxLookahead(int k)(Code)



toString
public String toString()(Code)



verify
public void verify()(Code)
Once this DFA has been built, need to verify that: 1. it's reduced 2. all alts have an accept state Elsewhere, in the NFA converter, we need to verify that: 3. alts i and j have disjoint lookahead if no sem preds 4. if sem preds, nondeterministic alts must be sufficiently covered



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.