[antlr-interest] What to override to prevent error recovery?

Robert Baruch autophile at zoominternet.net
Sat Nov 17 18:20:53 PST 2007


Hi all,

I have a grammar (v3) that looks like this:

grammar arguments;

format
	:	integerFormat EOF
	;
	
integerFormat
	:	'integer'
	|	'integer' 'in' '[' INT? ',' INT? ']'
	;
	
INT	:	'0'..'9'+ ;
WS	:	(' '|'\t')+ {skip();} ;


I am generating Java code.

If I have input "integergarbage", the parser will happily return after  
printing several lines like this:

line 1:7 no viable alternative at character 'g'

I figured out that I could override the Lexer's reportError method,  
set a "fail" boolean, and check that on return.

However, that does not solve the problem where input "integer in" also  
happily returns after printing:

BR.recoverFromMismatchedToken
line 0:-1 mismatched input '<EOF>' expecting '['


 From the source code of BaseRecognizer, this appears to be an error  
recovery technique to insert an "obvious" missing token or to delete a  
"spurious" extra token. I don't want my parser to do that. I want my  
parser to complain loudly and then keel over. I am not sure which  
method(s) I need to override in the Parser for that to happen. Any help?

Thanks,

--Rob

PS, where can I run a search on the mailing list archive?


More information about the antlr-interest mailing list