On Apr 21, 2005, at 8:29 AM, Cheng Po-wen wrote:
(B
(B> Hi,
(B>
(B> I have a a question about how to reuse a scanner,
(B> The document (which is flex.pdf -- Flex, version 2.5.31) says
(B>
(B> there is no need to destroy a scanner if you plan to reuse it. A flex
(B> scanner (both reentrant
(B> and non-reentrant) may be restarted by calling yyrestart
(B>
(B> my question is :
(B>
(B> 1. Is it safe, for a long lived applicaion to reuse a scanner all the
(B> time by calling
(B> yyrestart(..) ?
(B>
(B> will there be any dangling resources, which are not released or freed (B> by
(B> doing so???
(B
(BLooking at the man page:
(B
(B Essentially there is no difference
(B between just assigning yyin to a new input file or using (Byyrestart() to
(B do so; the latter is available for compatibility with previous (Bversions
(B of flex, and because it can be used to switch input files in the (Bmiddle
(B of scanning. It can also be used to throw away the (Bcurrent input
(B buffer, by calling it with an argument of yyin; but better is (Bto use
(B YY_FLUSH_BUFFER (see above). Note that yyrestart() does not (Breset the
(B start condition to INITIAL (see Start Conditions, below).
(B
(BI read that to say yyrestart just points yyin to point to the next (Binput file, and flushes the current input buffer. Other than the (Bcurrent input buffer, I guess it doesn't free any resources... I also (Bread that to say yyrestart is not the preferred way to do this.
(B
(B>
(B> 2. Does yy_scan_buffer (or yy_scan_string) internally do the "yyrestart
(B> things" ?
(B>
(B> what I mean is my scanner scans "strings", instead of "stdin".
(B> so, if i want to reuse a scanner,
(B> do I have to call yyrestart(NULL , my_scanner), and then call
(B> yy_scan_buffer(.....) ???
(B>
(B> or I can just call yy_scan_buffer(.....), and it internally does the
(B> "yyrestart things" ?
(B
(BI have had success doing the following in a loop (while also using (Byacc/bison):
(B
(Bstruct yy_buffer_state* bufferState;
(Bs="some string";
(B...
(BbufferState = yy_scan_string(*s);
(Byyparse();
(B yy_delete_buffer(bufferState);
(B...
(B
(BThis seems to work as I expect it to. I am just learning flex myself, (Bso everything above may be totally wrong...
(B
(BAaron
(B
(B>
(B> THANX
(B>
(B> Sting
(B>
(B>
(B>
(B> The function yylex_destroy should be called to free resources used by
(B> the scanner.
(B> After yylex_destroy is called, the contents of yyscanner should not be
(B> used. Of course,
(B> there is no need to destroy a scanner if you plan to reuse it. A flex
(B> scanner (both reentrant
(B> and non-reentrant) may be restarted by calling yyrestart
(B>
(B> -- (B> Sting, Cheng Po-wen($BE"GnJ8(B)
(B> Phone : 886-3-5914545 Fax : 886-3-5820085
(B> E-Mail : [EMAIL PROTECTED]
(B>
(B> Internet Software Technology Division(W100)
(B> Computer & Communication Research Lab. / ITRI
(B>
(B>
(B>
(B> _______________________________________________
(B> Help-flex mailing list
(B> [email protected]
(B> http://lists.gnu.org/mailman/listinfo/help-flex
(B>
(B
(B
(B
(B_______________________________________________
(BHelp-flex mailing list
([email protected]
(Bhttp://lists.gnu.org/mailman/listinfo/help-flex

Reply via email to