[antlr-interest] Switching keywords

Loring Craymer lgcraymer at yahoo.com
Tue Sep 5 13:28:06 PDT 2006


I'd tend to do the individual keywords as separate rules:

target:
    :    
    { input.LT(1).getText().equals("target") }? TEXT
    ;

and then lump them in a rule

variable
    :
    target
    |
        within
    |
        get
    |
        set
    ;

and then

v = keyword

to replace the subrule in rule1.  Or you could just do

{ input.LT(1).getText().equals("target"}?  v = TEXT
|
    { input.LT(1).getText().equals("within")}? v = TEXT
...

or even just do one horrible looking sempred.

--Loring

Sean Walton <swalton at cs.utah.edu> wrote: Sean Walton wrote:
> I mean "'A' statements are embedded in 'B' programs".
> Thanks for the tip.  I am using 3.0 -- would 
> "input.LT(1).getText().equals("includes")}?" be a reasonable solution?
> -Sean
Here's a more specific example.  Could you help me with the variable?

rule1
    : (v='target' | v='within' | v='get' | v='set') '(' identifier ')'
            -> ^(RULE_MODULE $v identifier)
    ;


-Sean


 		
---------------------------------
How low will we go? Check out Yahoo! Messenger’s low  PC-to-Phone call rates.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060905/534625ef/attachment.html 


More information about the antlr-interest mailing list