Class DFAState
I use a set of ATNConfig objects not simple states. An ATNConfig is both a state (ala normal conversion) and a RuleContext describing the chain of rules (if any) followed to arrive at that state.
A DFA state may have multiple references to a particular state, but with different ATN contexts (with same or different alts) meaning that state was reached via a different set of rule invocations.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classMap a predicate to a predicted alternative. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AcceptStateInfofinal ATNConfigSetprivate AbstractEdgeMap<DFAState> These keys for these edges are the top level element of the global context.private BitSetSymbols in this set require a global context transition before matching an input symbol.private AbstractEdgeMap<DFAState> edges.get(symbol)points to target of symbol.int -
Constructor Summary
ConstructorsConstructorDescriptionDFAState(DFA dfa, ATNConfigSet configs) Constructs a newDFAStatefor a DFA.DFAState(EmptyEdgeMap<DFAState> emptyEdges, EmptyEdgeMap<DFAState> emptyContextEdges, ATNConfigSet configs) Constructs a newDFAStatewith explicit initial values for the outgoing edge and context edge maps. -
Method Summary
Modifier and TypeMethodDescriptionbooleanTwoDFAStateinstances are equal if their ATN configuration sets are the same.final AcceptStateInfogetContextTarget(int invokingState) final LexerActionExecutorfinal intgetTarget(int symbol) inthashCode()final booleanfinal booleanfinal booleanisContextSymbol(int symbol) final voidsetAcceptState(AcceptStateInfo acceptStateInfo) voidsetContextSensitive(ATN atn) final voidsetContextSymbol(int symbol) voidsetContextTarget(int invokingState, DFAState target) voidtoString()
-
Field Details
-
stateNumber
public int stateNumber -
configs
-
edges
edges.get(symbol)points to target of symbol. -
acceptStateInfo
-
contextEdges
These keys for these edges are the top level element of the global context. -
contextSymbols
Symbols in this set require a global context transition before matching an input symbol. -
predicates
-
-
Constructor Details
-
DFAState
Constructs a newDFAStatefor a DFA.This constructor initializes the DFA state using empty edge maps provided by the specified DFA.
- Parameters:
dfa- The DFA.configs- The set of ATN configurations defining this state.
-
DFAState
public DFAState(@NotNull EmptyEdgeMap<DFAState> emptyEdges, @NotNull EmptyEdgeMap<DFAState> emptyContextEdges, @NotNull ATNConfigSet configs) Constructs a newDFAStatewith explicit initial values for the outgoing edge and context edge maps.The empty maps provided to this constructor contain information about the range of edge values which are allowed to be stored in the map. Since edges outside the allowed range are simply dropped from the DFA, this offers several potential benefits:
- In the general case, empty edge maps are initialized to support the range of values expected to be seen during prediction, which is in turn used to minimize the memory overhead associated with a dynamically-constructed DFA.
- As a special case, empty edge maps can be intentionally constructed so the DFA will not store edges with specific values. In the limit, a range which does not contain any allowed edges can be used to prevent the DFA from storing any edges, forcing the prediction algorithm to recompute all transitions as they are needed.
- Parameters:
emptyEdges- The empty edge map.emptyContextEdges- The empty context edge map.configs- The set of ATN configurations defining this state.
-
-
Method Details
-
isContextSensitive
public final boolean isContextSensitive() -
isContextSymbol
public final boolean isContextSymbol(int symbol) -
setContextSymbol
public final void setContextSymbol(int symbol) -
setContextSensitive
-
getAcceptStateInfo
-
setAcceptState
-
isAcceptState
public final boolean isAcceptState() -
getPrediction
public final int getPrediction() -
getLexerActionExecutor
-
getTarget
-
setTarget
-
getEdgeMap
-
getContextTarget
-
setContextTarget
-
getContextEdgeMap
-
hashCode
public int hashCode() -
equals
TwoDFAStateinstances are equal if their ATN configuration sets are the same. This method is used to see if a state already exists.Because the number of alternatives and number of ATN 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 DFA state numbers here because in
ParserATNSimulator.addDFAState(org.antlr.v4.runtime.dfa.DFA, org.antlr.v4.runtime.atn.ATNConfigSet, org.antlr.v4.runtime.atn.PredictionContextCache)we need to know if any other state exists that has this exact set of ATN configurations. ThestateNumberis irrelevant. -
toString
-