public class DFAState extends Object
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.
| Modifier and Type | Class and Description |
|---|---|
static class |
DFAState.PredPrediction
Map a predicate to a predicted alternative.
|
| Modifier and Type | Field and Description |
|---|---|
ATNConfigSet |
configs |
DFAState.PredPrediction[] |
predicates
|
int |
stateNumber |
| Constructor and Description |
|---|
DFAState(DFA dfa,
ATNConfigSet configs)
Constructs a new
DFAState for a DFA. |
DFAState(EmptyEdgeMap<DFAState> emptyEdges,
EmptyEdgeMap<DFAState> emptyContextEdges,
ATNConfigSet configs)
Constructs a new
DFAState with explicit initial values for the
outgoing edge and context edge maps. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object o)
Two
DFAState instances are equal if their ATN configuration sets
are the same. |
AcceptStateInfo |
getAcceptStateInfo() |
Map<Integer,DFAState> |
getContextEdgeMap() |
DFAState |
getContextTarget(int invokingState) |
Map<Integer,DFAState> |
getEdgeMap() |
LexerActionExecutor |
getLexerActionExecutor() |
int |
getPrediction() |
DFAState |
getTarget(int symbol) |
int |
hashCode() |
boolean |
isAcceptState() |
boolean |
isContextSensitive() |
boolean |
isContextSymbol(int symbol) |
void |
setAcceptState(AcceptStateInfo acceptStateInfo) |
void |
setContextSensitive(ATN atn) |
void |
setContextSymbol(int symbol) |
void |
setContextTarget(int invokingState,
DFAState target) |
void |
setTarget(int symbol,
DFAState target) |
String |
toString() |
public int stateNumber
@NotNull public final ATNConfigSet configs
@Nullable public DFAState.PredPrediction[] predicates
public DFAState(@NotNull
DFA dfa,
@NotNull
ATNConfigSet configs)
DFAState for a DFA.
This constructor initializes the DFA state using empty edge maps provided by the specified DFA.
dfa - The DFA.configs - The set of ATN configurations defining this state.public DFAState(@NotNull
EmptyEdgeMap<DFAState> emptyEdges,
@NotNull
EmptyEdgeMap<DFAState> emptyContextEdges,
@NotNull
ATNConfigSet configs)
DFAState with 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:
emptyEdges - The empty edge map.emptyContextEdges - The empty context edge map.configs - The set of ATN configurations defining this state.public final boolean isContextSensitive()
public final boolean isContextSymbol(int symbol)
public final void setContextSymbol(int symbol)
public void setContextSensitive(ATN atn)
public final AcceptStateInfo getAcceptStateInfo()
public final void setAcceptState(AcceptStateInfo acceptStateInfo)
public final boolean isAcceptState()
public final int getPrediction()
public final LexerActionExecutor getLexerActionExecutor()
public DFAState getTarget(int symbol)
public void setTarget(int symbol,
DFAState target)
public DFAState getContextTarget(int invokingState)
public void setContextTarget(int invokingState,
DFAState target)
public boolean equals(Object o)
DFAState instances 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. The
stateNumber is irrelevant.
Copyright © 1992–2024 Daniel Sun. All rights reserved.