[antlr-interest] Re: TreeParser efficiency: Can TreeParsers ignor e arbitary subtrees?

lgcraymer lgc at mail1.jpl.nasa.gov
Tue May 13 17:56:20 PDT 2003


Monty--

This is true in the current implementation, but is probably not a good 
thing since there is no way to check if skipping the subtree is 
intentional or not.  The "not" case would be a bug in the developer's 
tree walker grammar which cannot be tested for except by inserting 
action code.  We should probably add a couple of options to ANTLR 
3--one at the grammar level to turn on/off checking for subtrees 
(there is a time penalty for checking) and one at the rule level to 
override the "checking" option.  ANTLR should not support untestable 
grammar "features"!

--Loring


--- In antlr-interest at yahoogroups.com, mzukowski at y... wrote:
> Folks, here's another example of ignoring a subtree:
> 
> You can do this by just not specifying rules to follow.  For 
instance if
> declarations are something like this one from the gcc grammar:
> 
> declaration
>         :       #( NDeclaration
>                     declSpecifiers
>                     (                   
>                         initDeclList
>                     )?
> 		    ( SEMI )+
>                 )
>         ;
> 
> You can prevent traversal of that subtree by writing this instead:
> 
> declaration
>         :       NDeclaration
>         ;
> 
> You can also use the wildcard "." to match any node but not go down 
into the
> subtree.
> 
> A tree parser will only match what you ask it to.  Since trees are 
two
> dimensional--nextSibling() and firstChild()--or down v. right--you 
can
> easily skip subtrees by just choosing not to match them.  You could 
also
> ignore siblings if you want, that's just another way of only 
matching what
> you've asked for, but doing that is much less useful because if you 
do it at
> the top level then you've ended your parse.
> 
> Monty
> 
> -----Original Message-----
> From: micheal_jor [mailto:open.zone at v...]
> Sent: Tuesday, May 13, 2003 5:11 AM
> To: antlr-interest at yahoogroups.com
> Subject: [antlr-interest] TreeParser efficiency: Can TreeParsers 
ignore
> arbitary subtrees?
> 
> 
> Hi,
> 
> I just wondered if it is possible to generate TreeParsers that 
ignore 
> (i.e. do not "visit") the nodes in arbitary subtrees. 
> 
> I have an AST in which only a few nodes have attributes I am 
> interested in processing with a TreeParser. Because every TreeParser 
> grammar describes the whole tree(?), all nodes are still visited 
even 
> if no action code exists to be executed.
> 
> Is it possible to effectively say in the TreeParser grammar "I won't 
> be doing anything in this node/subtree so don't even generate code 
to 
> visit it?
> 
> Cheers,
> 
> Micheal
> 
> 
> 
>  
> 
> Your use of Yahoo! Groups is subject to 
http://docs.yahoo.com/info/terms/


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list