[antlr-interest] Segmentation fault for org.antlr.runtime.UnwantedTokenException in libantlr3c-3.4

Shen Li shen.li.1978 at googlemail.com
Wed May 2 07:39:44 PDT 2012

Dear All,

Sorry to bother you with this presumably trivial question regarding the libantlr3c-3.4 target of ANTLR.

I generated the C code for the SimpleCalc example from


where I only changed the line

input  = antlr3AsciiFileStreamNew          ((pANTLR3_UINT8)argv[1]);


input  = antlr3FileStreamNew          ((pANTLR3_UINT8)argv[1], ANTLR3_ENC_8BIT);

in order to make the code compilable. The code works as expected if I run it on a correct input (e.g. "3+4"). If I run it on an incorrect input, however, (e.g. "+4"), the code gives the output

test.txt(1)  : error 9 : org.antlr.runtime.UnwantedTokenExceptionSegmentation fault: 11

("test.txt" is the input file.) I expected to see the "error 9" statement, but the "Segmentation fault" surprises me. Could somebody please point out how to amend the generated code so that it throws exceptions without resulting in segmentation faults?

Thanks a lot,

More information about the antlr-interest mailing list