[antlr-interest] Exiting on parser errors

Greg Bedwell gregbedwell at gmail.com
Mon May 23 02:59:45 PDT 2005


I'm new to ANTLR so I expect this is a pretty simple question.  I've
looked through the docs and tohugh I;ve found stuff hinting towards
this I've not been able to see a simple explanation as far as I can
see.

I'm using ANTLR to generate C++ to parse a simple language of my own
design.  Initially I wrote my own parser but as the language grew more
complex I decided to see what a proper tool could do.  It's worked
wonders and I can't fault it, but I'm just running into a simple
problem.

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.

Thanks.


More information about the antlr-interest mailing list