Class ATN

java.lang.Object
org.antlr.v4.runtime.atn.ATN

public class ATN extends Object
  • Field Details

    • INVALID_ALT_NUMBER

      public static final int INVALID_ALT_NUMBER
      See Also:
    • states

      @NotNull public final List<ATNState> states
    • decisionToState

      @NotNull 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...
    • ruleToStartState

      public RuleStartState[] ruleToStartState
      Maps from rule index to starting state number.
    • ruleToStopState

      public RuleStopState[] ruleToStopState
      Maps from rule index to stop state number.
    • modeNameToStartState

      @NotNull public final Map<String,TokensStartState> modeNameToStartState
    • grammarType

      public final ATNType grammarType
      The type of the ATN.
    • maxTokenType

      public final int maxTokenType
      The maximum value for any symbol recognized by a transition in the ATN.
    • hasUnicodeSMPTransitions

      private boolean hasUnicodeSMPTransitions
    • ruleToTokenType

      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.
    • lexerActions

      public LexerAction[] lexerActions
      For lexer ATNs, this is an array of LexerAction objects which may be referenced by action transitions in the ATN.
    • modeToStartState

      @NotNull public final List<TokensStartState> modeToStartState
    • contextCache

      private final ConcurrentMap<PredictionContext,PredictionContext> contextCache
    • decisionToDFA

      @NotNull public DFA[] decisionToDFA
    • modeToDFA

      @NotNull public DFA[] modeToDFA
    • LL1Table

      protected final ConcurrentMap<Integer,Integer> LL1Table
  • Constructor Details

    • ATN

      public ATN(@NotNull ATNType grammarType, int maxTokenType)
      Used for runtime deserialization of ATNs from strings
  • Method Details

    • clearDFA

      public final void clearDFA()
    • getContextCacheSize

      public int getContextCacheSize()
    • getCachedContext

      public PredictionContext getCachedContext(PredictionContext context)
    • getDecisionToDFA

      public final DFA[] getDecisionToDFA()
    • nextTokens

      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.
    • nextTokens

      @NotNull public IntervalSet nextTokens(@NotNull 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.
    • addState

      public void addState(@Nullable ATNState state)
    • removeState

      public void removeState(@NotNull ATNState state)
    • defineMode

      public void defineMode(@NotNull String name, @NotNull TokensStartState s)
    • defineDecisionState

      public int defineDecisionState(@NotNull DecisionState s)
    • getDecisionState

      public DecisionState getDecisionState(int decision)
    • getNumberOfDecisions

      public int getNumberOfDecisions()
    • getExpectedTokens

      @NotNull public IntervalSet getExpectedTokens(int stateNumber, @Nullable 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 - the ATN state number
      context - 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 number stateNumber
    • hasUnicodeSMPTransitions

      public boolean hasUnicodeSMPTransitions()
    • setHasUnicodeSMPTransitions

      public void setHasUnicodeSMPTransitions(boolean value)