Top Fields Constructors Methods
org.antlr.v4.runtime.dfa

public Class DFA

extends Object
Class Inheritance
Imports
org.antlr.v4.runtime.Parser, .Token, .Vocabulary, .VocabularyImpl, org.antlr.v4.runtime.atn.ATN, .ATNConfigSet, .ATNState, .ATNType, .LexerATNSimulator, .StarLoopEntryState, .TokensStartState, org.antlr.v4.runtime.misc.NotNull, .Nullable, java.util.Map, .Set, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, java.util.concurrent.atomic.AtomicInteger, .AtomicReference

Field Summary

Modifier and TypeField and Description
public final ATNState
atnStartState

From which ATN state did we create this DFA?

public final int
private static final EmptyEdgeMap<DFAState>
EMPTY_PRECEDENCE_EDGES

This field initializes the outgoing edge map for the special starting DFA state created for precedence DFAs.

private final EmptyEdgeMap<DFAState>
emptyContextEdgeMap

This is the backing field for getEmptyContextEdgeMap().

private final EmptyEdgeMap<DFAState>
emptyEdgeMap

This is the backing field for getEmptyEdgeMap().

private final int
maxDfaEdge

This is the backing field for getMaxDfaEdge().

private final int
minDfaEdge

This is the backing field for getMinDfaEdge().

private final AtomicInteger
private final boolean
precedenceDfa

true if this DFA is for a precedence decision; otherwise, false.

public final AtomicReference<DFAState>
s0

This is the start state for SLL prediction.

public final AtomicReference<DFAState>
s0full

This is the start state for full context prediction.

public final ConcurrentMap<DFAState, DFAState>
states

A set of all DFA states.

Constructor Summary

AccessConstructor and Description
public
DFA(ATNState
The start state for the mode.
atnStartState
)

Constructs a DFA instance associated with a lexer mode.

public
DFA(ATNState
The decision associated with this DFA.
atnStartState
,
int
The decision number.
decision
)

Constructs a DFA instance associated with a decision.

Method Summary

Modifier and TypeMethod and Description
public DFAState
public EmptyEdgeMap<DFAState>

Returns:

The empty context edge map used for initializing DFAState instances associated with this DFA.
getEmptyContextEdgeMap
()

Gets an empty edge map initialized with the minimum and maximum context values allowed to be stored in this DFA.

public EmptyEdgeMap<DFAState>

Returns:

The empty edge map used for initializing DFAState instances associated with this DFA.
getEmptyEdgeMap
()

Gets an empty edge map initialized with the minimum and maximum symbol values allowed to be stored in this DFA.

public final int

Returns:

The maximum input symbol which can be stored in this DFA.
getMaxDfaEdge
()

Gets the maximum input symbol value which can be stored in this DFA.

public final int

Returns:

The minimum input symbol which can be stored in this DFA.
getMinDfaEdge
()

Gets the minimum input symbol value which can be stored in this DFA.

public final DFAState

Returns:

The start state corresponding to the specified precedence, or null if no start state exists for the specified precedence.
getPrecedenceStartState
(int
The current precedence.
precedence
,
boolean fullContext)

Get the start state for a specific precedence value.

public boolean
public boolean
public final boolean

Returns:

true if this is a precedence DFA; otherwise, false.
isPrecedenceDfa
()

Gets whether this DFA is a precedence DFA.

public final void
setPrecedenceDfa(boolean
true if this is a precedence DFA; otherwise, false
precedenceDfa
)

Deprecated This method no longer performs any action.
Sets whether this is a precedence DFA.
public final void
setPrecedenceStartState(int
The current precedence.
precedence
,
boolean fullContext, DFAState
The start state corresponding to the specified precedence.
startState
)

Set the start state for a specific precedence value.

public String
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public String
toString(String[] tokenNames)

Deprecated Use toString(Vocabulary) instead.
public String
toString(Vocabulary vocabulary)

public String
toString(String[] tokenNames, String[] ruleNames)

Deprecated Use toString(Vocabulary, String[]) instead.
public String
toString(Vocabulary vocabulary, String[] ruleNames)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

atnStartStateback to summary
public final ATNState atnStartState

From which ATN state did we create this DFA?

Annotations
@NotNull
decisionback to summary
public final int decision
EMPTY_PRECEDENCE_EDGESback to summary
private static final EmptyEdgeMap<DFAState> EMPTY_PRECEDENCE_EDGES

This field initializes the outgoing edge map for the special starting DFA state created for precedence DFAs.

The range of allowed values assigned to this map represent the precedence levels for which an edge will be stored in the DFA. If a precedence level is encountered outside this range, the DFA will not be able to hold an edge pointing to the start state for the decision, so prediction for this precedence level will always result in recomputing the start state. Should this occur, the existing start state can still be located within states so outgoing edges starting from the start state will not be dropped.

Annotations
@NotNull
emptyContextEdgeMapback to summary
private final EmptyEdgeMap<DFAState> emptyContextEdgeMap

This is the backing field for getEmptyContextEdgeMap().

Annotations
@NotNull
emptyEdgeMapback to summary
private final EmptyEdgeMap<DFAState> emptyEdgeMap

