[antlr-interest] Debugging: how? (Why do I get MismatchedTokenException or UnwantedTokenException?) Unhelpful error messages.
John B. Brodie
jbb at acm.org
Tue Oct 28 08:36:59 PDT 2008
Hendrik Maryns asked:
> I showed you my grammar yesterday. Now trying it out on some simple
> inputs blows me away right away: it doesn’t even parse anything.
Your problem seems to be with your Lexer rule for LABEL which is :
LABEL : ~(')')+ ;
this means that any sequence of characters that is not a ')' must be a LABEL.
another problem is that ')' is not matched by any Lexer rule. did you want
OPEN and CLOSE to be parens?
> For example, if I give “(word x Einführung)” as input to the rule
so all of the characters but the last are consumed as a LABEL token and we are
left with a ')' which is not matched by any Lexer rule.
> I get MismatchedTokenException (0!=0). Strangely enough, I
> do not think 0 is not equal to 0, but I have no idea what this is
> supposed to tell me.
I do not use AntlrWorks so can not help here. But I have seen similar messages
when I have not re-compiled every source file after applying a change to a
> If I feed it to formulaList, I get an UnwantedTokenException followed by
> an EOF, which doesn’t make me any wiser at this point.
Yes. Confusing message. Which is just one of the reasons I do not use
AntlrWorks.... (i assume you are using AntlrWroks? if so, maybe there is more
useful information in the console window?)
When I use a command line based test setup, I get thus:
line 1:18 no viable alternative at character ')'
line 1:0 extraneous input '(word x Einführung' expecting EOF
> Grateful for any suggestions,
>.....remainder of message snipped....
Hope this helps
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the antlr-interest