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

public Class ATN

extends Object
Class Inheritance
Imports
org.antlr.v4.runtime.ParserRuleContext, .RuleContext, .Token, org.antlr.v4.runtime.dfa.DFA, org.antlr.v4.runtime.misc.Args, .IntervalSet, .NotNull, .Nullable, java.util.ArrayList, .Arrays, .LinkedHashMap, .List, .Map, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap

Field Summary

Modifier and TypeField and Description
private final ConcurrentMap<PredictionContext, PredictionContext>
public DFA[]
public final List<DecisionState>
decisionToState

Each subrule/rule is a decision point and we must track them so we can go back later and build DFA predictors for them.

public final ATNType
grammarType

The type of the ATN.

private boolean
public static final int
public LexerAction[]
lexerActions

For lexer ATNs, this is an array of LexerAction objects which may be referenced by action transitions in the ATN.

protected final ConcurrentMap<Integer, Integer>
public final int
maxTokenType

The maximum value for any symbol recognized by a transition in the ATN.

public final Map<String, TokensStartState>
public DFA[]
public final List<TokensStartState>
public RuleStartState[]
ruleToStartState

Maps from rule index to starting state number.

public RuleStopState[]
ruleToStopState

Maps from rule index to stop state number.

public int[]
ruleToTokenType

For lexer ATNs, this maps the rule index to the resulting token type.

public final List<ATNState>

Constructor Summary

AccessConstructor and Description
public
ATN(ATNType grammarType, int maxTokenType)

Used for runtime deserialization of ATNs from strings

Method Summary

Modifier and TypeMethod and Description
public void
public final void
public int
public void
public PredictionContext
public int
public DecisionState
getDecisionState(int decision)

public final DFA[]
public IntervalSet

Returns:

The set of potentially valid input symbols which could follow the specified state in the specified context.
getExpectedTokens
(int
the ATN state number
stateNumber
,
RuleContext
the full parse context
context
)

Computes the set of input symbols which could follow ATN state number stateNumber in the specified full context.</quote>

public int
public boolean
public IntervalSet
nextTokens(ATNState s, PredictionContext ctx)

Compute the set of valid tokens that can occur starting in state s.

public IntervalSet
nextTokens(ATNState s)

Compute the set of valid tokens that can occur starting in s and staying in same rule.

public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contextCacheback to summary
private final ConcurrentMap<PredictionContext, PredictionContext> contextCache
decisionToDFAback to summary
public DFA[] decisionToDFA
Annotations
@NotNull
decisionToStateback to summary
public final List<DecisionState> decisionToState

Each subrule/rule is a decision point and we must track them so we can go back later and build DFA predictors for them. This includes all the rules, subrules, optional blocks, ()+, ()* etc...

Annotations
@NotNull
grammarTypeback to summary
public final ATNType grammarType

The type of the ATN.

hasUnicodeSMPTransitionsback to summary
private boolean hasUnicodeSMPTransitions
INVALID_ALT_NUMBERback to summary
public static final int INVALID_ALT_NUMBER
lexerActionsback to summary
public LexerAction[] lexerActions

For lexer ATNs, this is an array of LexerAction objects which may be referenced by action transitions in the ATN.

LL1Tableback to summary
protected final ConcurrentMap<Integer, Integer> LL1Table
maxTokenTypeback to summary
public final int maxTokenType

The maximum value for any symbol recognized by a transition in the ATN.

modeNameToStartStateback to summary
public final Map<String, TokensStartState> modeNameToStartState
Annotations
@NotNull
modeToDFAback to summary
public DFA[] modeToDFA
Annotations
@NotNull
modeToStartStateback to summary
public final List<TokensStartState> modeToStartState
Annotations
@NotNull
ruleToStartStateback to summary
public RuleStartState[] ruleToStartState

Maps from rule index to starting state number.

ruleToStopStateback to summary
public RuleStopState[] ruleToStopState

Maps from rule index to stop state number.

ruleToTokenTypeback to summary
public int[] ruleToTokenType

For lexer ATNs, this maps the rule index to the resulting token type. For parser ATNs, this maps the rule index to the generated bypass token type if the ATNDeserializationOptions#isGenerateRuleBypassTransitions deserialization option was specified; otherwise, this is null.

statesback to summary
public final List<ATNState> states
Annotations
@NotNull

Constructor Detail

ATNback to summary
public ATN(ATNType grammarType, int maxTokenType)

Used for runtime deserialization of ATNs from strings

Method Detail

addStateback to summary
public void addState(ATNState state)
clearDFAback to summary
public final void clearDFA()
defineDecisionStateback to summary
public int defineDecisionState(DecisionState s)
defineModeback to summary
public void defineMode(String name, TokensStartState s)
getCachedContextback to summary
public PredictionContext getCachedContext(PredictionContext context)
getContextCacheSizeback to summary
public int getContextCacheSize()
getDecisionStateback to summary
public DecisionState getDecisionState(int decision)
getDecisionToDFAback to summary
public final DFA[] getDecisionToDFA()
getExpectedTokensback to summary
public IntervalSet getExpectedTokens(int stateNumber, RuleContext context)

Computes the set of input symbols which could follow ATN state number stateNumber in the specified full context. This method considers the complete parser context, but does not evaluate semantic predicates (i.e. all predicates encountered during the calculation are assumed true). If a path in the ATN exists from the starting state to the RuleStopState of the outermost context without matching any symbols, Token#EOF is added to the returned set.

If context is null, it is treated as ParserRuleContext#EMPTY.

Note that this does NOT give you the set of all tokens that could appear at a given token position in the input phrase. In other words, it does not answer:

"Given a specific partial input phrase, return the set of all tokens that can follow the last token in the input phrase."

The big difference is that with just the input, the parser could land right in the middle of a lookahead decision. Getting all possible tokens given a partial input stream is a separate computation. See https://github.com/antlr/antlr4/issues/1428

For this function, we are specifying an ATN state and call stack to compute what token(s) can come next and specifically: outside of a lookahead decision. That is what you want for error reporting and recovery upon parse error.

Parameters
stateNumber:int

the ATN state number

context:RuleContext

the full parse context

Returns:IntervalSet

The set of potentially valid input symbols which could follow the specified state in the specified context.

Annotations
@NotNull
Exceptions
IllegalArgumentException:
if the ATN does not contain a state with number stateNumber
getNumberOfDecisionsback to summary
public int getNumberOfDecisions()
hasUnicodeSMPTransitionsback to summary
public boolean hasUnicodeSMPTransitions()
nextTokensback to summary
public IntervalSet nextTokens(ATNState s, PredictionContext ctx)

Compute the set of valid tokens that can occur starting in state s. If ctx is PredictionContext#EMPTY_LOCAL, the set of tokens will not include what can follow the rule surrounding s. In other words, the set will be restricted to tokens reachable staying within s's rule.

Annotations
@NotNull
nextTokensback to summary
public IntervalSet nextTokens(ATNState s)

Compute the set of valid tokens that can occur starting in s and staying in same rule. Token#EPSILON is in set if we reach end of rule.

Annotations
@NotNull
removeStateback to summary
public void removeState(ATNState state)
setHasUnicodeSMPTransitionsback to summary
public void setHasUnicodeSMPTransitions(boolean value)