01-23-04 10:36 PM
Hello,
I'm creating a small program which runs as a MT daemon where users can
connect using HTTP and perform misc tasks. One thing the user can do is
to post source code for a tiny special purpose language I designed.
I use Bison & Flex to parse the source code and believe I've created a
thread save version, using the %pure_parser directive. The parser reads
its input from a character buffer, not from file.
The problem is this: The first time I try to compile some source,
everything works well. The second time I get a "syntax error" message on
line 1.
My "theory" is that either flex or bison holds some kind of state info
and that they need to be reset in some way. If that is correct, doesn't
that indicate that the parser isn't reentrant?
I've browsed the C source generated by flex, and IMHO it looks quite
suspicious. Here's a few lines from the generated code:
quote:
> static YY_BUFFER_STATE yy_current_buffer = 0;
>
> /* We provide macros for accessing buffer states in case in the
> * future we want to put the buffer states in a more general
> * "scanner state".
> */
> #define YY_CURRENT_BUFFER yy_current_buffer
>
>
> /* yy_hold_char holds the character lost when yytext is formed. */
> static char yy_hold_char;
>
> static int yy_n_chars; /* number of characters read into yy_ch_buf */
>
>
> int yyleng;
>
> /* Points to current character in buffer. */
> static char *yy_c_buf_p = (char *) 0;
> static int yy_init = 1; /* whether we need to initialize */
> static int yy_start = 0; /* start state number */
>
> /* Flag which is used to allow yywrap()'s to do buffer switches
> * instead of setting up a fresh yyin. A bit of a hack ...
> */
> static int yy_did_buffer_switch_on_eof;
All of these variables have file scope. This doesn't look good, does it?
Has anyone out there successfully used bison&flex in a multithreaded
program before? Is it doable, and if so, what am I doing wrong?
Regards,
Bjørn
--
The worlds fastest web server is now available
at http://highlander.metasystems.no:2000. Enjoy!
[ Post a follow-up to this message ]
|