[antlr-interest] A throws clause on a grammar rule doesn't add a throws clause in the generated function

Ian Kaplan iank at bearcave.com
Tue Aug 12 19:50:57 PDT 2008


  Looking back in the Antlr-interest archives I see that a few people have
discovered what I did today: Adding a throws clause to a grammar rule
doesn't result in a throws clause being added to the generated function in
the parser.  Someone suggested throwing a RuntimeException, which is not
checked.  But a better alternative occurred to me (and probably has to
others).  A "throws RecognitionException" clause is always created for a
function generated by a grammar rule.  If you want to throw a special
exception, for example, a SemanticErrorException for a semantic problem
identified during parsing, you can simply extend RecognitionException:

    public class SemanticErrorException extends RecognitionException
   {
           public SemanticErrorException( final String message )
          {
                 super();
                 ....
           }

           @Override
            public String toString()...
   }

  I installed ANTLR 3.1 today in the hope that it would have a fix for this
problem.  However, that's not the case.  This seems to be a simple thing to
fix.  The "throws" clause is supported by ANTLR, but it has not done
anything for some time.  I don't understand why this hasn't been fixed.  Or,
if it's not going to be fixed, why the "throws" is not just removed from the
ANTLR grammar grammar.

  Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080812/459cd691/attachment.html 


More information about the antlr-interest mailing list