[antlr-interest] Working with tree walkers in V3
Terence Parr
parrt at cs.usfca.edu
Tue Mar 13 13:49:36 PDT 2007
On Feb 21, 2007, at 3:31 AM, Mark Bednarczyk wrote:
> I'm having difficulty accessing values from my tree walker. The
> tree is
> built and has hierachy of nodes in it. The walker properly matches
> on the
> various rules and that's where my problems start. I can't seem to
> get the
> grasp on all the special $ prefixed attributes. Everything throws
> NULL ptrs
> exceptions when I access them.
>
> It would be nice if there was a way to tell the rule to return
> whatever
> value it matched such as:
>
> modifier returns [String ret]
> @finally {
> $ret = $text; // Will throw NULL Ptr exception
> }
> : 'public'
> | 'protected'
> | 'private'
> | 'static'
> | 'final'
> | 'synchronized'
> | 'transient'
> | 'volatile'
> | 'field'
> ;
>
> Again, this is all in "tree grammar".
Hmm..that seems ok. Generates:
retval.ret = input.getTokenStream().toString(
input.getTreeAdaptor().getTokenStartIndex(retval.start),
input.getTreeAdaptor().getTokenStopIndex
(retval.start)); // Will throw NULL Ptr exception
which should work. Note it's @after now in 3.0b7 :)
Ter
More information about the antlr-interest
mailing list