简体   繁体   中英

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. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM