1
votes

I am trying to write a JSON parser (instead of using one of the freely available ones, because of certain project constraints) and have written lex+yacc based version with a simple wrapper C++ class. I have redefined the YY_INPUT macro for lex to read from a memory buffer. Now the deal is to ensure that the parser is thread-safe and I am not sure how easy it is to ensure that. There are two concerns:

  1. Ultimately YY_INPUT is reading from a global object. I could not think of another way of doing this.
  2. I have no idea how many globals does the generated lex/yacc code end up using.

Would be great if folks can share their experience of doing something similar.

Cheers.

PS. We don' t use STL/string or any templates for that matter. We use our own variant-based containers. We use lex+yacc rather than flex+bison, on four major Unices.

1
Thread-safe and re-entrant are two different beasts. Changed the title to use the correct term.paxdiablo

1 Answers

3
votes

I don't have much experience working directly with yacc, but I know that bison supports reentrant parsers that are thread-safe. It also looks like lex supports a reentrant lexer as well, and I'd guess that if you put the two together it should work out just fine.