多个flex/bison解析器 [英] Multiple flex/bison parsers
问题描述
处理一个项目中的多个Flex/Bison解析器的最佳方法是什么?
What is the best way to handle multiple Flex/Bison parsers inside a project?
我写了一个解析器,现在在同一个项目中需要第二个解析器.到目前为止,在parser1.y
的第三部分中,我插入了main(..)
方法并从此处调用yyparse
.
I wrote a parser and now I need a second one in the same project. So far in the third section of parser1.y
I inserted the main(..)
method and called yyparse
from there.
我想要获得的是拥有两个不同的解析器(parser1.y
和parser2.y
),并且能够通过外部函数使用它们(假设main.cpp
中的main
).
What I want to obtain is having two different parsers (parser1.y
and parser2.y
) and be able to use them from an external function (let's assume main
in main.cpp
).
我应该采取哪些预防措施将yyparse
函数导出到.y
文件之外,以及如何处理两个解析器?
Which precautions should I use to export yyparse
functions outside .y
files and how should I handle two parsers?
PS.我正在使用g ++进行编译,但未使用Flex和Bison的C ++版本进行编译,因此我想保持这种方式(因此避免将解析器封装在对象中).
PS. I'm using g++ to compile but not the C++ versions of Flex and Bison and I would like to keep it this way (so avoiding encapsulating the parser inside an object).
推荐答案
请注意,Bison提供了'-p zz'选项,以'zz'而不是'yy'作为符号的前缀.
Note that Bison provides the '-p zz' option to prefix symbols with 'zz' instead of 'yy'.
类似地,Flex提供了'-P zz'选项,为符号加上'zz'而不是'yy'前缀.它使用"-p"进行性能报告. 可惜他们彼此之间并不一致.
Similarly, Flex provides the '-P zz' option to prefix symbols with 'zz' instead of 'yy'. It uses '-p' for performance reporting. 'Tis a pity they are not consistent with each other.
这篇关于多个flex/bison解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!