[antlr-interest] anybody use exception[label]?

Terence Parr parrt at cs.usfca.edu
Fri Dec 23 09:09:39 PST 2005


On Dec 23, 2005, at 8:13 AM, Brannon King wrote:
> I've been using the exception catch in the parser like this:
>
> cornerType :
> 	LP! CORNERTYPE^ i:IDENTIFIER
> 		 { -1 != Arrays.binarySearch(cornerTypes,
> i.getText().toUpperCase()) }?
> 	RP!;
> 	exception catch[SemanticException ex]{
> 		throw new SemanticException("line " + i.getLine() + ":"
> + i.getColumn() + ":" + LT(1).getColumn() +
> 			": expecting one of [" +
> arrayToString(cornerTypes,", ") + "], found " + i.getText(),
> 		i.getFilename(), i.getLine(), i.getColumn());
> 	}
>
> What advantage would using the label give me? And how would that even
> change behavior?

With a label, the exception try/catch is put around just that  
construct no the whole rule. :)  You could then specify how a missing  
ID should be handled and then let the parser *continue* w/o jumping  
out of the rule.

Ter


More information about the antlr-interest mailing list