[antlr-interest] digit-ended literals (was New faq entries - import/export)

Bogdan Mitu bogdan at nobugconsulting.ro
Tue Oct 30 04:30:32 PST 2001


----- Original Message -----
From: "Terence Parr" <parrt at jguru.com>

> What exactly is the bug you refer to?  "if0" is specifically a literal
> that doesn't work or is the whole literals scheme broken from your
> perspective?
>
> Ter

I looked more closely to what is generated, and it's not a bug, indeed, but
still is something weird. If I have a string "if" in the parser, it
generates an entry:
int LITERAL_if = 4
in the interface XxxParserTokenTypes.java

But if the string is "if0", the generated line is just a comment:
// "if0" = 4

I thought this is a bug, but it works, because a number is still reserved
for the token. There is still a problem, however: if I want to refer the
tokens from outside, I can only use the number (in this example 4), and this
number is likely to change whenever I change the grammar. I don't see any
reason why literals ended with digits are treated different.

Best regards,
Bogdan


> On Monday, October 29, 2001, at 09:57  AM, Bogdan Mitu wrote:
>
> > Hi Ter,
> >
> > I have some comments about the 3rd entry: Why can't I get the
> > exportVocab/importVocab directives to work with string literals across
> > multiple files?
> >
> > I will argue that:
> > 1. The real problem with that grammar is not the import/export
> > relation, but
> > a bug in ANTLR.
> > 2. The approach suggested for import/export, while correct (when not
> > problem
> > 1.), is not the best.
> >
> > 1. String literals in parser are not always converted to lexer tokens.
> > For
> > instance, an occurrence of the string "if" in the parser grammar is
> > translated to LITERAL_if, but string "if0" (with a digit at the end) is
> > not
> > converted to anything (just a commented line in XxxTokenTypes.txt). The
> > same
> > happens in the grammar that originated this thread, were the string was
> > ".accept" (starting with dot), and was not converted properly. This a
> > bug in
> > ANTLR.
>
> I use string literals across multiple files all the time (for example,
> my tree grammars use literals all the time).
>
> What exactly is the bug you refer to?  "if0" is specifically a literal
> that doesn't work or is the whole literals scheme broken from your
> perspective?
>
> Ter
> --
> Chief Scientist & Co-founder, http://www.jguru.com
> Creator, ANTLR Parser Generator: http://www.antlr.org
>
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>



More information about the antlr-interest mailing list