[antlr-interest] variables and keywords

Anakreon p98043 at rainbow.cs.unipi.gr
Mon Jan 26 13:36:17 PST 2004


Rene' Jansen wrote:
> In the NetRexx language, when a string is used as a variable, it cannot 
> be a keyword anymore.  This is a great feature, and it comes out of the 
> real life experience that newly added keywords in most environments 
> (languages and toolkits) break existing programs. Now I've read about 
> (and used a bit) the keywords literals feature of Antlr, but I am at a 
> loss of how to specify the NetRexx behaviour in a grammar. Does anyone 
> have any pointers on how to implement such a feature, if I were to, 
> ahem, for example trying to make an antlr grammar for NetRexx?
> 
> Rene Vincent Jansen. 
> 
I wrote an asp parser where activeX objects may have methods which can be 
keywords for the language.
To solve the problem, I declared the tokens for each keyword in the tokens 
section, and populated a Map with keyword's text as the key, and an Integer 
having the value for the corresponding token.
Exmaple:
map.put("for", new Integer(FOR));
Then from the lexer, when the IDENTIFIER rule is matched, I would search in the 
map if a key with that text exists.If it did, the value corresponding to that 
key was assigned as the token type.Otherwise the Token would be an IDENTIFIER.


 

Yahoo! Groups Links

To visit your group on the web, go to:
 http://groups.yahoo.com/group/antlr-interest/

To unsubscribe from this group, send an email to:
 antlr-interest-unsubscribe at yahoogroups.com

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




More information about the antlr-interest mailing list