[antlr-interest] Re: Exiting on parser errors

Greg Bedwell gregbedwell at gmail.com
Tue Jun 7 04:06:40 PDT 2005


(This is a rpely to a fairly old topic... I only just came back to the
antlr section of my program and it is still bugging me :))

>>In simple terms, I just want to call exit(1) as soon as the first
>>syntax error is detected by ANTLR and the error message is displayed.
>>
>>
>Try putting "defaultErrorHandler=false;" in the >options block of your
>grammar file. This will prevent ANTLR from catching the
>ReconitionExceptions and other Exceptions itself and just allow the
>exception to propagate back up to the method that is actually calling
>the parsers.

I hate sounding thick here.  This is what I read in the documentation
and it does exit on errors which is what I wanted but I just get an
"Aborted" message rather than the lovely "error on line 14:5
(expecting '{')" messages that I was getting before.

I'm calling my antlr generated files from here:

try
{
    CodegenLexer lexer(ss1);
    CodegenParser parser(lexer);

    parser.program();
}
catch(exception& e)
{
    std::cerr << "exception: " << e.what() << std::endl;
    exit(1);
}

so if I was understanding correctly, at the very least I would expect
it to say "exception: Aborted" with the exception being thrown upwards
and caught by my catch block rather than caught by ANTLR.

What am I doing wrong that it is just saying "Aborted" rather than
"Error on line 14:5: Expecting '{'" before it exits.

Thanks


More information about the antlr-interest mailing list