[antlr-interest] Redirect error message to a file
Laura Adam
ladam at vbi.vt.edu
Fri Jul 25 07:37:15 PDT 2008
Hello,
I'd like to thank people that helped me previously. It has been very useful.
I am now using anltr-3.1b2, and taking informations mostly from the book because else it can be anltr v2 tutorials talking about things such as defaultErrorHandler...
I am working on redirecting the error message to a file.
I wrote (see bellow) in my file.g file the functions I want to redefine.
File.g and file.java compile but it seems that file.java is still using the default functions (error messages are printed on the shell).
It seems (by compiling) existing functions cannot have a different return type or throw any exception if before it does not, that's why my code is quite strange.
I also tried with the given examples in the book, the same happen. I may forget to do something...
What should I change?
Laura Adam
**************************************************************************
grammar G;
options{...}
@member{
private String Errormsg="";
public void emitErrorMessage(String msg) {
Errormsg= msg;
}
public void displayRecognitionError(String[] tokenNames, RecognitionException e){
String hdr = getErrorHeader(e);
String msg = getErrorMessage(e, tokenNames);
emitErrorMessage(hdr+" "+msg);
repportErrormsg();
}
public void repportErrormsg(){
try{
PrintWriter file = new PrintWriter("Error.txt");
file.println(Errormsg);
file.close();}
catch(Exception e){System.out.println("problem while writing in the Error.txt file");}
}
}
rules....
More information about the antlr-interest
mailing list