[antlr-interest] A question about literals

Bogdan Mitu bogdan_mt at yahoo.com
Sat Aug 31 09:35:19 PDT 2002


Hi Richard,

It is not a bug, it's a feature ;-)
For ANTLR it's enough to *reserve* a new integer for each literal. In normal
cases, ANTLR also creates a field in XxxTokenTypes.java called
LITERAL_<name>. But it only does it if <name> contains only plain letters
(no digits, no special symbols). Otherwise it just reserve an integer and
add a comments in XxxTokenTypes.java.

This is understandable for special characters like #, because
LITERAL_#include wouldn't be a valid Java ID. But it could very easy accept
digits. Unfortunately it doesn't.

I met the same problem when working on a Verilog grammar. In Verilog there
actually *exist* keywords ending in digits (although I admit this is not the
case with most languages).

I have somewhere a patch for this, if I will find ot I will post it here,
with the hope that it will be included in the next release.

Best regards,
Bogdan



--- "Hensley, Richard" <richard.hensley at mckesson.com> wrote:
> I think it causes a problem because I have the LITERAL_xxx for
> everything else so I can use that when I'm cruising around in the AST
> doing what I need. I will goof around with the tokens section.
> 
> -----Original Message----- 
> From: mzukowski at yci.com [ mailto:mzukowski at yci.com
> <mailto:mzukowski at yci.com> ] 
> Sent: Friday, August 30, 2002 12:39 PM 
> To: antlr-interest at yahoogroups.com 
> Subject: RE: [antlr-interest] A question about literals 
> 
> 
> I should add that antlr is trying to protect itself from creating a
> variable 
> name that won't work in the target language.  It constructs the name
> from 
> your prefix "LITERAL_" and then the keyword.  
> 
> First: does this cause a problem for you, or are you just curious? 
> Second:  I believe you can use the tokens section to add a keyword and a
> 
> token name for it.  
> 
> 
> From http://www.antlr.org/doc/metalang.html#_bb1: 
> 
> You can also define literals in this section and, most importantly,
> assign 
> to them a valid label as in the following example. 
> 
> tokens { 
>     KEYWORD_VOID="void"; 
>     EXPR; 
>     DECL; 
>     INT="int"; 
> } 
> 
> Monty 
> 
> > -----Original Message----- 
> > From: mzukowski at yci.com [ mailto:mzukowski at yci.com
> <mailto:mzukowski at yci.com> ] 
> > Sent: Friday, August 30, 2002 12:31 PM 
> > To: antlr-interest at yahoogroups.com 
> > Subject: RE: [antlr-interest] A question about literals 
> > 
> > 
> > That's weird.  It probably doesn't like the '2' in varchar2.  Try 
> > varchar_two maybe? 
> > 
> > Monty 
> > 
> > > -----Original Message----- 
> > > From: richardhensley99 [ mailto:richard.hensley at mckesson.com
> <mailto:richard.hensley at mckesson.com> ] 
> > > Sent: Friday, August 30, 2002 12:21 PM 
> > > To: antlr-interest at yahoogroups.com 
> > > Subject: [antlr-interest] A question about literals 
> > > 
> > > 
> > > My grammar generates the following TokenTypes, however the varchar2 
> > > is commented, instead of being LITERAL_varchar2 = 16. Why does this 
> > > happen? 
> > > 
> > > public interface OracleDDLTokenTypes { 
> > >     int EOF = 1; 
> > >     int NULL_TREE_LOOKAHEAD = 3; 
> > >     int LITERAL_execute = 4; 
> > >     int COMMANDEND = 5; 
> > >     int ID = 6; 
> > >     int LPAREN = 7; 
> > >     int RPAREN = 8; 
> > >     int COMMA = 9; 
> > >     int QUOTED_STRING = 10; 
> > >     int LITERAL_whenever = 11; 
> > >     int LITERAL_sqlerror = 12; 
> > >     int LITERAL_create = 13; 
> > >     int LITERAL_table = 14; 
> > >     int LITERAL_tablespace = 15; 
> > >     // "varchar2" = 16 
> > >     int LITERAL_varchar = 17; 
> > >     int LITERAL_number = 18; 
> > >     int LITERAL_date = 19; 
> > >     int LITERAL_integer = 20; 
> > >     int LITERAL_long = 21; 
> > >     int LITERAL_raw = 22; 
> > >     int CARDINAL = 23; 
> > >     int LITERAL_index = 24; 
> > >     int LITERAL_view = 25; 
> > >     int LITERAL_drop = 26; 
> > >     int LITERAL_insert = 27; 
> > >     int WS = 28; 
> > >     int SL_COMMENT = 29; 
> > > } 
> > > 
> > > 
> > > 
> > >  
> > > 
> > > Your use of Yahoo! Groups is subject to 
> > > http://docs.yahoo.com/info/terms/
> <http://docs.yahoo.com/info/terms/>  
> > > 
> > > 
> > 
> >  
> > 
> > Your use of Yahoo! Groups is subject to 
> http://docs.yahoo.com/info/terms/ <http://docs.yahoo.com/info/terms/>  
> 
> 
>   
> 
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/ <http://docs.yahoo.com/info/terms/>  
> 
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list