[antlr-interest] Possible Bug in Java Grammer

mzukowski at yci.com mzukowski at yci.com
Thu Oct 3 12:22:03 PDT 2002


That's the right way to do it.  You have to split the "finally"^ into its
own rule just like you did.

Monty

> -----Original Message-----
> From: Trey Spiva [mailto:Trey.Spiva at embarcadero.com]
> Sent: Thursday, October 03, 2002 11:28 AM
> To: 'antlr-interest at yahoogroups.com'
> Subject: [antlr-interest] Possible Bug in Java Grammer
> 
> 
> 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/ 


 

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



More information about the antlr-interest mailing list