|How to restart FLEX scanners? email@example.com (1999-02-03)|
|Re: How to restart FLEX scanners? firstname.lastname@example.org (1999-02-12)|
|Re: How to restart FLEX scanners? email@example.com (1999-02-16)|
|Re: How to restart FLEX scanners? firstname.lastname@example.org (1999-02-18)|
|From:||email@example.com (Joe English)|
|Date:||3 Feb 1999 23:55:26 -0500|
|Organization:||Advanced Rotorcraft Technology, Inc.|
I have an interactive parser built with lex/yacc that I'm trying to
port to flex. It's giving me considerable problems.
The language has a "load file" command, which leads to the usual
re-entrancy problems. I'm solving this in the usual way: the grammar
is written to return one statement at a time, and the read-eval-print
loop looks something like this:
extern PARSE_TREE parse_tree; /* set by yyparse() %start rule */
int parse_file(FILE *fp)
YY_BUFFER_STATE old = YY_CURRENT_BUFFER;
YY_BUFFER_STATE new = yy_create_buffer(fp, ...);
while (yyparse() != EOF_SIGNAL)
if (old != NULL)
yywrap() always returns 1, which causes yylex() to return EOF, which
in turn causes yyparse() to return EOF_SIGNAL, and finally
parse_file() restores the previous input buffer and returns.
Everything seems to work fine so far: if main() calls
parse_file(stdin) (which can indirectly call parse_file(), recursively
to any depth and breadth) there are no problems. But if main() calls
parse_file() a second time, the program invariably gets a segmentation
fault somewhere in the bowels of malloc() or free().
This indicates that somebody is scribbling over memory that they
shouldn't be. I suspect that yylex() is the culprit, since this code
has been in production for several years (using stock lex on several
different Unices) with no problems.
My question is: what am I doing wrong? Is there any way to get a FLEX
scanner to start over again with a fresh input buffer after the
initial one is exhausted?
Thanks in advance for any advice,
[Don't do that. Neither yylex() nor yyparse() can be called recursively.
Return to the
Search the comp.compilers archives again.