[antlr-interest] MismatchedTokenException and how to find errors in ANTLRWorks

Thomas Brandon tbrandonau at gmail.com
Tue Feb 12 17:30:17 PST 2008


On Feb 13, 2008 10:58 AM, Guntis Ozols <guntiso at latnet.lv> wrote:

> Sure it is confusing. I fell into this 'xy' trap, too.
> If COLON is defined and STAR is defined, then creating
> another token for ':*' in a *parser* rule is confusing.
> It should be fixed in antlr.
> At least, antlr should emit 'anonymous token' warning[s].
>
> I prefer literals because of simplicity / readability.
> The tool needs to be patched, not users.
>
> Guntis
>
> If I understand your "problem" I don't think this can be fixed. If you
type ':*', how can ANTLR know you don't want ':*' as a single token. It is
perfectly valid to have ':', '*' and ':*' tokens, so this is what ANTLR
produces.
And emitting a warning just because you use a perfectly valid (if easily
misusable) construct doesn't seem right.
Unfortunately I don't think this is a case where ANTLR can protect you from
yourself.
Perhaps literals could be allowed in the parser but only to refer to tokens
defined in the lexer, generating an error otherwise. That should alleviate
many (if not all) of the issues while still allowing the stylistic choice
some seem to want.

Tom.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080213/e2a30f1b/attachment.html 


More information about the antlr-interest mailing list