In `c++`, can't load build/libparser.a as lexer or parser.

60 views
Skip to first unread message

Vifird Micho

unread,
Dec 26, 2019, 10:46:48 PM12/26/19
to antlr-discussion

I'm using c++ parser code(and runtime), and i dont know how to use grun with c++, i can use it fine with java.
The grammar is ok, the parser file is ok( i can use it to parse my code to ParserTree ), the problem may be the object file of parser.
Here are my CMakeLists.txt:

include_directories(
  $ENV{ANTLR_RUNTIME}/include
)
include_directories(
  ${PROJECT_SOURCE_DIR}/src
)
# cpp files of parser
file(GLOB parser_files
  ${PROJECT_SOURCE_DIR}/src/grammar/*.cpp
)

add_library(parser ${parser_files} $ENV{ANTLR_RUNTIME}/lib/libantlr4-runtime.a)
# target_link_libraries(parser)

This will create build/libparser.a, then i run grun build/libparser.a program -gui "var a=1;", error occured:

Can't load build/libparser.a as lexer or parser

The same error occured if i add target_link_libraries(parser) to CMakeLists.txt.

So what should be the type of the parser file? How could i generate it in c++?

Mike Lischke

unread,
Dec 27, 2019, 4:47:23 AM12/27/19
to antlr-discussion

I'm using c++ parser code(and runtime), and i dont know how to use grun with c++, i can use it fine with java.This will create build/libparser.a, then i run grun build/libparser.a program -gui "var a=1;", error occured:

Can't load build/libparser.a as lexer or parser
grun is a Java app (actually the TestRig class used by that grun script) and cannot load C++ libs. The TestRig class has not been translated to C++ because there you cannot load and run arbitrary code like you can in Java (and python for that matter, where a pygrun file exists).


Vifird Micho

unread,
Dec 30, 2019, 12:36:35 AM12/30/19
to antlr-discussion
Thanks a lot. Feeling sad for this.

在 2019年12月27日星期五 UTC+8下午5:47:23,Mike Lischke写道:
Reply all
Reply to author
Forward
0 new messages