Solved

BISON:How can I make a While-Loop?

Posted on 1998-12-02
6
1,760 Views
Last Modified: 2013-12-26
Hello experts
I want to implement a While loop in Flex/Bison, but I don't
know how I can step back in my input string.
e.g.
while I < 10 do
c = c + b;
I = I + 1;
endwhile

It is not a problem to run the example above once.
When I get the token endwhile I want to go back to the While-Statement to check the condition. I don't know, how I can get the While-Statement again.

Thanks for your help.
0
Comment
Question by:micha71
  • 3
  • 3
6 Comments
 
LVL 3

Accepted Solution

by:
elfie earned 200 total points
ID: 1294535
if you put in a separete rule let's say while_rule,
then define a another rule

while_rules:
                         while_rule ¦
             while_rules while_rule;

this should do it

0
 

Author Comment

by:micha71
ID: 1294536
In my opinion this makes it possible to interlock the while loops like
while statement do
   while statement do
     ..
     ..
   endwhile;
endwhile

clarification of my problem
-presently the while statement runs but as a normal if-then-endif statement
-because the condition in the while-do line will be evaluated one time only and
 the statements in the loop will be executed or not depending on the conditions
 (I set a flag when the condition is false and the statements will not executed.)
-the endwhile token will be identified by the flex/bison
-when the endwhile token is identified, a jump to the "while statement do" line is required   to evaluate the while-condition again
-this jump (a step back in the input-string) is my problem (the rules action not the rule I   think)

Do you mean your answer solved my problem?

Thanks for your help.
0
 
LVL 3

Expert Comment

by:elfie
ID: 1294537
If  proposed structure itself doesn't allow the indented while loop.

probably you have something like

while_rule: 'while' condition statements end_while.

and inside your statements you will have a reference towards while_rule.

The only solution here is make a statements_no_while rule, which is a copy of the statements rule, but leave the while aout of it.

So you will have

statements: stat1_rule¦ stat2_rule¦while_rules¦stat3_rules¦ ...
stat_no_while: stat1_rule¦ stat2_rule¦stat3_rules¦ ...

while_rules: while_rule ¦ while_rules while_rule;

while_rule: 'while' condition stat_no_while end_while
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:micha71
ID: 1294538
Ok I will test it.
Do you know a book or a web page with good examples? (apart lex & yacc , O'REILLY)
Is the last question really.
0
 
LVL 3

Expert Comment

by:elfie
ID: 1294539
0
 

Author Comment

by:micha71
ID: 1294540
Lot thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Expand data scrubbing tool 13 36
firstChar challenge 13 132
Increment column based of a FK 8 48
c++  placing data into a form and an editbox 5 21
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question