Package org.antlr.v4.runtime.atn
Class ATN
java.lang.Object
org.antlr.v4.runtime.atn.ATN
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal List
<DecisionState> Each subrule/rule is a decision point and we must track them so we can go back later and build DFA predictors for them.final ATNType
The type of the ATN.static final int
For lexer ATNs, this is an array ofLexerAction
objects which may be referenced by action transitions in the ATN.final int
The maximum value for any symbol recognized by a transition in the ATN.final Map
<String, TokensStartState> final List
<TokensStartState> Maps from rule index to starting state number.Maps from rule index to stop state number.int[]
For lexer ATNs, this maps the rule index to the resulting token type. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
int
getDecisionState
(int decision) getExpectedTokens
(int stateNumber, RuleContext context) Computes the set of input symbols which could follow ATN state numberstateNumber
in the specified fullcontext
.int
Compute the set of valid tokens that can occur starting ins
and staying in same rule.nextTokens
(ATNState s, RuleContext ctx) Compute the set of valid tokens that can occur starting in states
.void
removeState
(ATNState state)
-
Field Details
-
INVALID_ALT_NUMBER
public static final int INVALID_ALT_NUMBER- See Also:
-
states
-
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... -
ruleToStartState
Maps from rule index to starting state number. -
ruleToStopState
Maps from rule index to stop state number. -
modeNameToStartState
-
grammarType
The type of the ATN. -
maxTokenType
public final int maxTokenTypeThe maximum value for any symbol recognized by a transition in the ATN. -
ruleToTokenType
public int[] ruleToTokenTypeFor 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 theATNDeserializationOptions.isGenerateRuleBypassTransitions()
deserialization option was specified; otherwise, this isnull
. -
lexerActions
For lexer ATNs, this is an array ofLexerAction
objects which may be referenced by action transitions in the ATN. -
modeToStartState
-
-
Constructor Details
-
ATN
Used for runtime deserialization of ATNs from strings
-
-
Method Details
-
nextTokens
Compute the set of valid tokens that can occur starting in states
. Ifctx
is null, the set of tokens will not include what can follow the rule surroundings
. In other words, the set will be restricted to tokens reachable staying withins
's rule. -
nextTokens
Compute the set of valid tokens that can occur starting ins
and staying in same rule.Token.EPSILON
is in set if we reach end of rule. -
addState
-
removeState
-
defineDecisionState
-
getDecisionState
-
getNumberOfDecisions
public int getNumberOfDecisions() -
getExpectedTokens
Computes the set of input symbols which could follow ATN state numberstateNumber
in the specified fullcontext
. 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 theRuleStopState
of the outermost context without matching any symbols,Token.EOF
is added to the returned set.If
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.context
isnull
, it is treated asRuleContext.EMPTY
.- Parameters:
stateNumber
- the ATN state numbercontext
- the full parse context- Returns:
- The set of potentially valid input symbols which could follow the specified state in the specified context.
- Throws:
IllegalArgumentException
- if the ATN does not contain a state with numberstateNumber
-