[antlr-interest] Again wildcards in tree grammars

Oliver Zeigermann oliver.zeigermann at gmail.com
Sat Dec 13 03:18:56 PST 2008


This rule in a tree grammar

child : childNode=. {System.out.println("Child="+$childNode.text);} ;

is accepted by the ANTLR tool without problems, but the generated code
is broken, as there is a catch block for an exception
(RecognitionException) that is never thrown:

    public final SQLEmitter.child_return child() throws RecognitionException {
        SQLEmitter.child_return retval = new SQLEmitter.child_return();
        retval.start = input.LT(1);

        CommonTree childNode=null;

        try {
            // T:\\FlexOCL\\workspace\\OCL\\SQLEmitter.g:17:7: (childNode= . )
            // T:\\FlexOCL\\workspace\\OCL\\SQLEmitter.g:17:9: childNode= .
            {
            childNode=(CommonTree)input.LT(1);
            matchAny(input);
            System.out.println("Child="+(childNode!=null?childNode.getText():null));

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }


Error: Unreachable catch block for RecognitionException. This
exception is never thrown from the try statement body.

This seems to be a problem in the Java emitter templates, right?

Oliver


More information about the antlr-interest mailing list