🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #3824

Can Flex Parse Multiple _Strings_?

#3824
From: 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
Technical Details
Message-ID: <6cdnb6$87k$1@News.Dal.Ca>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10c696,b4ff2d156f848b35,start
X-Google-Attributes: gid10c696,public
X-Google-Thread: 1025b4,b4ff2d156f848b35,start
X-Google-Attributes: gid1025b4,public
X-Google-Thread: fc89c,b4ff2d156f848b35,start
X-Google-Attributes: gidfc89c,public
X-Google-Thread: 1103af,b4ff2d156f848b35,start
X-Google-Attributes: gid1103af,public
X-Google-Thread: 1014db,b4ff2d156f848b35,start
X-Google-Attributes: gid1014db,public
From: franklin@ug.cs.dal.ca (Steve Franklin)
Subject: Can Flex Parse Multiple _Strings_?
Date: 1998/02/18
Message-ID: <6cdnb6$87k$1@News.Dal.Ca>
X-Deja-AN: 326094083
Organization: ISINet, Nova Scotia
Newsgroups: comp.unix.programmer,comp.os.linux.misc,comp.os.linux.development.apps,gnu.misc.discuss,comp.lang.c