[antlr-interest] ANTLR 3.0ea3 released

Terence Parr parrt at cs.usfca.edu
Fri Jun 24 14:32:42 PDT 2005


On Jun 24, 2005, at 2:01 PM, Andy Tripp wrote:

>> On Jun 24, 2005, at 8:18 AM, Gerald B. Rosenberg wrote: > Even  
>> where carry forward would work, look-back may simply be a >  
>> cleaner conceptual model in some situations. hi. My experience is  
>> that if you need to look back, it's just as easy to keep a ptr in  
>> each rule of interest you enter so you can simply ask for the tree  
>> location for the rule above you.
> Doesn't that mean that in general, you have to keep a ptr for  
> essentially all rules?
> In other words, if I want to know if the current statement is  
> somewhere within a
> "for" block, I need to keep a ptr at each rule in which I might end  
> up with an AST
> that has a "statement" somewhere under a "for".

Hi.  Actually you just need a single pointer: currentStatement and  
define it once in stat rule I think.

> That seems a lot more difficult than just overriding CommonAST to  
> provide a parent and
> being done with it.

A lot slower to do the walk though... ;)

>> Remember that when you want to look up, you mean you want to know  
>> your context.
> Not always. I often had to look at other places in the AST, and a  
> stack with the current
> context wouldn't have done it. For example, when manipulating C  
> code, I see a "%d"
> somewhere, look up the tree for the "printf" node, and then look  
> down for the appropriate
> child to get the "printf" argument that matches my "%d". Context is  
> not enough.

currentExpression will get that for you. ;)  Walk down from  
currentExpression.

Ter
--
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com



More information about the antlr-interest mailing list