LexerInterpreter.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #include "atn/ATNType.h"
  6. #include "atn/LexerATNSimulator.h"
  7. #include "dfa/DFA.h"
  8. #include "Exceptions.h"
  9. #include "Vocabulary.h"
  10. #include "LexerInterpreter.h"
  11. using namespace antlr4;
  12. LexerInterpreter::LexerInterpreter(const std::string &grammarFileName, const dfa::Vocabulary &vocabulary,
  13. const std::vector<std::string> &ruleNames, const std::vector<std::string> &channelNames, const std::vector<std::string> &modeNames,
  14. const atn::ATN &atn, CharStream *input)
  15. : Lexer(input), _grammarFileName(grammarFileName), _atn(atn), _ruleNames(ruleNames),
  16. _channelNames(channelNames), _modeNames(modeNames),
  17. _vocabulary(vocabulary) {
  18. if (_atn.grammarType != atn::ATNType::LEXER) {
  19. throw IllegalArgumentException("The ATN must be a lexer ATN.");
  20. }
  21. for (size_t i = 0; i < atn.getNumberOfDecisions(); ++i) {
  22. _decisionToDFA.push_back(dfa::DFA(_atn.getDecisionState(i), i));
  23. }
  24. _interpreter = new atn::LexerATNSimulator(this, _atn, _decisionToDFA, _sharedContextCache); /* mem-check: deleted in d-tor */
  25. }
  26. LexerInterpreter::~LexerInterpreter()
  27. {
  28. delete _interpreter;
  29. }
  30. const atn::ATN& LexerInterpreter::getATN() const {
  31. return _atn;
  32. }
  33. std::string LexerInterpreter::getGrammarFileName() const {
  34. return _grammarFileName;
  35. }
  36. const std::vector<std::string>& LexerInterpreter::getRuleNames() const {
  37. return _ruleNames;
  38. }
  39. const std::vector<std::string>& LexerInterpreter::getChannelNames() const {
  40. return _channelNames;
  41. }
  42. const std::vector<std::string>& LexerInterpreter::getModeNames() const {
  43. return _modeNames;
  44. }
  45. const dfa::Vocabulary& LexerInterpreter::getVocabulary() const {
  46. return _vocabulary;
  47. }