[antlr-interest] [v3] TreeParser capabilities

Kay Roepke kroepke at classdump.org
Mon Nov 20 02:10:37 PST 2006


On 20. Nov 2006, at 10:24 , Emond Papegaaij wrote:

>>
>> My first question: Is it possible to use a TreeParser with these  
>> nodes? It
>> seems the TreeParser is based on a NodeStream, which presents the  
>> tree
>> nodes to the TreeParser one by one. However only an implementation  
>> based on
>> CommonTree is provided. What is needed to use a TreeParser with my  
>> custom
>> TreeAdaptor? Do I need to write a TreeNodeStream based on a  
>> TreeAdaptor, or
>> is such a stream already available?
>
> 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?

>> 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.

> Can anybody help me with this?

HTH,
-k
-- 
Kay Röpke
http://classdump.org/






More information about the antlr-interest mailing list