[antlr-interest] Unexpected token; parsing java files

dharbari2 vijay at mindspring.com
Wed Sep 17 22:51:27 PDT 2003


This question might be elementary but... I'm trying to use antlr to 
check the syntax correctness of Java files.
I have the following code:

try {       
    FileReader rdr = new FileReader(myFile);
    JavaLexer lexer = new JavaLexer(rdr);
    JavaRecognizer parser = new JavaRecognizer(lexer);
    parser.compilationUnit();
}
catch(Exception e) {
    e.printStackTrace();
}

Works fine except when there are syntax errors like - "Unexpected 
token" or "expecting RCURLY, found '/'" in which cases no exception 
is thrown. How do I catch these? I'm looking for a very simple 
solution. I just need to know if the file has syntax errors or not. I 
don't care what the error is.
Thanks

Vijay


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list