This is the backing field for getEmptyEdgeMap().

Annotations
@NotNull
maxDfaEdgeback to summary
private final int maxDfaEdge

This is the backing field for getMaxDfaEdge().

minDfaEdgeback to summary
private final int minDfaEdge

This is the backing field for getMinDfaEdge().

nextStateNumberback to summary
private final AtomicInteger nextStateNumber
precedenceDfaback to summary
private final boolean precedenceDfa

true if this DFA is for a precedence decision; otherwise, false. This is the backing field for isPrecedenceDfa.

s0back to summary
public final AtomicReference<DFAState> s0

This is the start state for SLL prediction.

When isPrecedenceDfa is true, this state is not used directly. Rather, getPrecedenceStartState is used to obtain the true SLL start state by traversing an outgoing edge corresponding to the current precedence level in the parser.

Annotations
@NotNull
s0fullback to summary
public final AtomicReference<DFAState> s0full

This is the start state for full context prediction.

Annotations
@NotNull
See Also
s0
statesback to summary
public final ConcurrentMap<DFAState, DFAState> states

A set of all DFA states. Use 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.

Annotations
@NotNull

Constructor Detail

DFAback to summary
public DFA(ATNState atnStartState)

Constructs a 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.

Parameters
atnStartState:ATNState

The start state for the mode.

DFAback to summary
public DFA(ATNState atnStartState, int decision)

Constructs a DFA instance associated with a decision.

Parameters
atnStartState:ATNState

The decision associated with this DFA.

decision:int

The decision number.

Method Detail

addStateback to summary
public DFAState addState(DFAState state)
getEmptyContextEdgeMapback to summary
public EmptyEdgeMap<DFAState> getEmptyContextEdgeMap()

Gets an empty edge map initialized with the minimum and maximum context values allowed to be stored in this DFA.

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.

Returns:EmptyEdgeMap<DFAState>

The empty context edge map used for initializing DFAState instances associated with this DFA.

Annotations
@NotNull
getEmptyEdgeMapback to summary
public EmptyEdgeMap<DFAState> getEmptyEdgeMap()

Gets an empty edge map initialized with the minimum and maximum symbol values allowed to be stored in this DFA.

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.

Returns:EmptyEdgeMap<DFAState>

The empty edge map used for initializing DFAState instances associated with this DFA.

Annotations
@NotNull
getMaxDfaEdgeback to summary
public final int getMaxDfaEdge()

Gets the maximum input symbol value which can be stored in this DFA.

Returns:int

The maximum input symbol which can be stored in this DFA.

See Also
getEmptyEdgeMap
getMinDfaEdgeback to summary
public final int getMinDfaEdge()

Gets the minimum input symbol value which can be stored in this DFA.

Returns:int

The minimum input symbol which can be stored in this DFA.

See Also
getEmptyEdgeMap
getPrecedenceStartStateback to summary
public final DFAState getPrecedenceStartState(int precedence, boolean fullContext)

Get the start state for a specific precedence value.

Parameters
precedence:int

The current precedence.

Returns:DFAState

The start state corresponding to the specified precedence, or null if no start state exists for the specified precedence.

Annotations
@SuppressWarnings:null
Exceptions
IllegalStateException:
if this is not a precedence DFA.
See Also
isPrecedenceDfa()
isContextSensitiveback to summary
public boolean isContextSensitive()
isEmptyback to summary
public boolean isEmpty()
isPrecedenceDfaback to summary
public final boolean isPrecedenceDfa()

Gets whether this DFA is a precedence DFA. Precedence DFAs use a special start state 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.

Returns:boolean

true if this is a precedence DFA; otherwise, false.

See Also
Parser#getPrecedence()
setPrecedenceDfaback to summary
public final void setPrecedenceDfa(boolean precedenceDfa)

Deprecated

This method no longer performs any action.

Sets whether this is a precedence DFA.

Parameters
precedenceDfa:boolean

true if this is a precedence DFA; otherwise, false

Annotations
@Deprecated
Exceptions
UnsupportedOperationException:
if precedenceDfa does not match the value of isPrecedenceDfa for the current DFA.
setPrecedenceStartStateback to summary
public final void setPrecedenceStartState(int precedence, boolean fullContext, DFAState startState)

Set the start state for a specific precedence value.

Parameters
precedence:int

The current precedence.

startState:DFAState

The start state corresponding to the specified precedence.

Annotations
@SuppressWarnings:SynchronizeOnNonFinalField, null
Exceptions
IllegalStateException:
if this is not a precedence DFA.
See Also
isPrecedenceDfa()
toLexerStringback to summary
public String toLexerString()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
toStringback to summary
public String toString(String[] tokenNames)

Deprecated

Use toString(Vocabulary) instead.

Annotations
@Deprecated
toStringback to summary
public String toString(Vocabulary vocabulary)
toStringback to summary
public String toString(String[] tokenNames, String[] ruleNames)

Deprecated

Use toString(Vocabulary, String[]) instead.

Annotations
@Deprecated
toStringback to summary
public String toString(Vocabulary vocabulary, String[] ruleNames)