[antlr-interest] Possible Bug in Java Grammer

Trey Spiva Trey.Spiva at embarcadero.com
Thu Oct 3 11:28:22 PDT 2002


Can any one see a flaw in my reasoning?

The tryBlock looks like:

// an exception handler try/catch block
tryBlock
  : "try"^ compoundStatement
    (handler)*
    ( "finally"^ compoundStatement )?
  ;

// an exception handler
handler
  : "catch"^ LPAREN! parameterDeclaration RPAREN! compoundStatement
  ;

For the java code:

try
{
  ...
}
finally
{
}

The AST Tree will look like:

"finally"
  |
   - "try 

The Tree Grammar looks like:

tryBlock
  : #( "try" slist (handler)* (#("finally" slist))? )
  ;

handler
  : #( "catch" parameterDef slist )
  ;

The Tree Parser is expecting the tree

"try"
  |
   _ "finally"

So I changed the tryBlock rule to look like

// an exception handler try/catch block
tryBlock
  : "try"^ compoundStatement
    (handler)*
    ( finallyHandler )?
  ;

// an exception handler
handler
  : "catch"^ LPAREN! parameterDeclaration RPAREN! compoundStatement
  ;

finallyHandler
  : "finally"^ compoundStatement
  ;

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list