[antlr-interest] BUG: Constant (literal) token is incorrectly assumed to be present in AST rewrite

Austin Hastings Austin_Hastings at Yahoo.com
Wed Aug 13 18:06:49 PDT 2008


Howdy,

I have a C-like grammar with this entry:

conditional_expr
    : logical_or ( '?' expression ':' conditional_expr )?
       -> ^( '?' logical_or expression? conditional_expr?)
    ;

I am using antlr v3.1. In this case, the generated code assumes that the 
rewrite-rule's '?' token is the same as the possibly-nonexistent '?' in 
the matching rule, and tries to dereference the "stream" that would 
contain that token, if it were present.

In the case where no conditional expression is present, the rewrite 
should collapse into ^( '?' logical_or )

I suspect that there's a better way to handle this particular rewrite 
scenario. I'd like to hear it.

At the same time, this is pretty clearly a bug: antlr is confusing two 
tokens that look the same, but one of which doesn't exist.

=Austin



More information about the antlr-interest mailing list