[antlr-interest] BUG: Constant (literal) token is incorrectly assumed to be present in AST rewrite
Raphael Reitzig
r_reitzi at cs.uni-kl.de
Thu Aug 14 03:58:25 PDT 2008
Hi Austin!
Thou shalt not use string literals in parser rules! 't'll lead thee to
chaos and madness!
Introduce Tokens for that. The other guys told you how (lexer token
for the rule '?', imaginary token for the tree one)
Reagards
Raphael
"Austin Hastings" <Austin_Hastings at Yahoo.com> wrote (Thu Aug 14
03:06:49 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
>
>
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: PGP Digital Signature
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20080814/7acfffbb/attachment.bin
More information about the antlr-interest
mailing list