[antlr-interest] Performance question.

Alex Shneyderman a.shneyderman at gmail.com
Wed Feb 14 23:46:00 PST 2007


I need to  parse java files to augment them with some code. So, I went
to antlr's site downlaoded the availble java grammar and generted
myself a parser.

Now, I run the parser on one of the projects - it has approximately
1000 java files. To parse each file I use the following code:

try {
  Java15Lexer lexer = new Java15Lexer(new FileInputStream(file));
  Java15Parser parser = new Java15Parser(lexer);
  parser.compilationUnit();
} catch (Throwable t) {
  System.out.println ("Can't parse: " + file.getAbsolutePath() + "; "
+ t.getMessage());
}

Parsing of this many files takes about 41 sec.

Then I came across ecj (eclipse compiler that is distributed
separately now) that has parser as part of it. So I run the parser
only part on the same source set and the turn-around there is about 3
sec. I am not sure of the quality of the AST it generated but I can
definitely navigate typpe declarations, fields, methods and statements
within the methods.

I am wondering whether I am doing anything wrong while runing ANTLR
(2.6.7 version).
Any suggestions to improve performance?

-- 
Thanks,
Alex.


More information about the antlr-interest mailing list