[antlr-interest] Ignoring nodes with the tree parser

Greg Smolyn smolyn at cs.ubc.ca
Tue Mar 12 11:42:11 PST 2002


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/ 



More information about the antlr-interest mailing list