[antlr-interest] [v3] TreeParser capabilities

Emond Papegaaij e.papegaaij at student.utwente.nl
Mon Nov 20 02:57:59 PST 2006


On Monday 20 November 2006 11:10, Kay Roepke wrote:
> On 20. Nov 2006, at 10:24 , Emond Papegaaij wrote:
<cut TreeParser over custom AST nodes with TreeAdaptor>
> >
> > It seems like there is currently no such stream. Is there a reason why
> > CommonTreeNodeStream is written based on the Tree interface,
> > instead of using a TreeAdaptor?
>
> You'd need to implement a custom node stream class in this case. It
> might be a problem if you do not implement Tree at all, I thought it was
> used in some cast or something, but it could be that I'm wrong about this.
> Is there a specific reason that you can't implement Tree?

I'm using a heterogeneous AST, which is generated by an external tool. This 
tree is strictly typed, with fields containing the various subtrees. This 
makes the Tree interface difficult to implement. All functionality required 
for the Tree interface is already part of the custom TreeAdaptor (such as 
getChildCount() and getChild(int)). Therefore, I'm wondering why the 
CommonTreeNodeStream is based on the Tree interface, and not on a 
TreeAdaptor. Especially because CommonTreeNodeStream can take a TreeAdaptor 
in its constructor, but it's not used.

> >> My second question: Is it possible to skip sub-trees, or visit the
> >> same
> >> branch more than once (for example in an interpreter of a for
> >> statement)? I
> >> suspect that the NodeStream will get out-of-sync when you try to
> >> do so.
> >
> > So far, I've not been able to skip children. A simple wildcard '.'
> > seems to
> > match only a single node in the stream, and '^(.)' gives a syntax
> > error.
>
> ANTLR cannot skip subtrees currently :( It's a pain, but it's not
> there yet, sorry.

Is this a planned feature?

Best regards,
Emond


More information about the antlr-interest mailing list