/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. * Use of this file is governed by the BSD 3-clause license that * can be found in the LICENSE.txt file in the project root. */ #pragma once #include "RuleContext.h" namespace antlr4 { namespace atn { class ANTLR4CPP_PUBLIC ATN { public: static const size_t INVALID_ALT_NUMBER = 0; /// Used for runtime deserialization of ATNs from strings. ATN(); ATN(ATN &&other); ATN(ATNType grammarType, size_t maxTokenType); virtual ~ATN(); std::vector states; /// 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... std::vector decisionToState; /// Maps from rule index to starting state number. std::vector ruleToStartState; /// Maps from rule index to stop state number. std::vector ruleToStopState; /// The type of the ATN. ATNType grammarType; /// The maximum value for any symbol recognized by a transition in the ATN. size_t maxTokenType; /// /// 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 /// /// deserialization option was specified; otherwise, this is {@code null}. /// std::vector ruleToTokenType; /// For lexer ATNs, this is an array of {@link LexerAction} objects which may /// be referenced by action transitions in the ATN. std::vector> lexerActions; std::vector modeToStartState; ATN& operator = (ATN &other) NOEXCEPT; ATN& operator = (ATN &&other) NOEXCEPT; /// /// Compute the set of valid tokens that can occur starting in state {@code s}. /// If {@code ctx} is null, the set of tokens will not include what can follow /// the rule surrounding {@code s}. In other words, the set will be /// restricted to tokens reachable staying within {@code s}'s rule. /// virtual misc::IntervalSet nextTokens(ATNState *s, RuleContext *ctx) const; /// /// Compute the set of valid tokens that can occur starting in {@code s} and /// staying in same rule. is in set if we reach end of /// rule. /// virtual misc::IntervalSet const& nextTokens(ATNState *s) const; virtual void addState(ATNState *state); virtual void removeState(ATNState *state); virtual int defineDecisionState(DecisionState *s); virtual DecisionState *getDecisionState(size_t decision) const; virtual size_t getNumberOfDecisions() const; /// /// Computes the set of input symbols which could follow ATN state number /// {@code stateNumber} in the specified full {@code 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 /// of the outermost context without matching any /// symbols, is added to the returned set. ///

/// If {@code context} is {@code null}, it is treated as /// . ///

/// the ATN state number /// the full parse context /// The set of potentially valid input symbols which could follow the /// specified state in the specified context. /// if the ATN does not contain a state with /// number {@code stateNumber} virtual misc::IntervalSet getExpectedTokens(size_t stateNumber, RuleContext *context) const; std::string toString() const; private: mutable std::mutex _mutex; }; } // namespace atn } // namespace antlr4