[antlr-interest] Switching keywords

Loring Craymer lgcraymer at yahoo.com
Tue Sep 5 10:04:24 PDT 2006


What do you mean by "on top of"?  Do you mean that "A" statements are embedded in "B" programs?  Or that "B" compiles to "A"?

If you just need to handle tokens that are keywords in one context and not another, then these are best handled as

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

and then use "keyword" in the appropriate context.  Semantic predicate hoisting is very handy, and "is a keyword only in context" is a common problem.

--Loring


Sean Walton <swalton at cs.utah.edu> wrote: [This is for anyone that can answer this problem.]
I am building a language (B) on top of another language (A).  This 
causes a particular problem with any new reserved words defined in 
Language B.  For example, if there needs to be a reserved word 'set' in 
Language B, but when in the context of Language A, 'set' still needs to 
be an identifier.
Does anyone have any ideas how to do this?
-Sean Walton
PS. The real development is honestly more complicated than the above: 
there is a third language (C) involved.  Why?  I guess I like pain.... ;)


 		
---------------------------------
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/7ec32b63/attachment.html 


More information about the antlr-interest mailing list