Solved

BISON:How can I make a While-Loop?

Posted on 1998-12-02
6
1,628 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
centeredAverage challenge 8 121
sum28 challenge 31 95
Window placement 17 64
Path of Workbook 3 45
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now