🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.unix.programmer
2 messages
2 total messages Started by Steve Franklin Wed, 18 Feb 1998 00:00
Can Flex Parse Multiple _Strings_?
#3824
Author: Steve Franklin
Date: Wed, 18 Feb 1998 00:00
49 lines
2936 bytes

(Apologies for the widespread distribution of this message - I could not
find a suitable forum for flex/lex discussions, and dejanews pointed to
multiple newsgroups for intelligent discussions).

I am currently working on a parser that uses both flex and bison to parse
text which is contained within a string. Everything works great, but I
actually call yyparse from main(), and would like to loop through multiple
strings, tokenizing and parsing each string separately.

At present, I have a main routine that does some stuff with text retrieved
from the file system, then places it in a buffer that is globally accessible
- my rewritten YY_INPUT accesses this buffer and works from it instead of
*yyin (as described in Levine et al's ORA book). 

This works great, but if I call yyparse() from within a loop, and for each
iteration of the loop I repoint my globalbuffer pointer to a new string so
that it is visible from YY_INPUT, YY_INPUT is still pointing at the original
chunk of memory, and doesn't want to think about the new strings.

I have looked into the capabilities of yywrap, but all examples that I have
found seem to be suitable for input _files_ that throw <<EOF>> tokens at the
end. I, of course, don't have this - I get a \0 at the end of my string that
indicates an EOS (end of string). In fact, when I get to the end of a
string, yywrap doesn't get called.

Is there no way for me to easily have:

main() {
  ...
  for(i=0; i<5; i++) { // for 5 strings...
    // create new string and do stuff with it
    // point to new string
    yyparse(); // Run yyparse() nice and clean as if nothing has been run
    report_results();    
  }
}

I've been bashing my head against the wall with this one for quite some time
- any answers would be a greatly appreciated. Really, if I could just figure
out how to "clean up" between calls to yyparse() so that I was always
starting at square one, that would be ideal. I suspect that's what yywrap()
simulates with multiple files, but I can't benefit from those examples.

   Thanks in advance,

Steve Franklin
franklin@ug.c.sdal.ca
Re: Can Flex Parse Multiple _Strings_?
#3823
Author: Kaz Kylheku
Date: Wed, 18 Feb 1998 00:00
13 lines
1348 bytes
In article <6cdnb6$87k$1@News.Dal.Ca>,
Steve Franklin <franklin@ug.cs.dal.ca> wrote:
>
>(Apologies for the widespread distribution of this message - I could not
>find a suitable forum for flex/lex discussions, and dejanews pointed to
>multiple newsgroups for intelligent discussions).

You should have considered comp.compilers, since lexical analyzer generators
are compiler construction tools. Some GNU tool newsgroup would also have
been better for question specific to the capabilities of flex.

Shame on you!
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads