[antlr-interest] ANTLR 3.0ea3 released
Terence Parr
parrt at cs.usfca.edu
Fri Jun 24 09:33:15 PDT 2005
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. Remember
that when you want to look up, you mean you want to know your
context. To me context means what rules led to this rule and what
input did they start with. For recursive stuff, you need a stack of
these pointers...ANTLR v3 should make this easier:
tree grammar t;
decl
scope {
Tree root;
}
init {
root = input.LT(1); // point at input tree node for this rule
}
: type declarator ';'
;
declarator
: ID {$decl.root} // can refer to whole decl tree no
sweat...even recursively
;
So if decl calls decl eventually then you get another copy of the
declRoot pointer :) It refers to the most recent always. :)
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