// Create a scanner that reads from the input stream passed to us
JavaLexer lexer = new JavaLexer(r);
lexer.setFilename(f);
// Create a parser that reads from the scanner
JavaRecognizer parser = new JavaRecognizer(lexer);
parser.setFilename(f);
// start parsing at the compilationUnit rule
parser.compilationUnit();
// do something with the tree
doTreeAction(f, parser.getAST(), parser.getTokenNames());
}
catch (Exception e) {
System.err.println("parser exception: "+e);
e.printStackTrace(); // so we can get stack trace
}