Related articles |
---|
How to restart FLEX scanners? jenglish@flightlab.com (1999-02-03) |
Re: How to restart FLEX scanners? gneuner@dyn.com (1999-02-12) |
Re: How to restart FLEX scanners? rkrayhawk@aol.com (1999-02-16) |
Re: How to restart FLEX scanners? jenglish@flightlab.com (1999-02-18) |
From: | gneuner@dyn.com (George Neuner) |
Newsgroups: | comp.compilers |
Date: | 12 Feb 1999 02:56:05 -0500 |
Organization: | Dynamic ReSolutions, Inc. |
References: | 99-02-013 |
Keywords: | lex |
On 3 Feb 1999 23:55:26 -0500, jenglish@flightlab.com (Joe English)
wrote:
>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, ...);
> yy_switch_to_buffer(new);
> while (yyparse() != EOF_SIGNAL)
> evaluate(parse_tree);
> yy_delete_buffer(new);
> if (old != NULL)
> yy_switch_to_buffer(old);
> }
>
This won't work for either yyparse or yylex unless the "load file"
command functions as an inline substitution - i.e. the scanner's input
file is changed but the parser simply continues on with the parse
sequence.
Neither yyparse nor yylex can normally be called recursively. The GNU
project has a Yacc work-alike called Bison which can generate a
reentrant parser compatible with yylex, but as yet there is no
corresponding reentrant scanner tool.
George Neuner
Dynamic Resolutions, Inc.
Return to the
comp.compilers page.
Search the
comp.compilers archives again.