[英]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. 我正在尝试编写JSON解析器(由于某些项目限制,而不是使用免费的解析器),并且已经使用简单的包装C ++类编写了基于lex + yacc的版本。 I have redefined the YY_INPUT macro for lex to read from a memory buffer.
我已经为lex重新定义了YY_INPUT宏,以便从内存缓冲区读取数据。 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:
有两个问题:
Would be great if folks can share their experience of doing something similar. 如果人们可以分享他们做类似事情的经验,那就太好了。
Cheers. 干杯。
PS. PS。 We don' t use STL/string or any templates for that matter.
我们不会为此使用STL /字符串或任何模板。 We use our own variant-based containers.
我们使用自己的基于变体的容器。 We use lex+yacc rather than flex+bison, on four major Unices.
我们在四个主要Unices上使用lex + yacc而不是flex + bison。
I don't have much experience working directly with yacc
, but I know that bison
supports reentrant parsers that are thread-safe. 我没有直接与
yacc
一起工作的经验,但是我知道bison
支持线程安全的可重入解析器 。 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. 看起来
lex
支持可重入lexer ,而且我想如果将两者放在一起,效果会很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.