Re: Thread-safety, lex and yacc.

Troy Cauble <>
10 Apr 2001 01:22:21 -0400

          From comp.compilers

Related articles
Thread-safety, lex and yacc. (Nicholas Dronen) (2001-03-31)
Re: Thread-safety, lex and yacc. (2001-04-04)
Re: Thread-safety, lex and yacc. (Troy Cauble) (2001-04-10)
Re: Thread-safety, lex and yacc. (Clark) (2001-04-12)
| List of all articles for this month |

From: Troy Cauble <>
Newsgroups: comp.compilers
Date: 10 Apr 2001 01:22:21 -0400
Organization: Bell Labs, Holmdel, NJ, USA
References: 01-03-164
Keywords: lex, yacc, parallel
Posted-Date: 10 Apr 2001 01:22:20 EDT

Nicholas Dronen <> wrote:

: Does anyone have experience with making an apparantly non-thread-safe
: lex/yacc code base thread-safe? Suggestions and pointers welcome.

: [If you tell flex to generate a C++ lexer, it's thread safe. Haven't
: seen a thread-safe yacc but I haven't looked very hard either. It
: wouldn't be hard to do. -John]

Flex C lexers are not thread safe, but I recently wrote an awk script
to make one thread safe. (C++ could not be used.)

Basic approach:
Redefine all globals in a structure passed in via YY_DECL.
The awk script removes the global definitions, substitutes
arg->global for all globals, and changes the generated
subroutines to take that structure also.

The script also dumped the definition of yy_buffer_state to
a header file so the argument structure could reference it.

A *lot* of the generated subroutines were superfluous for my
intended use, so the awk script just removed those. I also
created an error return for yy_get_next_buffer() and took out
the exit() call.


Post a followup to this message

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