Solved

BISON:How can I make a While-Loop?

Posted on 1998-12-02
6
1,850 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

627 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