[antlr-interest] How to get ANTLR 3.2 to exit upon first error?

Kirby Bohling kirby.bohling at gmail.com
Mon Mar 15 13:41:06 PDT 2010


You need to repeat some of that for the lexer.  Using the
@lexer::members syntax if you're going to do it as a combined
lexer/parser grammar (I always separate mine to keep my mental working
set smaller).  If you don't do the lexer, you can have a lex error and
recover from it, but this should catch all of the parse errors.

Kirby


On Mon, Mar 15, 2010 at 3:32 PM, Andrew Haritonkin <thikone at gmail.com> wrote:
> For Java and C# target add this in the beginning of the grammar but
> after grammar statement:
>
> grammar grammar1;
>
> @members {
> protected override object RecoverFromMismatchedToken(IIntStream input,
> int ttype, BitSet follow)
> {
>        throw new MismatchedTokenException(ttype, input);
> }
> public override object RecoverFromMismatchedSet(IIntStream input,
> RecognitionException e, BitSet follow)
> {
>        throw e;
> }
> }
>
> @rulecatch {
> catch (RecognitionException e)
> {
>    throw e;
> }
> }
>
> Hope it helps,
> Andrew
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


More information about the antlr-interest mailing list