[antlr-interest] Skipping or ignoring whole subtrees in a tree grammar

Hardy, Stephen Stephen_Hardy at rabbit.com
Mon Aug 13 08:50:58 PDT 2007


Frank,

thanks for the response!  It seems that '.' is a bit more magic than I
thought.  That is, the semantics seem to be that '.' matches the token
plus any subtree that it may have, not just the 'root' token itself
(although I stand open to correction on this interpretation).

Regards,
SJH


> -----Original Message-----
> From: Frank Smith [mailto:fasmith718 at gmail.com] 
> Sent: Monday, August 13, 2007 8:44 AM
> To: Hardy, Stephen
> Cc: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Skipping or ignoring whole 
> subtrees in a tree grammar
> 
> my mistake: you can access bar by doing foo.start.getChild(0);
> 
> Sorry for the mixup
> 
> --Frank
> 
> 
> On 8/13/07, Frank Smith <fasmith718 at gmail.com> wrote:
> 
> 	Use the wild card.  That causes a tree grammar to skip 
> a token e.g.:
> 	
> 	...
> 	| ^(DELETED_FOO .)
> 	...
> 	
> 	you can still access bar if you want by using 
> DELETED_FOO.start.getChild(0); if you want to use it in an 
> action somehow, but not be stepped through automatically by 
> the walker.  I used this a lot- works great. 
> 	
> 	Best regards,
> 	     Frank
> 	
> 	
> 	
> 	On 8/13/07, Hardy, Stephen < Stephen_Hardy at rabbit.com 
> <mailto:Stephen_Hardy at rabbit.com> > wrote: 
> 
> 		Hi all,
> 		
> 		supposing I have a tree grammar which includes 
> something like
> 		
> 		foo
> 		   : ^(FOO          bar  { some action... } ) 
> 		   | ^(DELETED_FOO  bar)
> 		   ;
> 		
> 		Suppose bar is a complex, deeply recursive, 
> subtree; and I wish to avoid
> 		as much as possible the overhead of parsing it 
> in the DELETED_FOO case.
> 		(Imagine that DELETED_FOO was once a FOO, but 
> the parser or application 
> 		decided after the fact that it was an 
> irrelevant part of the input, and
> 		changed the token to mark it as deleted, but 
> without actually removing
> 		the subtree.  Why not delete the tree?  Well, a 
> different tree grammar 
> 		may still want to see the contents, just not this one.)
> 		
> 		Is there a way of telling ANTLR to basically 
> 'skip' any analysis of the
> 		subtree under DELETED_FOO?  For example, a 
> routine which simply consumes 
> 		tokens from the DOWN which immediately follows 
> DELETED_FOO until the
> 		matching (balanced) UP token is seen?
> 		
> 		I seem to recall a mention of something like 
> this in TDAR, but darned if
> 		I can locate it.
> 		
> 		Regards,
> 		SJH
> 		
> 		
> 
> 
> 
> 


More information about the antlr-interest mailing list