help-bison
[Top][All Lists]
Advanced

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

Re: simple loop construct, advice needed


From: Laurence Finston
Subject: Re: simple loop construct, advice needed
Date: Fri, 13 Aug 2004 10:16:54 +0200 (MEST)

On Fri, 13 Aug 2004 address@hidden wrote:
>
> For performance reasons, I would like to add a very simple loop
> functionality to this existing flex/bison environment.

I haven't implemented loops in my parser yet, but the way I plan to do
it is to read the entire body of the loop into a string and replace the
loop header (e.g., `for i = 1 upto 5' or whatever) with a conditional.
When the parser reaches the end of the string it evaluates the
conditional.  If it's true, the scanner reads from the string again,
otherwise, it continues reading from the input stream it was reading
from before.

I use a `struct' for streams that includes a pointer to another `struct'
of the same type, thereby implementing a stack of `structs'.
When the scanner reads a loop construction, it (or the parser) creates a
new `struct' and pushes it onto the stack.
When the parser is finished with it, it just pops it off the stack.
I haven't decided yet how to divide the work between the scanner and the
parser.
I believe that this technique should also make it possible to have nested
loops without too much additional complication.

The `struct' contains a data member indicating what sort of stream it's
reading from, i.e., stdin, a file, or a string.  If necessary, I can
distinguish between strings used for different purposes, such as "loop
strings", "conditional strings", "macro strings", etc.

If the loop text is too long, I can dump it to a file and read it from
there.

Laurence




reply via email to

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