Solved

BISON:How can I make a While-Loop?

Posted on 1998-12-02
6
1,706 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how do i create updater to My Activex application? 3 88
sameEnds challenge 3 159
countEvens challenge 2 100
scoreUp challenge 14 62
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

770 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