[antlr-interest] amount of reserved keywords

Bogdan Mitu bogdan_mt at yahoo.com
Mon Jun 24 08:07:26 PDT 2002


--- gertgrossmann <Gert.Grossmann50 at epost.de> wrote:
> It is necessary that all literals are reserved keywords?
> IMHO this is slightly exaggerated.
> Or is there a possibilty to avoid this 'feature'?

Can you be more specific in describing your problem? This will increase your
chance to receive meaningful answers. If you want to write a grammar for a
language where keywords are not reserved, just don't use the option
"testLiterals=true;". You will loose, however, the ability to write "Xxx" in
the parser to denote a keyword; you will receive from the lexer an
identifier, and you will have to check the token's text to decide if in a
given context, it's a keyword or a true identifier.

Alternatively, you can write the lexer as if keywords were reserved
("testLiterals=true;"), and in the parser write a rule 
identifier
    :   IDENTIFIER | "keyword1" | "keyword2" ...
    ;

(Never did it, but should work ;)

Hope this helps,
Bogdan

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


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

 

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



More information about the antlr-interest mailing list