[antlr-interest] Declaring exceptions in rules

Christof Lutteroth lutteroth at cs.auckland.ac.nz
Mon Apr 20 22:08:07 PDT 2009


Hi!

I am trying to get ANTRL 3.1.3 to generate a method that declares an exception.
For example, I want rule compilationUnit (from the Java grammar in the grammars 
section of the ANTLR website) to throw an Exception:

compilationUnit  throws Exception
     :   (   (annotations)?
             packageDecl=packageDeclaration
         )?
         (importDeclaration)*
         (typeDeclaration)*
     ;

So now I would expect that the compilationUnit() method that is generated would 
declare "throws Exception", but:

     public final void compilationUnit() throws RecognitionException {

Why is the Exception declaration not generated?
Thanks you for any help.

Cheers,
Christof


More information about the antlr-interest mailing list