| Modifier and Type | Field and Description |
|---|---|
| public Vector | |
| protected DFAState[] | altToAcceptState
We only want one accept state per predicted alt; track here |
| protected boolean | cyclic
Are there any loops in this DFA? |
| public static final int | |
| public static final int | |
| public static final int | |
| public NFAState | decisionNFAStartState
From what NFAState did we create the DFA? |
| public int | decisionNumber
This DFA is being built for which decision? |
| public String | description
The printable grammar fragment associated with this DFA |
| protected int | edgeTransitionClass
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 Map | edgeTransitionClassMap
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 Vector | |
| public Vector | |
| protected CodeGenerator | generator
Which generator to use if we're building state tables |
| public boolean | |
| public Vector | |
| protected int | max_k
While building the DFA, track max lookahead depth if not cyclic |
| public static int | MAX_STATE_TRANSITIONS_FOR_TABLE
How many edges can each DFA state have before a "special" state is created that uses IF expressions instead of a table? |
| public static int | MAX_TIME_PER_DFA_CREATION
Set to 0 to not terminate early (time in ms) |
| public Vector | |
| protected int | |
| public NFA | nfa
Which NFA are we converting (well, which piece of the NFA)? |
| protected NFAToDFAConverter | |
| protected int | numberOfStates
count only new states not states that were rejected as already present |
| public boolean | predicateVisible
Track whether this DFA has at least one sem/syn pred encountered during a closure operation. |
| public DecisionProbe | probe
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. |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public IntSet | recursiveAltSet
Track whether an alt discovers recursion for each alt during NFA to DFA conversion; >1 alt with recursion implies nonregular. |
| protected boolean | reduced
Is this DFA reduced? |
| public Vector | |
| public List | specialStates
List of special DFAState objects |
| public List | specialStateSTs
List of ST for special states. |
| public DFAState | startState
What's the start state for this DFA? |
| protected int | stateCounter
Unique state numbers per DFA |
| protected Vector | states
Maps the state number to the actual DFAState. |
| public Vector | |
| public Vector | transitionEdgeTables
just the Vector<Integer> indicating which unique edge table is at position i. |
| protected int | |
| protected Map | uniqueStates
A set of all uniquely-numbered DFA states. |
| protected List | unreachableAlts
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 int | user_k
User specified max fixed lookahead. |
| Access | Constructor and Description |
|---|---|
| protected | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv int | |
| pack-priv boolean | |
| pack-priv boolean | |
| pack-priv boolean | |
| protected DFAState | |
| public boolean | |
| protected void | createEOTAndEOFTables(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 void | |
| protected void | |
| public void | |
| protected void | |
| protected boolean | doesStateReachAcceptState(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 void | findAllGatedSynPredsUsedInDFAAcceptStates()
Walk all accept states and find the manually-specified synpreds. |
| public DFAState | |
| public boolean | |
| public GrammarAST | |
| public int | |
| public String | |
| public boolean | |
| public List | |
| public List | |
| public List | |
| public List | |
| public List | |
| public List | |
| public List | |
| public int | |
| public int | |
| public NFAState | |
| public int | |
| public int | |
| public String | |
| public List | getRunLengthEncoding(List<Integer> data)
Compress the incoming data list so that runs of same number are encoded as number,value pair sequences. |
| public DFAState | |
| public Map | |
| public List | getUnreachableAlts()
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 int | |
| public boolean | |
| public boolean | |
| public boolean | hasSynPred()
Count all disambiguating syn preds (ignore synpred tests for gated edges, which occur for nonambig input sequences). |
| protected void | |
| public boolean | |
| public boolean | |
| public boolean | |
| public boolean | |
| public boolean | |
| public DFAState | |
| public boolean | okToRetryDFAWithK1()
If this DFA failed to finish during construction, we might be able to retry with k=1 but we need to know whether it will potentially succeed. |
| public int | |
| public void | |
| public void | resetStateNumbersToBeContiguous()
Walk all states and reset their numbers to be a contiguous sequence of integers starting from 0. |
| public void | |
| public void | |
| public void | |
| public String | |
| public void |
| accept | back to summary |
|---|---|
| public Vector<Integer> accept | |
| altToAcceptState | back to summary |
|---|---|
| protected DFAState[] altToAcceptState We only want one accept state per predicted alt; track here | |
| cyclic | back to summary |
|---|---|
| protected boolean cyclic Are there any loops in this DFA? Computed by doesStateReachAcceptState() | |
| CYCLIC_BUSY | back to summary |
|---|---|
| public static final int CYCLIC_BUSY | |
| CYCLIC_DONE | back to summary |
|---|---|
| public static final int CYCLIC_DONE | |
| CYCLIC_UNKNOWN | back to summary |
|---|---|
| public static final int CYCLIC_UNKNOWN | |
| decisionNFAStartState | back to summary |
|---|---|
| public NFAState decisionNFAStartState From what NFAState did we create the DFA? | |
| decisionNumber | back to summary |
|---|---|
| public int decisionNumber This DFA is being built for which decision? | |
| description | back to summary |
|---|---|
| public String description The printable grammar fragment associated with this DFA | |
| edgeTransitionClass | back to summary |
|---|---|
| protected int edgeTransitionClass 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 | back to summary |
|---|---|
| public Map<List<Integer>, Integer> edgeTransitionClassMap 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 | back to summary |
|---|---|
| public Vector<Integer> eof | |
| eot | back to summary |
|---|---|
| public Vector<Integer> eot | |
| generator | back to summary |
|---|---|
| protected CodeGenerator generator Which generator to use if we're building state tables | |
| hasPredicateBlockedByAction | back to summary |
|---|---|
| public boolean hasPredicateBlockedByAction | |
| max | back to summary |
|---|---|
| public Vector<Integer> max | |
| max_k | back to summary |
|---|---|
| protected int max_k While building the DFA, track max lookahead depth if not cyclic | |
| MAX_STATE_TRANSITIONS_FOR_TABLE | back to summary |
|---|---|
| public static int MAX_STATE_TRANSITIONS_FOR_TABLE 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 | back to summary |
|---|---|
| public static int MAX_TIME_PER_DFA_CREATION Set to 0 to not terminate early (time in ms) | |
| min | back to summary |
|---|---|
| public Vector<Integer> min | |
| nAlts | back to summary |
|---|---|
| protected int nAlts | |
| nfa | back to summary |
|---|---|
| public NFA nfa Which NFA are we converting (well, which piece of the NFA)? | |
| nfaConverter | back to summary |
|---|---|
| protected NFAToDFAConverter nfaConverter | |
| numberOfStates | back to summary |
|---|---|
| protected int numberOfStates count only new states not states that were rejected as already present | |
| predicateVisible | back to summary |
|---|---|
| public boolean predicateVisible Track whether this DFA has at least one sem/syn pred encountered during a closure operation. This is useful for deciding whether to retry a non-LL(*) with k=1. If no pred, it will not work w/o a pred so don't bother. It would just give another error message. | |
| probe | back to summary |
|---|---|
| public DecisionProbe probe 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. | |
| REACHABLE_BUSY | back to summary |
|---|---|
| public static final int REACHABLE_BUSY | |
| REACHABLE_NO | back to summary |
|---|---|
| public static final int REACHABLE_NO | |
| REACHABLE_UNKNOWN | back to summary |
|---|---|
| public static final int REACHABLE_UNKNOWN | |
| REACHABLE_YES | back to summary |
|---|---|
| public static final int REACHABLE_YES | |
| recursiveAltSet | back to summary |
|---|---|
| public IntSet recursiveAltSet Track whether an alt discovers recursion for each alt during NFA to DFA conversion; >1 alt with recursion implies nonregular. | |
| reduced | back to summary |
|---|---|
| protected boolean reduced Is this DFA reduced? I.e., can all states lead to an accept state? | |
| special | back to summary |
|---|---|
| public Vector<Integer> special | |
| specialStates | back to summary |
|---|---|
| public List<DFAState> specialStates List of special DFAState objects | |
| specialStateSTs | back to summary |
|---|---|
| public List<ST> specialStateSTs List of ST for special states. | |
| startState | back to summary |
|---|---|
| public DFAState startState What's the start state for this DFA? | |
| stateCounter | back to summary |
|---|---|
| protected int stateCounter Unique state numbers per DFA | |
| states | back to summary |
|---|---|
| protected Vector<DFAState> states 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 | back to summary |
|---|---|
| public Vector<Vector<Integer>> transition | |
| transitionEdgeTables | back to summary |
|---|---|
| public Vector<Integer> transitionEdgeTables just the Vector<Integer> indicating which unique edge table is at position i. | |
| uniqueCompressedSpecialStateNum | back to summary |
|---|---|
| protected int uniqueCompressedSpecialStateNum | |
| uniqueStates | back to summary |
|---|---|
| protected Map<DFAState, DFAState> uniqueStates 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<DFAState,DFAState>. 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 | back to summary |
|---|---|
| protected List<Integer> unreachableAlts 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 | back to summary |
|---|---|
| protected int user_k User specified max fixed lookahead. If 0, nothing specified. -1 implies we have not looked at the options table yet to set k. | |
| DFA | back to summary |
|---|---|
| protected DFA() | |
| DFA | back to summary |
|---|---|
| public DFA(int decisionNumber, NFAState decisionStartState) | |
| _getMaxLookaheadDepth | back to summary |
|---|---|
| pack-priv int _getMaxLookaheadDepth(DFAState d, int depth) | |
| _hasCycle | back to summary |
|---|---|
| pack-priv boolean _hasCycle(DFAState d, Map<DFAState, Integer> busy) | |
| _hasSemPred | back to summary |
|---|---|
| pack-priv boolean _hasSemPred(DFAState d, Set<DFAState> busy) | |
| _hasSynPred | back to summary |
|---|---|
| pack-priv boolean _hasSynPred(DFAState d, Set<DFAState> busy) | |
| addState | back to summary |
|---|---|
| protected DFAState addState(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. 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. | |
| canInlineDecision | back to summary |
|---|---|
| public boolean canInlineDecision() | |
| createEOTAndEOFTables | back to summary |
|---|---|
| protected void createEOTAndEOFTables(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. | |
| createMinMaxTables | back to summary |
|---|---|
| protected void createMinMaxTables(DFAState s) | |
| createSpecialTable | back to summary |
|---|---|
| protected void createSpecialTable(DFAState s) | |
| createStateTables | back to summary |
|---|---|
| public void createStateTables(CodeGenerator generator) | |
| createTransitionTableEntryForState | back to summary |
|---|---|
| protected void createTransitionTableEntryForState(DFAState s) | |
| doesStateReachAcceptState | back to summary |
|---|---|
| protected boolean doesStateReachAcceptState(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. 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 | |
| findAllGatedSynPredsUsedInDFAAcceptStates | back to summary |
|---|---|
| public void findAllGatedSynPredsUsedInDFAAcceptStates() Walk all accept states and find the manually-specified synpreds. Gated preds are not always hoisted I used to do this in the code generator, but that is too late. This converter tries to avoid computing DFA for decisions in syntactic predicates that are not ever used such as those created by autobacktrack mode. | |
| getAcceptState | back to summary |
|---|---|
| public DFAState getAcceptState(int alt) | |
| getAutoBacktrackMode | back to summary |
|---|---|
| public boolean getAutoBacktrackMode() | |
| getDecisionASTNode | back to summary |
|---|---|
| public GrammarAST getDecisionASTNode() 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 | back to summary |
|---|---|
| public int getDecisionNumber() | |
| getDescription | back to summary |
|---|---|
| public String getDescription() | |
| getHasSynPred | back to summary |
|---|---|
| public boolean getHasSynPred() | |
| getJavaCompressedAccept | back to summary |
|---|---|
| public List | |
| getJavaCompressedEOF | back to summary |
|---|---|
| public List | |
| getJavaCompressedEOT | back to summary |
|---|---|
| public List | |
| getJavaCompressedMax | back to summary |
|---|---|
| public List | |
| getJavaCompressedMin | back to summary |
|---|---|
| public List | |
| getJavaCompressedSpecial | back to summary |
|---|---|
| public List | |
| getJavaCompressedTransition | back to summary |
|---|---|
| public List | |
| getMaxLookaheadDepth | back to summary |
|---|---|
| public int getMaxLookaheadDepth() Return k if decision is LL(k) for some k else return max int | |
| getMaxStateNumber | back to summary |
|---|---|
| public int getMaxStateNumber() What is the max state number ever created? This may be beyond getNumberOfStates(). | |
| getNFADecisionStartState | back to summary |
|---|---|
| public NFAState getNFADecisionStartState() | |
| getNumberOfAlts | back to summary |
|---|---|
| public int getNumberOfAlts() | |
| getNumberOfStates | back to summary |
|---|---|
| public int getNumberOfStates() | |
| getReasonForFailure | back to summary |
|---|---|
| public String getReasonForFailure() | |
| getRunLengthEncoding | back to summary |
|---|---|
| public List 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<String> where each string is either \xyz for 8bit char and for 16bit. Hideous and specific to Java, but it is the only target bad enough to need it. | |
| getState | back to summary |
|---|---|
| public DFAState getState(int stateNumber) | |
| getUniqueStates | back to summary |
|---|---|
| public Map | |
| getUnreachableAlts | back to summary |
|---|---|
| public List 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 | back to summary |
|---|---|
| public int getUserMaxLookahead() 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. | |
| hasCycle | back to summary |
|---|---|
| public boolean hasCycle() Compute cyclic w/o relying on state computed during analysis. just check. | |
| hasSemPred | back to summary |
|---|---|
| public boolean hasSemPred() | |
| hasSynPred | back to summary |
|---|---|
| public boolean hasSynPred() Count all disambiguating syn preds (ignore synpred tests for gated edges, which occur for nonambig input sequences). E.g., x : (X)=> (X|Y)\n" + | X\n" + ; gives .s0-X->.s1 .s0-Y&&{synpred1_t}?->:s2=>1 .s1-{synpred1_t}?->:s2=>1 .s1-{true}?->:s3=>2 | |
| initAltRelatedInfo | back to summary |
|---|---|
| protected void initAltRelatedInfo() | |
| isClassicDFA | back to summary |
|---|---|
| public boolean isClassicDFA() | |
| isCyclic | back to summary |
|---|---|
| public boolean isCyclic() 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 | back to summary |
|---|---|
| public boolean isGreedy() | |
| isReduced | back to summary |
|---|---|
| public boolean isReduced() 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 | back to summary |
|---|---|
| public boolean isTokensRuleDecision() Is this DFA derived from the NFA for the Tokens rule? | |
| newState | back to summary |
|---|---|
| public DFAState newState() | |
| okToRetryDFAWithK1 | back to summary |
|---|---|
| public boolean okToRetryDFAWithK1() If this DFA failed to finish during construction, we might be able to retry with k=1 but we need to know whether it will potentially succeed. Can only succeed if there is a predicate to resolve the issue. Don't try if k=1 already as it would cycle forever. Timeout can retry with k=1 even if no predicate if k!=1. | |
| predict | back to summary |
|---|---|
| public int predict(IntStream input) | |
| removeState | back to summary |
|---|---|
| public void removeState(DFAState d) | |
| resetStateNumbersToBeContiguous | back to summary |
|---|---|
| public void resetStateNumbersToBeContiguous() 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 | back to summary |
|---|---|
| public void setAcceptState(int alt, DFAState acceptState) | |
| setState | back to summary |
|---|---|
| public void setState(int stateNumber, DFAState d) | |
| setUserMaxLookahead | back to summary |
|---|---|
| public void setUserMaxLookahead(int k) | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| verify | back to summary |
|---|---|
| public void verify() 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 This is avoided if analysis bails out for any reason. | |