[antlr-interest] Problem with rewrite rules with optional non-terminals

Andreas Meyer andreas.meyer at smartshift.de
Thu Mar 26 10:48:57 PDT 2009


David Jameson schrieb:
> I have the following grammar fragment
>
> refTag :
>                  LSQUARE a=expression (COMMA b=expression)? RSQUARE
>                     {
>                           //stuff
>
>                     } -> ^(REFTAG $a  $b)
>
>                  ;
>
>
> However, if I feed in source that does NOT have the optional comma  
> expression clause, the parser crashes because it blindly tries to  
> dereference  the stream_b object.
>
> How can I test whether there was an optional expression and control  
> the rewrite rule accordingly to include the $b or not?

Does ($b)? in the rewrite rule not work?

Andreas


More information about the antlr-interest mailing list