[antlr-interest] Tree walker simple quastion

ens06jpk ens06jpk at cs.umu.se
Thu Jul 12 04:49:33 PDT 2007


Hi,
I want count IF statement in my JavaAST 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;}
    ;
----
during compilation some errors appears. It says that found [package ...] 
where was searching 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