[antlr-interest] Handling Antlr Syntax Errors or how to give a better message on unexpected token

Burton Samograd burton.samograd at markit.com
Tue May 1 08:18:02 PDT 2012


Hello,

We have the following sub-part of an Antlr grammar:

    signed_int
            : SIGN? INT
                    ;

    INT : '0'..'9'+
            ;

When someone enters a numeric value everything is fine, but if they
mistakenly type something like 1O (one and capital o) we get a cryptic
error message like:

    error 1 : Missing token              at offset 14
    near [Index: 0 (Start: 0-Stop: 0) ='<missing COLON>'    type<24> Line: 26 LinePos:14]
     : syntax error...

Obviously our grammar is more complex than the one given above, but this type of
error happens when the user mistypes an integer as above.

What is a good way to handle this type of error?  I thought of
defining a catch-all SYMBOL token type but this lead to too many parser
building errors.  I will continue looking into Antlr error handling but I
thought I would post this here to look for some insights.

Also asked on Stack Overflow:  http://stackoverflow.com/questions/10386499/handling-antlr-syntax-errors-or-how-to-give-a-better-message-on-unexpected-token

--
Burton Samograd

________________________________
This e-mail, including accompanying communications and attachments, is strictly confidential and only for the intended recipient. Any retention, use or disclosure not expressly authorised by Markit is prohibited. This email is subject to all waivers and other terms at the following link: http://www.markit.com/en/about/legal/email-disclaimer.page

Please visit http://www.markit.com/en/about/contact/contact-us.page? for contact information on our offices worldwide.


More information about the antlr-interest mailing list