/* 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 "misc/IntervalSet.h" namespace antlr4 { namespace atn { /// /// The following images show the relation of states and /// for various grammar constructs. /// /// /// ///

Basic Blocks

/// ///

Rule

/// /// /// ///

Block of 1 or more alternatives

/// /// /// ///

Greedy Loops

/// ///

Greedy Closure: {@code (...)*}

/// /// /// ///

Greedy Positive Closure: {@code (...)+}

/// /// /// ///

Greedy Optional: {@code (...)?}

/// /// /// ///

Non-Greedy Loops

/// ///

Non-Greedy Closure: {@code (...)*?}

/// /// /// ///

Non-Greedy Positive Closure: {@code (...)+?}

/// /// /// ///

Non-Greedy Optional: {@code (...)??}

/// /// ///
class ANTLR4CPP_PUBLIC ATN; class ANTLR4CPP_PUBLIC ATNState { public: ATNState(); ATNState(ATNState const&) = delete; virtual ~ATNState(); ATNState& operator=(ATNState const&) = delete; #if __cplusplus >= 201703L static constexpr size_t INITIAL_NUM_TRANSITIONS = 4; static constexpr size_t INVALID_STATE_NUMBER = std::numeric_limits::max(); #else enum : size_t { INITIAL_NUM_TRANSITIONS = 4, INVALID_STATE_NUMBER = static_cast(-1), // std::numeric_limits::max(); doesn't work in VS 2013 }; #endif enum { ATN_INVALID_TYPE = 0, BASIC = 1, RULE_START = 2, BLOCK_START = 3, PLUS_BLOCK_START = 4, STAR_BLOCK_START = 5, TOKEN_START = 6, RULE_STOP = 7, BLOCK_END = 8, STAR_LOOP_BACK = 9, STAR_LOOP_ENTRY = 10, PLUS_LOOP_BACK = 11, LOOP_END = 12 }; static const std::vector serializationNames; size_t stateNumber = INVALID_STATE_NUMBER; size_t ruleIndex = 0; // at runtime, we don't have Rule objects bool epsilonOnlyTransitions = false; public: virtual size_t hashCode(); bool operator == (const ATNState &other); /// Track the transitions emanating from this ATN state. std::vector transitions; virtual bool isNonGreedyExitState(); virtual std::string toString() const; virtual void addTransition(Transition *e); virtual void addTransition(size_t index, Transition *e); virtual Transition* removeTransition(size_t index); virtual size_t getStateType() = 0; private: /// Used to cache lookahead during parsing, not used during construction. misc::IntervalSet _nextTokenWithinRule; std::atomic _nextTokenUpdated { false }; friend class ATN; }; } // namespace atn } // namespace antlr4