antlr / antlr4

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
http://antlr.org
BSD 3-Clause "New" or "Revised" License
17.27k stars 3.29k forks source link

Got error when compiling C++ result. #4351

Closed vega0 closed 1 year ago

vega0 commented 1 year ago
nigtmare@192 ~/Рабочее Пространство/rossijskij-yap $ ./Build.sh 
In file included from Сборка/ЧислаLexer.cpp:5,
                 from Main.cpp:4:
Сборка/ЧислаLexer.h:33:43: ошибка: «virtual const std::vector<std::basic_string<char> >& ЧислаLexer::getTokenNames() const» помечен «override», но не делается override
   33 |   virtual const std::vector<std::string>& getTokenNames() const override; // deprecated, use vocabulary instead
      |                                           ^~~~~~~~~~~~~
Сборка/ЧислаLexer.h:36:39: ошибка: некорректный ковариантный тип результата для «virtual const std::vector<short unsigned int> ЧислаLexer::getSerializedATN() const»
   36 |   virtual const std::vector<uint16_t> getSerializedATN() const override;
      |                                       ^~~~~~~~~~~~~~~~
In file included from antlr4/runtime/Cpp/runtime/src/Lexer.h:8,
                 from antlr4/runtime/Cpp/runtime/src/antlr4-runtime.h:31,
                 from Main.cpp:2:
antlr4/runtime/Cpp/runtime/src/Recognizer.h:58:36: замечание: overridden function is «virtual antlr4::atn::SerializedATNView antlr4::Recognizer::getSerializedATN() const»
   58 |     virtual atn::SerializedATNView getSerializedATN() const {
      |                                    ^~~~~~~~~~~~~~~~
In file included from Main.cpp:4:

Сборка.zip

kaby76 commented 1 year ago

You generated the recognizers using Antlr 4.9.2, but that's all we know. The .zip file contains a bunch of .cpp, .h, .interp, and .tokens files--but that's it. That leaves nothing left in figuring out how you are actually building your program in Build.sh. A program is more than just C++ source files.

vega0 commented 1 year ago

You generated the recognizers using Antlr 4.9.2, but that's all we know. The .zip file contains a bunch of .cpp, .h, .interp, and .tokens files--but that's it. That leaves nothing left in figuring out how you are actually building your program in Build.sh. A program is more than just C++ source files.

gcc -Lantlr4/runtime/Cpp/dist -lantlr4-runtime -IСборка/ -Iantlr4/runtime/Cpp/runtime/src/ Main.cpp Сборка/*.cpp

vega0 commented 1 year ago

Main.zip

You generated the recognizers using Antlr 4.9.2, but that's all we know. The .zip file contains a bunch of .cpp, .h, .interp, and .tokens files--but that's it. That leaves nothing left in figuring out how you are actually building your program in Build.sh. A program is more than just C++ source files.

https://github.com/adeharo9/antlr4-cpp-runtime

kaby76 commented 1 year ago

It is because you aren't using the correct Antlr runtime version with the tool that you used to generate the recognizers (I just verified; also, 4.9.1 != 4.9.2). I suggest you clone the repo, git checkout 5e5b6d3 (version 4.9.2), and compare the source you are using against what you got through the git clone/checkout. You can also check by compiling against the clone repo source and see that it works.

You should get in the habit of doing "due diligence" after each step. In general, I do not trust a single thing that I do. I have to check and recheck everything. Writing software has been that way since at least as long as I've been writing software, 48 years. You might also want to check gcc --version and make sure that you are up-to-date. When you report an error, you should get in the habit of reporting the versions of Antlr, toolchains, OS, etc.

vega0 commented 1 year ago

ah, ok.