[antlr-interest] Exiting on parser errors

Chris Black chris at lotuscat.com
Mon May 23 11:08:12 PDT 2005


Greg Bedwell wrote:

>[stuff deleted]
>Whenever the parser encounters a syntax error it tells me the location
>of the error and what was expected which is great but then it
>continues on through.  Due to the legacy of the program I am
>incorporating it into it will still pass the created data structure
>through to the next stage which causes a segmentation fault when
>errors have been found.
>
>I know I *could* build in some checks at this stage of the program for
>invalid data structures and exit the program there, but I'm sure there
>must be an easier way to do it from ANTLR.
>
>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.

Hope this helps,
Chris


More information about the antlr-interest mailing list