LL1Analyzer.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #pragma once
  6. #include "Token.h"
  7. #include "atn/ATNConfig.h"
  8. #include "atn/PredictionContext.h"
  9. #include "support/BitSet.h"
  10. namespace antlr4 {
  11. namespace atn {
  12. class ANTLR4CPP_PUBLIC LL1Analyzer final {
  13. public:
  14. /// Special value added to the lookahead sets to indicate that we hit
  15. /// a predicate during analysis if {@code seeThruPreds==false}.
  16. static constexpr size_t HIT_PRED = Token::INVALID_TYPE;
  17. explicit LL1Analyzer(const atn::ATN &atn) : _atn(atn) {}
  18. /// <summary>
  19. /// Calculates the SLL(1) expected lookahead set for each outgoing transition
  20. /// of an <seealso cref="ATNState"/>. The returned array has one element for each
  21. /// outgoing transition in {@code s}. If the closure from transition
  22. /// <em>i</em> leads to a semantic predicate before matching a symbol, the
  23. /// element at index <em>i</em> of the result will be {@code null}.
  24. /// </summary>
  25. /// <param name="s"> the ATN state </param>
  26. /// <returns> the expected symbols for each outgoing transition of {@code s}. </returns>
  27. std::vector<misc::IntervalSet> getDecisionLookahead(ATNState *s) const;
  28. /// <summary>
  29. /// Compute set of tokens that can follow {@code s} in the ATN in the
  30. /// specified {@code ctx}.
  31. /// <p/>
  32. /// If {@code ctx} is {@code null} and the end of the rule containing
  33. /// {@code s} is reached, <seealso cref="Token#EPSILON"/> is added to the result set.
  34. /// If {@code ctx} is not {@code null} and the end of the outermost rule is
  35. /// reached, <seealso cref="Token#EOF"/> is added to the result set.
  36. /// </summary>
  37. /// <param name="s"> the ATN state </param>
  38. /// <param name="ctx"> the complete parser context, or {@code null} if the context
  39. /// should be ignored
  40. /// </param>
  41. /// <returns> The set of tokens that can follow {@code s} in the ATN in the
  42. /// specified {@code ctx}. </returns>
  43. misc::IntervalSet LOOK(ATNState *s, RuleContext *ctx) const;
  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="stopState"> the ATN state to stop at. This can be a
  55. /// <seealso cref="BlockEndState"/> to detect epsilon paths through a closure. </param>
  56. /// <param name="ctx"> the complete parser context, or {@code null} if the context
  57. /// should be ignored
  58. /// </param>
  59. /// <returns> The set of tokens that can follow {@code s} in the ATN in the
  60. /// specified {@code ctx}. </returns>
  61. misc::IntervalSet LOOK(ATNState *s, ATNState *stopState, RuleContext *ctx) const;
  62. private:
  63. const atn::ATN &_atn;
  64. };
  65. } // namespace atn
  66. } // namespace antlr4