[antlr-interest] newbie question: throwing an exception from parsing behavior

Blake Meike bmeike at speakeasy.net
Sun Feb 24 17:31:14 PST 2008


I'm working with v3 and a grammar that handles numbers that are  
defined like numeric literals in Java:

0(0..7)+  |  (- |1..9)(0..9)+  |  0x(0..9|A..F|a..f)+

I find it simplified my grammar substantially, if I just accept a  
pretty general symbol, and validate it in the behavior associated with  
the rule, instead of trying to enforce the constraints in the grammar  
itself.

It all works fine, except that I can't figure our how to throw a  
useful exception, when the input is invalid.

I looked at the book, the various subclasses of RecognitionException  
and tried to follow things in the debugger.  It seems like something  
that would be common enough need, so that there ought to be a fairly  
simple way to do it...

Suggestions?

Thanks,
  -blake


More information about the antlr-interest mailing list