Solved

BISON:How can I make a While-Loop?

Posted on 1998-12-02
6
1,722 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Shell script to login to remote m/c and execute commands 10 78
haveThree challenge 22 121
fix34  challenge 9 139
firstChar challenge 13 119
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…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

808 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