[antlr-interest] Parser Exception-Handlers with Labels

Carleton Coffrin carleton.coffrin at gmail.com
Wed Jun 14 09:37:42 PDT 2006


I am using the Java ANTLR compiler 2.7.5 and am having some difficulty
using labeled Exception-Handlers.  When I use a label to refer to a
grammar rule the code for that exception is not generated.  For
example,

identifier returns [ASTIdentifier n = null] : x:ID { n = new
ASTIdentifier(tok(x)); }
	;	
	exception catch [RecognitionException ex] {reportError(ex,
"identifier message");}
	exception[x] catch [TokenStreamException ex] {reportError(ex, "ID
token Mmssage");}  //This works great!
	

autoDef {ASTIdentifier n;}
	: auto:"auto" n=identifier
	;
    exception catch [RecognitionException ex] {reportError(ex,
"autoDef message");}
    exception[n] catch [This does] {not(get,"identifier rule
message");}  //<-------------- This never makes it to the generated
code


I have struggled to find any documentation on useing labeled
Exception-Handlers, this is my last resort.  If this is not best venue
for this inquery I am pleased to redirect it.

-Carleton


More information about the antlr-interest mailing list