[antlr-interest] Trying to implement a while loop using embedded actions in ANTLR

Adam Connelly adam.rpconnelly at googlemail.com
Tue Jun 3 02:58:45 PDT 2008


Not 100% on this, but it looks like you have a typo.

'while' c1 = cond
            {$c1.value == true}?=>
            {while !($c1.value==true)
            {

            evaluate=true;}
                stat+
             }
             'endwhile'

Should be

'while' c1 = cond
            {$c1.value == true}?=>
            {while !($c1.value==true)
            {

            evaluate=true;}
             }
             stat+
             'endwhile'

Looks like the stat+ is inside the action.  I think I know what you're
trying to say, but I doubt it will work like that.  I'm actually surprised
it compiles, but then I'm not an ANTLR expert.  Sorry I can't think of a
solution at the moment.

Adam

2008/6/3 Kevina Choolhun <kevina.choolhun at gmail.com>:

>
>
> Hello everybody,
>
> I am new at antlr and have been trying my hand at embedding actions to try
> make a while_loop work...
>
> Here is part of my code.
>
> whileStatement
> @init{ evaluate = false;}
> @after{evaluate=true;}
>
> :
>         'while' c1 = cond
>             {$c1.value == true}?=>
>             {while !($c1.value==true)
>             {
>
>             evaluate=true;}
>                 stat+
>              }
>              'endwhile'
>
>
>  It works fine apart from the
> ("major") fact that it does not iterate, i.e. It enters the loop if
> condition is true, process the actions inside the loop and exits, even if
> condition is still true...
>
> I have run out of ideas.. well, i am new at antlr and may be missing an
> important point somewhere.
>
> Can someone please counsel?
>
> Thank you for your help.
>
> Kevina
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080603/b7f3127d/attachment-0001.html 


More information about the antlr-interest mailing list