Re: Reentrant Flex and Bison

"Randall Hyde" <rhyde@shoe-size.com>
6 Jun 2000 23:18:48 -0400

          From comp.compilers

Related articles
Reentrant Flex and Bison etetz@my-deja.com (2000-06-03)
Re: Reentrant Flex and Bison rhyde@shoe-size.com (Randall Hyde) (2000-06-06)
Reentrant Flex and Bison richard.lanyon@wadham.oxford.ac.uk (1999-11-16)
Re: Reentrant Flex and Bison perkens@sdm.de (Burkhard Perkens-Golomb) (1999-12-07)
| List of all articles for this month |

From: "Randall Hyde" <rhyde@shoe-size.com>
Newsgroups: comp.compilers
Date: 6 Jun 2000 23:18:48 -0400
Organization: Compilers Central
References: 00-06-020
Keywords: lex, comment

<etetz@my-deja.com> wrote in message news:00-06-020@comp.compilers...
> I'm trying to create a reentrant scanner/parser using Flex and Bison
> (to create a simple scripting language for a Windows app). Bison has
> the %pure_parser directive to support creating a reentrant parser. The
> problem with this is it changes the interface to yylex to look like
> this:
>
> int yylex (YYSTYPE* yyval);
>
> Flex doesn't seem to have the corresponding support this feature. In
> other words, Flex is still going to expect yylex to look like "int yylex
> ()".
>
> Am I missing something?
>
> Curious,
> Eric Tetz
> [No, flex doesn't easily make reentrant lexers. -John]


It's been years since I wrote that portion of the HLA compiler, but
I suspect that all that you need is the following:


%{


/*
** Allow for a recursive version of Bison parser.
*/


#undef YY_DECL
#define YY_DECL int yylex( YYSTYPE *yylval, YYLTYPE *yylloc)




/* Other C Decls */


  I stuck this stuff at the (very) top of the FLEX file.
Whenever I had to make a recursive FLEX call, I just used
the prototype above.


I've been using the recursive parser quite a bit.
Flex itself must also work recursively because the recursive
parser calls wind up calling the scanner.
If you have any further questions, you can always download
the HLA (High Level Assembler) sources from
http://webster.cs.ucr.edu. The recursive entry into the
parser is somewhat kludgy, but it does work.
Randy Hyde
[That'll probably work for recursive calls to the lexer, but it's no
good for a reentrant lexer because yylex() is still full of static
variables. If you use the C++ option, the generated C++ class should
be reentrant. -John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.