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++?
I'm using
c++
parser code(and runtime), and i dont know how to usegrun
withc++
, i can use it fine withjava
.This will createbuild/libparser.a
, then i rungrun 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).