[antlr-interest] Creating tokens on error

Randall R Schulz rschulz at sonic.net
Sun Apr 6 11:20:23 PDT 2008


On Sunday 06 April 2008 10:41, Marko Simovic wrote:
> If I have a parser rule for addition that looks like this:
>
> sum	:	something (Plus^ something)*;
>
> it works fine for input like:
>
> a+b
>
> however, if I have input such as:
>
> a+
>
> which is invalid syntax (and causes a NoViableAltException), I would
> like the parser to generate a "placeholder" token for the missing
> operand. Is this possible?

I don't know if ANTLR has built-in support for this sort of thing, but 
what I do is write productions for common error cases and in their 
actions issue a diagnostic and then supply distinctive placeholders for 
the missing elements (or simply drop superfluous ones, as the case may 
be).


> Thanks,
> Marko


Randall Schulz


More information about the antlr-interest mailing list