[antlr-interest] bug or strange behaviour in rewrite operator ?

Alessandro alessnet at gmail.com
Thu Jun 14 04:07:09 PDT 2007


Hello,

I have also another problem with this rule : ( I replaced
"stream_prog" with "stream_retval" because of the bug quoted above)

prog:
       ((func  | (decvar SEMI)) -> $prog? func? decvar? )*
       -> ^(PROG_DEC $prog?);

This rule always catch the first result of "func" and "decvar" because
the generated code includes stream_func.reset() and
stream_decvar.reset().

So if you have "decvar(1) decvar(2) func" at the input, your output
will be "decvar(1) decvar(1) func decvar(1)"

If you change de rule with this (equivalent ?!) rule  :

prog:
       ((func -> $prog? func | (decvar SEMI) -> $prog? decvar))*
       -> ^(PROG_DEC $prog?);

there is neither stream_decvar.reset(), nor stream_func.reset() in the
generated code.
So the output is correct.

is this normal ?

Thanks


On 6/9/07, Terence Parr <parrt at cs.usfca.edu> wrote:
> ooops. looks like a bug. added
>
> http://www.antlr.org:8888/browse/ANTLR-135
>
> Ter
> On Jun 9, 2007, at 6:07 AM, Alessandro wrote:
>
> > Hello,
> >
> > When I use $rule? the code generated seems to be not correct.
> > Here is a example :
> >
> > prog:
> >       (func | (decvar SEMI) -> $prog? func? decvar? )*
> >       -> ^(PROG_DEC $prog)
> > ;
> >
> > The code generated for ($prog)? is :
> >
> > // ( $prog)?
> > if ( stream_prog.hasNext() ) {
> >   adaptor.addChild(root_0, stream_retval.next());
> > }
> > stream_prog.reset();
> >
> > the variable stream_prog does not exist, the correct variable is
> > "stream_retval".
> > Is it a bug ?
> >
> > Thanks,
> >
> > Alessandro
>
>


More information about the antlr-interest mailing list