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

mzukowski at yci.com mzukowski at yci.com
Tue May 13 12:17:43 PDT 2003


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 virgin.net]
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