[antlr-interest] [newbie] Tree pattern matching

Robin diabeteman at gmail.com
Wed Mar 28 04:51:54 PDT 2012

Hello list,

I've read a lot from the mailing list http://antlr.markmail.org but I
couldn't find an answer. I guess it is because i'm too much a ANTLR n00b.

My task is simple:

   - recognize sub-tree patterns (mostly function, class, etc.
   declarations) in a Java AST
   - print on the console what is found (later i'd like to store this
   somewhere, but let's start small)

To generate the Java AST I'm using the this grammar from the website

Then, i took the JavaTreeParser (that comes with it)
http://www.antlr.org/grammar/1207932239307/Java1_5Grammars/JavaTreeParser.g and
removed most of the rules and added the option: filter = true;

Here is my test rig http://pastebin.com/66mrqJ64

The problem is that when I run this on a Java source file containing
classes and methods, i don't get any output.

$ java -jar target/apiwatch-0.1-SNAPSHOT-jar-with-dependencies.jar
    Lexer Start
      lexed in 1ms.
    Parser Start
      Parsed in 303ms.
    AST Walk Start

      AST Walked in 26ms.

Could someone point where i made a mistake? I already tried to move my
System.out.println calls around but nothing works...

Thanks in advance


More information about the antlr-interest mailing list