Thread-safe C++ wrapper around a lex/yacc parser
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. T开发者_如何转开发here are two concerns:
- Ultimately YY_INPUT is reading from a global object. I could not think of another way of doing this.
- 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.
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.
精彩评论