question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generated parser code contains error

See original GitHub issue

I create a compiler with antlr and llvm in c++. I’ve created the two .g4 files and in my CMakeLists.txt I call the antlr jar to generate the lexer and the parser. Then I compile all my files with the same CMakeLists file and I got these errors :

Filc/src/generated/FilParser.cpp:803:16: error: invalid use of member function ‘antlrcppfil::FilParser::ExceptionContext* antlrcppfil::FilParser::ExprContext::exception()’ (did you forget the ‘()’ ?)
  803 |     _localctx->exception = std::current_exception();
      |     ~~~~~~~~~~~^~~~~~~~~
      |                         ()
Filc/src/generated/FilParser.cpp:804:43: error: invalid use of non-static member function ‘antlrcppfil::FilParser::ExceptionContext* antlrcppfil::FilParser::ExprContext::exception()’
  804 |     _errHandler->recover(this, _localctx->exception);
      |                                ~~~~~~~~~~~^~~~~~~~~

I looking in some tutorials and on stackoverflow why i’ve got these errors. But I didn’t found any mention of that. And in tutorials code they have the same code as me, but it compile.

So I tried to update my antlr version to version 4.11.1 (originally I use 4.8) but it doesn’t change anything.

For information, I use c++ 17, and this is my CMakeLists.txt :

project(Filc)

cmake_minimum_required(VERSION 3.10)

set(CMAKE_CXX_STANDARD 17)

set(antlr4-jar ${PROJECT_SOURCE_DIR}/bin/antlr-4.11.1-complete.jar)

set(antlr4-output
        ${PROJECT_SOURCE_DIR}/src/generated/FilLexer.cpp
        ${PROJECT_SOURCE_DIR}/src/generated/FilLexer.h
        ${PROJECT_SOURCE_DIR}/src/generated/FilParser.cpp
        ${PROJECT_SOURCE_DIR}/src/generated/FilParserBaseVisitor.cpp
        ${PROJECT_SOURCE_DIR}/src/generated/FilParserBaseVisitor.h
        ${PROJECT_SOURCE_DIR}/src/generated/FilParserVisitor.cpp
        ${PROJECT_SOURCE_DIR}/src/generated/FilParserVisitor.h
)

add_custom_target(GenerateLexerParser
        COMMAND java -jar ${antlr4-jar} -Dlanguage=Cpp -visitor -no-listener -o ${PROJECT_SOURCE_DIR}/src/generated/ -package antlrcppfil ${PROJECT_SOURCE_DIR}/src/antlr/FilLexer.g4 ${PROJECT_SOURCE_DIR}/src/antlr/FilParser.g4
        DEPENDS ${PROJECT_SOURCE_DIR}/src/antlr/FilLexer.g4 ${PROJECT_SOURCE_DIR}/src/antlr/FilParser.g4
)

include_directories(
        src
        src/generated
        src/utils
        antlr-runtime/src
)

add_executable(filc
        src/main.cpp
        src/utils/cxxopts.hpp
        src/generated/FilLexer.cpp
        src/generated/FilLexer.h
        src/generated/FilParser.cpp
        src/generated/FilParserBaseVisitor.cpp
        src/generated/FilParserBaseVisitor.h
        src/generated/FilParserVisitor.cpp
        src/generated/FilParserVisitor.h
)

add_dependencies(filc  GenerateLexerParser)

target_link_libraries(filc  antlr4-runtime.a)

install(TARGETS filc DESTINATION bin)

I’ve asked on stackoverflow and be redirected here.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Gashmobcommented, Sep 9, 2022

You’re right, it’s just that. I’ve already changed class, enum, null, but not think to exception. Thank you very much

0reactions
KvanTTTcommented, Sep 9, 2022

Agree.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generated parser code with antlr4.11.1 contains error
I tried the c++ target on one of my project and it compiled correctly in 4.9.3. Are you sure you didn't mix the...
Read more >
Reading 18: Parser Generators
A parser generator takes a grammar as input and automatically generates source code that can parse streams of characters using the grammar.
Read more >
yacc program error handling - IBM
When the parser reads an input stream, that input stream might not match the rules in the grammar file. The parser detects the...
Read more >
JavaCC | The most popular parser generator for use with Java ...
Hence the suffix Error in TokenMgrError . You do not have to worry about this exception - if you have designed your tokens...
Read more >
Error Handling and Recovery - ANTLR Parser Generator
ANTLR will generate default error-handling code, or you may specify your own exception handlers. Either case results (where supported by the language) in ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found