loops in bison

Aaron Jewell <jewell@willowglen.ab.ca>
4 Aug 2000 16:04:06 -0400

          From comp.compilers

Related articles
loops in bison jewell@willowglen.ab.ca (Aaron Jewell) (2000-08-04)
Re: loops in bison cfc@world.std.com (Chris F Clark) (2000-08-05)
Re: loops in bison jewell@willowglen.ab.ca (Aaron Jewell) (2000-08-10)
Re: loops in bison cfc@world.std.com (Chris F Clark) (2000-08-13)
| List of all articles for this month |
From: Aaron Jewell <jewell@willowglen.ab.ca>
Newsgroups: comp.compilers
Date: 4 Aug 2000 16:04:06 -0400
Organization: Willowglen Systems Inc
Keywords: interpreter

Hi,


I am developing a small interpreted script language at work for generic
communication protocol simulations. I have been developing the language
with flex/bison. My problem is that I need to implement "looping" kind
of as follows:


..
..
..


statement_list
: statement
| statement_list ';' statement
;


statement
: ...
| ...
| loop_statement
;


loop_statement
: LOOP '(' expression ')' statement_list END_LOOP
;


..
..
..


Does anybody have insight on how I might go about doing this?
Specifically, I need to ensure that the statement_list in the last
rule is executed a number of times indicated by the expression
value. The mere act of reducing this rule will execute it once.


One idea I had is to redirect yylex()'s input from a string and then
feed the parser a series of strings read line by line from the script
file. That way I could buffer those strings corresponding to the
statement_list within the loop and run them through the lexer again
'n' times. However, I'm not sure if this will work - for example, if
the END_LOOP token falls on the same line as the last statement in the
statement_list. It may also be alot of work and unfortunately a have
limited time to implement this.


Any help would be greatly appreciated.


-Aaron
[Once again, my advice is "don't do that". Unless you have a really
compelling reason that you have to invent yet another incompatible
scripting language, use tcl or rexx. That's what they're for. Tcl
is written in portable C, is fast, reliable, and free. -John]





Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.