[antlr-interest] [v3] LITERAL_xxx tokens?

David Holroyd dave at badgers-in-foil.co.uk
Wed Aug 16 06:39:07 PDT 2006


On Wed, Aug 16, 2006 at 10:40:33AM +0100, Anthony Youngman wrote:
> Is that defining a variable called IF, or STATIC ... ?

ANTLR 3 defines constants (in both the parser and the lexer) for
explicitly named tokens in the 'tokens { }' section or in the lexer,
yes.  For literals, it appears to be generating constants like 'T123'
for the token-who's-integer-type-value-is-'123', rather than constants
with human-readable names.


> That will blow up a heck of a lot of languages. I guess that's why v2
> prefixed everything with LITERAL_ - precisely to prevent explosions when
> compiling the grammar.

My specific examples above don't cause a problem in my specific target
language (Java).

Anyway, I imagine ANTLR needs some way of 'mangling' values which are
keywords in the target language anyway, no?


> Note to Ter - not that I have any use for it - might it make sense for
> v3 to generate this stuff automatically if asked by a switch - seeing as
> people like David have a need for it?

No need for a switch, IMO.  Keep the UI simple ;)


> -----Original Message-----
> From: antlr-interest-bounces at antlr.org
> [mailto:antlr-interest-bounces at antlr.org] On Behalf Of David Holroyd
> Sent: 16 August 2006 10:16
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] [v3] LITERAL_xxx tokens?
> 
> On Wed, Aug 16, 2006 at 07:41:17AM +0000, David Holroyd wrote:
> > For the moment, I'll just add lots of entries like
> > 
> >   tokens { IF='if'; STATIC='static'; ... }
> 
> Now that I think about it more, maybe this is actually a better way to
> define a concrete interface between the parser and the application than
> all those LITERAL_.. thingies anyway.  Nice to have them both using
> STATIC to refer to the same thing, eh?
> 
> It'll be a *lot* easier to use IDE-auto-complete from the java side
> without that common prefix everywhere too! ;)
> 
> 
> ta,
> dave
> 
> -- 
> http://david.holroyd.me.uk/
> 
> * ************************************************************************ *
> 
> This transmission is intended for the named recipient only. It may contain private and confidential information. If this has come to you in error you must not act on anything disclosed in it, nor must you copy it, modify it, disseminate it in any way, or show it to anyone. Please e-mail the sender to inform us of the transmission error or telephone ECA International immediately and delete the e-mail from your information system.
> 
> Telephone numbers for ECA International offices are: Sydney +61 (0)2 8272 5300, Hong Kong + 852 2121 2388, London +44 (0)20 7351 5000 and New York +1 212 582 2333.
> 
> * ************************************************************************ *

-- 
"Your shoes are on the wrong feet, or your feet are on the wrong legs.
And you have gloves on inside, which we all know is unlucky. I'm actually
in your desk drawer. Don't try and find me though. I'm quick. Really quick."
                                                      -- AW


More information about the antlr-interest mailing list