]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/runtime/src/atn/LL1Analyzer.h
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / runtime / src / atn / LL1Analyzer.h
1 /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2  * Use of this file is governed by the BSD 3-clause license that
3  * can be found in the LICENSE.txt file in the project root.
4  */
5
6 #pragma once
7
8 #include "Token.h"
9 #include "support/BitSet.h"
10 #include "atn/PredictionContext.h"
11 #include "atn/ATNConfig.h"
12
13 namespace antlr4 {
14 namespace atn {
15
16   class ANTLR4CPP_PUBLIC LL1Analyzer {
17   public:
18     /// Special value added to the lookahead sets to indicate that we hit
19     ///  a predicate during analysis if {@code seeThruPreds==false}.
20 #if __cplusplus >= 201703L
21     static constexpr size_t HIT_PRED = Token::INVALID_TYPE;
22 #else
23     enum : size_t {
24       HIT_PRED = Token::INVALID_TYPE,
25     };
26 #endif
27
28     const atn::ATN &_atn;
29
30     LL1Analyzer(const atn::ATN &atn);
31     virtual ~LL1Analyzer();
32
33     /// <summary>
34     /// Calculates the SLL(1) expected lookahead set for each outgoing transition
35     /// of an <seealso cref="ATNState"/>. The returned array has one element for each
36     /// outgoing transition in {@code s}. If the closure from transition
37     /// <em>i</em> leads to a semantic predicate before matching a symbol, the
38     /// element at index <em>i</em> of the result will be {@code null}.
39     /// </summary>
40     /// <param name="s"> the ATN state </param>
41     /// <returns> the expected symbols for each outgoing transition of {@code s}. </returns>
42     virtual std::vector<misc::IntervalSet> getDecisionLookahead(ATNState *s) const;
43
44     /// <summary>
45     /// Compute set of tokens that can follow {@code s} in the ATN in the
46     /// specified {@code ctx}.
47     /// <p/>
48     /// If {@code ctx} is {@code null} and the end of the rule containing
49     /// {@code s} is reached, <seealso cref="Token#EPSILON"/> is added to the result set.
50     /// If {@code ctx} is not {@code null} and the end of the outermost rule is
51     /// reached, <seealso cref="Token#EOF"/> is added to the result set.
52     /// </summary>
53     /// <param name="s"> the ATN state </param>
54     /// <param name="ctx"> the complete parser context, or {@code null} if the context
55     /// should be ignored
56     /// </param>
57     /// <returns> The set of tokens that can follow {@code s} in the ATN in the
58     /// specified {@code ctx}. </returns>
59     virtual misc::IntervalSet LOOK(ATNState *s, RuleContext *ctx) const;
60
61     /// <summary>
62     /// Compute set of tokens that can follow {@code s} in the ATN in the
63     /// specified {@code ctx}.
64     /// <p/>
65     /// If {@code ctx} is {@code null} and the end of the rule containing
66     /// {@code s} is reached, <seealso cref="Token#EPSILON"/> is added to the result set.
67     /// If {@code ctx} is not {@code null} and the end of the outermost rule is
68     /// reached, <seealso cref="Token#EOF"/> is added to the result set.
69     /// </summary>
70     /// <param name="s"> the ATN state </param>
71     /// <param name="stopState"> the ATN state to stop at. This can be a
72     /// <seealso cref="BlockEndState"/> to detect epsilon paths through a closure. </param>
73     /// <param name="ctx"> the complete parser context, or {@code null} if the context
74     /// should be ignored
75     /// </param>
76     /// <returns> The set of tokens that can follow {@code s} in the ATN in the
77     /// specified {@code ctx}. </returns>
78     virtual misc::IntervalSet LOOK(ATNState *s, ATNState *stopState, RuleContext *ctx) const;
79
80     /// <summary>
81     /// Compute set of tokens that can follow {@code s} in the ATN in the
82     /// specified {@code ctx}.
83     /// <p/>
84     /// If {@code ctx} is {@code null} and {@code stopState} or the end of the
85     /// rule containing {@code s} is reached, <seealso cref="Token#EPSILON"/> is added to
86     /// the result set. If {@code ctx} is not {@code null} and {@code addEOF} is
87     /// {@code true} and {@code stopState} or the end of the outermost rule is
88     /// reached, <seealso cref="Token#EOF"/> is added to the result set.
89     /// </summary>
90     /// <param name="s"> the ATN state. </param>
91     /// <param name="stopState"> the ATN state to stop at. This can be a
92     /// <seealso cref="BlockEndState"/> to detect epsilon paths through a closure. </param>
93     /// <param name="ctx"> The outer context, or {@code null} if the outer context should
94     /// not be used. </param>
95     /// <param name="look"> The result lookahead set. </param>
96     /// <param name="lookBusy"> A set used for preventing epsilon closures in the ATN
97     /// from causing a stack overflow. Outside code should pass
98     /// {@code new HashSet<ATNConfig>} for this argument. </param>
99     /// <param name="calledRuleStack"> A set used for preventing left recursion in the
100     /// ATN from causing a stack overflow. Outside code should pass
101     /// {@code new BitSet()} for this argument. </param>
102     /// <param name="seeThruPreds"> {@code true} to true semantic predicates as
103     /// implicitly {@code true} and "see through them", otherwise {@code false}
104     /// to treat semantic predicates as opaque and add <seealso cref="#HIT_PRED"/> to the
105     /// result if one is encountered. </param>
106     /// <param name="addEOF"> Add <seealso cref="Token#EOF"/> to the result if the end of the
107     /// outermost context is reached. This parameter has no effect if {@code ctx}
108     /// is {@code null}. </param>
109   protected:
110     virtual void _LOOK(ATNState *s, ATNState *stopState, Ref<PredictionContext> const& ctx, misc::IntervalSet &look,
111       ATNConfig::Set &lookBusy, antlrcpp::BitSet &calledRuleStack, bool seeThruPreds, bool addEOF) const;
112   };
113
114 } // namespace atn
115 } // namespace antlr4