[antlr-interest] expecting "class", found 'class'
Sven Busse
mail at ghost23.de
Sat Feb 17 06:13:43 PST 2007
Hi,
arghh, after several days now, i found, what the problem is.
Since i originally copied the java grammar as a starting point
for my own, now i found this line in the Parser options caused the problem:
exportVocab = myLanguage;
I deleted the line and now it works.
I read, that exportVocab is allways set, also if you don't
actually provide it, so i don't really understand that.
Cheers
Sven
-----Ursprüngliche Nachricht-----
Von: Martin Probst [mailto:mail at martin-probst.com]
Gesendet: Mittwoch, 14. Februar 2007 08:34
An: Sven Busse
Cc: 'Ric Klaren'; antlr-interest at antlr.org
Betreff: Re: [antlr-interest] expecting "class", found 'class'
Hi,
> i have lexer and parser in one file. Using the
> traceLexer or traceParser didn't help me.
>
> What does this message mean anyway?
It means that the parser expected a token with the text 'class' and
found one with the text 'class'. The problem is that the parser
actually expected a token with a certain token type, and it found one
with a different token type. However the error message doesn't show
that (I hope this was fixed in ANTLR 3...).
So this is usually a bug coming from a rule IDENT like this:
IDENT: ('a'..'z' | 'A'..'Z')+;
And a rule:
CLASS: 'class';
Where the text 'class' can be matched by both rules, and somehow it
ends up being matched by IDENT where the parser expects a CLASS
token. This is a very common problem, and you can usually solve it by
removing the CLASS rule altogether and replacing it with a
testLiterals=true and simply write "class" in the parser, instead of
CLASS.
To further debug it, you will probably have to turn of the default
error handler, catch the exception, and investigate the actual token
types that are available from the exception. Those token types are
offsets into YourParser._tokenNames[], look there to find the token
name.
HTH,
Martin
More information about the antlr-interest
mailing list