public class DFA extends Object
| Modifier and Type | Field and Description |
|---|---|
ATNState |
atnStartState
From which ATN state did we create this DFA?
|
int |
decision |
AtomicReference<DFAState> |
s0
This is the start state for SLL prediction.
|
AtomicReference<DFAState> |
s0full
This is the start state for full context prediction.
|
ConcurrentMap<DFAState,DFAState> |
states
A set of all DFA states.
|
| Constructor and Description |
|---|
DFA(ATNState atnStartState)
Constructs a
DFA instance associated with a lexer mode. |
DFA(ATNState atnStartState,
int decision)
Constructs a
DFA instance associated with a decision. |
| Modifier and Type | Method and Description |
|---|---|
DFAState |
addState(DFAState state) |
EmptyEdgeMap<DFAState> |
getEmptyContextEdgeMap()
Gets an empty edge map initialized with the minimum and maximum context
values allowed to be stored in this DFA.
|
EmptyEdgeMap<DFAState> |
getEmptyEdgeMap()
Gets an empty edge map initialized with the minimum and maximum symbol
values allowed to be stored in this DFA.
|
int |
getMaxDfaEdge()
Gets the maximum input symbol value which can be stored in this DFA.
|
int |
getMinDfaEdge()
Gets the minimum input symbol value which can be stored in this DFA.
|
DFAState |
getPrecedenceStartState(int precedence,
boolean fullContext)
Get the start state for a specific precedence value.
|
boolean |
isContextSensitive() |
boolean |
isEmpty() |
boolean |
isPrecedenceDfa()
Gets whether this DFA is a precedence DFA.
|
void |
setPrecedenceDfa(boolean precedenceDfa)
Deprecated.
This method no longer performs any action.
|
void |
setPrecedenceStartState(int precedence,
boolean fullContext,
DFAState startState)
Set the start state for a specific precedence value.
|
String |
toLexerString() |
String |
toString() |
String |
toString(String[] tokenNames)
Deprecated.
Use
toString(Vocabulary) instead. |
String |
toString(String[] tokenNames,
String[] ruleNames)
Deprecated.
Use
toString(Vocabulary, String[]) instead. |
String |
toString(Vocabulary vocabulary) |
String |
toString(Vocabulary vocabulary,
String[] ruleNames) |
@NotNull public final ConcurrentMap<DFAState,DFAState> states
Map so we can get old state back
(Set only allows you to see if it's there).
Note that this collection of states holds the DFA states for both SLL
and LL prediction. Only the start state needs to be differentiated for
these cases, which is tracked by the s0 and s0full
fields.
@NotNull public final AtomicReference<DFAState> s0
When isPrecedenceDfa() is true, this state is not used
directly. Rather, getPrecedenceStartState(int, boolean) is used to obtain the
true SLL start state by traversing an outgoing edge corresponding to the
current precedence level in the parser.
@NotNull public final AtomicReference<DFAState> s0full
s0public final int decision
@NotNull public final ATNState atnStartState
public DFA(@NotNull
ATNState atnStartState)
DFA instance associated with a lexer mode.
The start state for a DFA constructed with this method should
be a TokensStartState, which is the start state for a lexer mode.
The prediction made by this DFA determines the lexer rule which matches
the current input.
atnStartState - The start state for the mode.public final int getMinDfaEdge()
getEmptyEdgeMap()public final int getMaxDfaEdge()
getEmptyEdgeMap()@NotNull public EmptyEdgeMap<DFAState> getEmptyEdgeMap()
Setting a range of allowed symbol values for a DFA bounds the memory
overhead for storing the map of outgoing edges. The various
implementations of EdgeMap use this range to determine the best
memory savings will be obtained from sparse storage (e.g.
SingletonEdgeMap or SparseEdgeMap) or dense storage
(ArrayEdgeMap). Symbols values outside the range are supported
during prediction, but since DFA edges are never created for these
symbols they will always recompute the target state through a match and
closure operation.
Empty edge maps are immutable objects which track the allowed range of
input symbols that can be stored as edges in the DFA. By storing an empty
edge map instance in the DFA, new instances of DFAState created
for the DFA can be initialized with a non-null outgoing edge map with the
proper symbol range without incurring extra allocations.
DFAState
instances associated with this DFA.@NotNull public EmptyEdgeMap<DFAState> getEmptyContextEdgeMap()
The value assigned to a context edge within the DFA is an ATN state
number, so the range of allowed values for the context edge map is
ATNState.INVALID_STATE_NUMBER through the number of states stored
in ATN.states for the ATN.
This empty edge map serves a purpose similar to
getEmptyEdgeMap(). It is used for initializing DFAState
instances without incurring memory overhead for the (especially) common
case where no outgoing context edges are added to the DFA state.
DFAState
instances associated with this DFA.public final boolean isPrecedenceDfa()
s0 which is not stored in states. The
DFAState.edges array for this start state contains outgoing edges
supplying individual start states corresponding to specific precedence
values.true if this is a precedence DFA; otherwise,
false.Parser.getPrecedence()public final DFAState getPrecedenceStartState(int precedence, boolean fullContext)
precedence - The current precedence.null if no start state exists for the specified precedence.IllegalStateException - if this is not a precedence DFA.isPrecedenceDfa()public final void setPrecedenceStartState(int precedence,
boolean fullContext,
DFAState startState)
precedence - The current precedence.startState - The start state corresponding to the specified
precedence.IllegalStateException - if this is not a precedence DFA.isPrecedenceDfa()@Deprecated public final void setPrecedenceDfa(boolean precedenceDfa)
precedenceDfa - true if this is a precedence DFA; otherwise,
falseUnsupportedOperationException - if precedenceDfa does not
match the value of isPrecedenceDfa() for the current DFA.public boolean isEmpty()
public boolean isContextSensitive()
@Deprecated public String toString(@Nullable String[] tokenNames)
toString(Vocabulary) instead.public String toString(@NotNull Vocabulary vocabulary)
@Deprecated public String toString(@Nullable String[] tokenNames, @Nullable String[] ruleNames)
toString(Vocabulary, String[]) instead.public String toString(@NotNull Vocabulary vocabulary, @Nullable String[] ruleNames)
public String toLexerString()
Copyright © 1992–2024 Daniel Sun. All rights reserved.