[antlr-interest] Ignoring nodes with the tree parser

mzukowski at bco.com mzukowski at bco.com
Tue Mar 12 13:02:16 PST 2002


You can use the wildcard operator to match but not descend a subtree.

#(NAspectDeclaration (declarator)=> .
                      (  (adviceDecl)=>.
                        | (pointcutDecl)=>.
                        | functionDef )*
   )

Technically you wouldn't need the syntactic predicates if you were convinced
that you were building your trees correctly.  This should work:

#(NAspectDeclaration  . /*that dot matches declarator*/
                      (  (functionDef)=>functionDef
                        | .
			    )*
   )

Monty

> -----Original Message-----
> From: Greg Smolyn [mailto:smolyn at cs.ubc.ca]
> Sent: Tuesday, March 12, 2002 11:42 AM
> To: antlr-interest at yahoogroups.com
> Subject: [antlr-interest] Ignoring nodes with the tree parser
> 
> 
> Okay, I'm working with a modified version of the C grammar that came 
> with ANTLR.
> 
> Anyways, in my AST there are nodes I would like to ignore during the 
> emitting phase.  In the code generation phase all code is 
> output as side 
> effects (ie. print(token)).  Now, is there a way I can ignore 
> an element 
> in a tree node?
> 
> ie.
> I have an augmented C ast that contains the following
> 
> aspect foo {
> 
> before(): call(int bar()) {
>    helperFunction();
> }
> 
> void helperFunction() {}
> 
> }
> 
> (as well, we add new function decls inside this AST element 
> during our 
> processing phase).
> 
> 
> Anyways, I have a node that looks like:
> 
> #(NAspectDeclaration declarator
>                       (  (adviceDecl)=>adviceDecl
>                         | pointcutDecl
>                         | functionDef )*
>    )
> 
> Now, I want to ignore "declarator", "adviceDecl" and "pointcutDecl".
> Is there any way to do this easily?
> I first started by doing a
> (declarator)=>ignoreDeclarator, and creating a special node to ignore 
> the declarator (ie. the node from the TreeGrammar without the 
> actions).
> 
> However, I can't do that for adviceDecl and pointcutDecl, 
> because they 
> use elements from the C grammar and it would require a LOT of work 
> converting every single instance to ignoreFooToken, ignoreBarToken, 
> yadda yadda.
> 
> Any suggestions?  What would be really wicked would be some 
> sort of "!" 
> so I could say "!declarator" and it would know of it's 
> existance but not 
> process any actions on it.
> 
> - greg
> 
> 
> 
> 
>  
> 
> 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