help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

simple loop construct, advice needed


From: hacienda
Subject: simple loop construct, advice needed
Date: Fri, 13 Aug 2004 09:54:10 +0200 (MEST)

Hello, 


I am new to the flex/bison -- lex/yacc world.

In order to create certain files at run-time, we are using a very simple
"programming language" that is described by a set of
flex rules and a bison grammar. 
This "language" then is evaluated and determines the structure of the files
to be created.

This "language" accepts only a very limited set of commands, e.g. DEFINE and
CALL commands and an IF-ELSE-structure.

In many cases, some commands are repeated (with absolutely no changes) a
number of times.

For performance reasons, I would like to add a very simple loop
functionality to this existing flex/bison environment.

For example:

FOR 10
  command1
  command2
  command3
ENDFOR


My approach would be something like this:
First, the new expressions have to be introduced in the flex file so that
they are accepted by the language flex generates.
E.g.
FOR      { strcat(strng, "FOR");
           return(forcall);
         };
     
ENDFOR   { strcat(strng, "ENDFOR");
           return(endforcall);
         };
        
(the same way it's done with all the other commands) 

         
Then, in the bison file, I would add the new tokens "forcall" and
"endforcall":

...
%token forcall endforcall othertokensgohere
...
%%
Start   :
allkindsofrules {...} | 
ENDFORCLL   :    endforcall
;

FORCLL      :    forcall
' ' VALUE
{ logic goes here }


Sorry for going into detail that much, but I have absolutely no idea on how
to implement this.

I already looked at the existing structures (the IF-contruct e.g.) and found
it quite complex.
Searching the web didn't return any useful links either.


Maybe someone here can give me some hints.      


Thanks in advance!

-- 
NEU: WLAN-Router für 0,- EUR* - auch für DSL-Wechsler!
GMX DSL = supergünstig & kabellos http://www.gmx.net/de/go/dsl





reply via email to

[Prev in Thread] Current Thread [Next in Thread]