[antlr-interest] Puzzling Problem
Sam Barnett-Cormack
sdb at geekworld.co.uk
Sun Apr 9 09:09:59 PDT 2006
Scott Amort wrote:
> On Sun, 2006-04-09 at 16:20 +0100, Sam Barnett-Cormack wrote:
>
>>The error I get on running it is the slightly odd
>>
>>line 1:10: unexpected token: 0
>>
>>This is especially odd, as the grammar specifies that the first token it
>>should get *is* "0".
>
>
> Hi Sam,
>
> I can offer a guess at this, but I am still pretty new to ANTLR.
>
> I believe your lexer is returning a type of INT for the 0, while your
> parser is checking for a literal "0". Although you have turned on
> testLiterals in your INT rule in the lexer, the problem is that you have
> separate files for the parser and lexer. So, the lexer has no
> definition of the "0" literal. You need to import the parser vocabulary
> into your lexer to make this connection, and of course, this entails
> running antlr on the parser first to generate that vocab, then on the
> lexer.
And that would be a little odd... but I could instead statically define
the "0" literal in the lexer, I think... I just didn't think of the
effect of literals in the subgrammar. In fact, to be simpler, I could define
zero
: "0"
;
In the supergrammar (which I'm sure is technically a subgrammar, but
meh), and use zero where I used "0" in the subgrammar (which is
technically a supergrammar, I think, but I'm just confusing the issue).
Sam
More information about the antlr-interest
mailing list