[antlr-interest] Tree walker simple quastion

ens06jpk ens06jpk at cs.umu.se
Fri Jul 13 01:49:07 PDT 2007


I'm not sure if this(more or less) post was already sent because I had 
some mail-software problems:(. However, if anyone can help me I will be 
totally grateful.
Hi,
I want count IF statement in my Java AST build from source.java file. 
How can I implement conditions for nodes in tree walkers?
I use a java.g grammar from ANTLR example files for creating an AST and 
java.tree.g from tree walking. However when I try to add my own function:
----
somecalc returns [int cnt]
{
   cnt=0;
}
   :    #("if" expression stat (stat)? ) {cnt = cnt+1;}
   ;
----
When I run antlr on "source.java" file  some errors appears. It says 
that found [package ...] where was expecting for IF node. Does anyone 
know how to check all nodes in AST and count for instance IF statements ?
Thanks for any help

janusz


More information about the antlr-interest mailing list