On 06/26/16 20:18, Cleverson Ledur wrote:
> Hi Kevin,
>
> Thank you for suggesting this demo. I tried to compile this, but without
> success.
I was able to use the code in the demo, to help port a program I already
had running in ANTLR2 and ANTLR3. So, basically, it was just a question
of "what is the magic incantation(s) to use with ANTLR4".
Mike helped me choose the proper C++ support libraries (wide streams).
> I had some problems when trying to compile this. Basically I generated
> the files using the generate.sh file through uncommenting the following
> commands and inserting $LOCATION path to ANTLR jar file:
> java -jar $LOCATION -Dlanguage=Cpp-listener -visitor -o
> generated/-packageantlrcpptest TLexer.g4 TParser.g4
> After I copied the main.cpp file to "generated" folder, to have all
> ".cpp" files in the same folder.
> Then, inside generated folder, I tried the following compilation command:
>
> |
> g++-fPIC -shared -g -O3 -Wall-std=c++11*.cpp -I.-I ../../runtime/src/-I
> ../../runtime/src/atn/-I ../../runtime/src/dfa/-I
> ../../runtime/src/misc/-I ../../runtime/src/tree/-I
> ../../runtime/src/support/-I ../../runtime/src/tree/pattern/-I
> ../../runtime/src/tree/xpath/ -o parser
> |
I have a Makefile that needed some tweaking for ANTLR4, the basics are
the following:
CC = g++
CFLAGS = -fPIC -shared -g -O3 -Wall -std=c++11 $(NUMERRORS)
LDFLAGS =
IFLAGS =-I../antlrcpp -I. -I$(RUNTIME) -I$(RUNTIME)/atn\
-I$(RUNTIME)/dfa -I$(RUNTIME)/misc -I$(RUNTIME)/tree\
-I$(RUNTIME)/tree/pattern -I$(RUNTIME)/tree/xpath\
-I$(RUNTIME)/support
Then I used:
$(CC) $(IFLAGS) $(CFLAGS) -o $@ -c $<
to compile each file, and:
$(CC) -o program $(obj_FILES) ./libantlr4.a
to link them into an executable.
My program (now) runs fine.
> When I tried to execute ./parser, this gives me a segmentation fault.
What is the file type of your file parser? On Linux for me, it is an
ELF executable. Did all of your C++ files compile without errors? Did
the linking succeed with unresolved references? What did you use for
the antlr4 runtime library? Are you using the shared library or the
object archive?
> I ran gdb and the output is the following:
> |
>
> Programreceived signal SIGSEGV,Segmentationfault.
> 0x0000000000017dd6in??()
> (gdb)backtrace
> #0 0x0000000000017dd6 in ?? ()
> #1 0x000055555556bfa0 in __static_initialization_and_destruction_0
> (__initialize_p=1, __priority=65535) at /usr/include/c++/5/iostream:74
> #2 _GLOBAL__sub_I_main.cpp(void) () at main.cpp:33
> (gdb)
Didn't Mike say we should use wiostream?
> Did you have success compiling this demo? Could you describe how you did
> or suggest what am I doing wrong?
Can't say without seeing more of your specifics. Note that the demo
program uses wstring to store the string to be parsed....
> Thank you very much.
--