[antlr-interest] Unexpected token; parsing java files

mzukowski at yci.com mzukowski at yci.com
Thu Sep 18 07:59:12 PDT 2003


You just have to set the option defaultErrorHandler=false in java.g and the
exceptions will be thrown all the way up to you.

Monty6

-----Original Message-----
From: dharbari2 [mailto:vijay at mindspring.com] 
Sent: Wednesday, September 17, 2003 10:51 PM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Unexpected token; parsing java files



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/ 


 

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




More information about the antlr-interest mailing list