[antlr-interest] unreachable catch block

Warren Falk warren-antlr.org at warrenfalk.com
Thu May 14 14:21:21 PDT 2009


This has been asked on here before, but the answers no longer appear
to be correct using the latest version (3.1.3).

The output of the  following combined grammar, TestParser.java, fails
to compile with "Unreachable catch block" in the token rule (despite
the empty @rulecatch which doesn't appear to have an effect).  What am
I missing?  (The reason it's unreachable is because the '.' can't fail
-- this is just an abbreviated grammar for illustration only).

// -----------------------------
grammar Test;

options {
    language = Java;
    output = AST;
}

document
  : token+
  ;

token
  @rulecatch { }
  : .
  ;

WS : WSCHAR+ ;

WORD : NONWSCHAR+ ;

fragment
NONWSCHAR : ~WSCHAR ;

fragment
WSCHAR    : (' '|'\n'|'\r'|'\t') ;
// -----------------------------

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

Thanks in advance.

P.S. this is my first time posting here and I'm a bit new to ANTLR, so
I apologize in advance if this is a stupid request.


More information about the antlr-interest mailing list