[antlr-interest] Trying to implement a while loop using embedded actions in ANTLR
Kevina Choolhun
kevina.choolhun at gmail.com
Wed Jun 4 00:01:08 PDT 2008
Thanks Adam ;)
I tried that just in case it could work.. I did not expect it to compile but
it did...
I hope to find a solution soon and should i be able to crack it up.. i will
post it here...
But any help is still welcomed. :)
Kevina
On Tue, Jun 3, 2008 at 1:58 PM, Adam Connelly <
adam.rpconnelly at googlemail.com> wrote:
> 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/20080604/0c1fd2f3/attachment.html
More information about the antlr-interest
mailing list