[antlr-interest] A Question on FAQ
Gokulakannan Somasundaram
gokul007 at gmail.com
Thu Dec 25 13:23:11 PST 2008
Hi,
I was going through the FAQ "How can I allow keywords as identifiers?".
The example is like this
*grammar Pred;
prog: stat+ ;
stat: keyIF expr stat
| keyCALL ID ';'
| ';'
;
expr: ID
;
keyIF : {input.LT(1).getText().equals("if")}? ID ;
keyCALL : {input.LT(1).getText().equals("call")}? ID ;
ID : 'a'..'z'+ ;
WS : (' '|'\n')+ {$channel=HIDDEN;} ;
*
My doubt is, why can't we write KeyIF and KeyCall as
KEYIF : 'if';
KEYCALL : 'call';
instead of writing like the above one. Or am i just repeating what is
already told in the second alternative in the same FAQ?
Thanks,
Gokul.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081226/87c8885c/attachment.html
More information about the antlr-interest
mailing list