Flex ++ Bisonc ++解析器 [英] Flex++ Bisonc++ parser
问题描述
我正在尝试在项目中使用flex
和bison
为文件结构生成解析器代码.主要的编程语言是C ++,项目基于主要并行运行的OO设计.
I'm trying to use flex
and bison
in my project to generate a parser code for a file structure. Main programming language is C++ and project is on an OO design mainly running in parallel.
我听说flex
和bison
生成的解析器是C代码,它们不能重新输入.谷歌搜索,我发现了flex++
和bisonc++
.不幸的是,没有简单的入门指南.大多数示例均基于bison/flex
.有些人以某种方式将bison/flex
解析器集成到了他们的C ++代码中.他们应该是"tric脚的" ...
I heard that flex
and bison
generated parsers are C codes and they're not reenterant. Googling, I found flex++
and bisonc++
. Unfortunately there is no simple tutorial to get started. Most examples are based on bison/flex
. Some people somehow integrated bison/flex
parsers in their C++ code. They supposed to be "tricky"...
flex++
和bisonc++
的文档对我没有帮助.教程和示例,它们都从stdin获得输入,并在stdout上打印一些消息.
Documentation of flex++
and bisonc++
doesn't help me and. Tutorials and examples, they all get input from stdin and print some messages on stdout.
我在解析器中需要这些功能:
I need these features in my parser:
- 解析器应为C ++类,以常规方式定义(标头和cpp文件)
- 解析器从
std::string
或std::stringstream
或以空终止的char*
接收数据.
- Parser should be a C++ class, defined in normal manner (a header and a cpp file)
- Parser receives data from either an
std::string
orstd::stringstream
or a null-terminatedchar*
.
我感到很困惑.我应该使用flex++/bisonc++
还是flex/bison
?以及如何满足上述条件?
I feel so confused. Should I use flex++/bisonc++
or flex/bison
? And how to do that, satisfying above conditions?
推荐答案
有flex/bison,flex ++/bison ++和flexc ++/bisonc ++.我认为最好选择这三对中的一对,而不是混合/匹配flex ++和bisonc ++. 以下是 Flexc ++ 和
There are flex/bison, flex++/bison++ and flexc++/bisonc++. I think it's best to pick one of these three pairs, instead of mixing/matching flex++ and bisonc++. Here are the user guides for Flexc++ and Bisonc++.
在Flexc ++网站上:
From the Flexc++ website:
与flex和flex ++相反,Flexc ++生成的代码是 明确打算供C ++程序使用.著名的flex(1) 程序生成C源代码,而flex ++(1)仅提供类似C ++的代码 围绕着由flex(1)生成的yylex函数,几乎没有 支持有关C ++软件开发的最新想法. 与此相反,flexc ++创建了一个提供预定义的C ++类. 成员函数lex将输入与正则表达式进行匹配,并且 一旦匹配了正则表达式,就可能执行C ++代码.这 flexc ++生成的代码是纯C ++,允许其用户应用所有 该语言提供的功能.
Flexc++, contrary to flex and flex++, generates code that is explicitly intended for use by C++ programs. The well-known flex(1) program generates C source-code and flex++(1) merely offers a C++-like shell around the yylex function generated by flex(1) and hardly supports present-day ideas about C++ software development. Contrary to this, flexc++ creates a C++ class offering a predefined member function lex matching input against regular expressions and possibly executing C++ code once regular expressions were matched. The code generated by flexc++ is pure C++, allowing its users to apply all of the features offered by that language.
在Bisonc ++网站上:
From the Bisonc++ website:
Bisonc ++是用于转换语法的通用解析器生成器 LALR(1)上下文无关文法到C ++类的说明 解析该语法.一旦您精通bisonc ++,就可以使用 它开发了广泛的语言解析器,从 简单的桌面计算器到复杂的编程语言. Bisonc ++是 与Alain Coetmeur编写的bison ++程序高度可比: 所有正确编写的bison ++语法都应该可以转换为 bisonc ++语法变化很小或没有变化.任何熟悉的人 bison ++或其前身bison应该能够将bisonc ++与 小麻烦.您需要流利地使用C ++编程 以便使用bisonc ++或了解本手册.
Bisonc++ is a general-purpose parser generator that converts a grammar description for an LALR(1) context-free grammar into a C++ class to parse that grammar. Once you are proficient with bisonc++, you may use it to develop a wide range of language parsers, from those used in simple desk calculators to complex programming languages. Bisonc++ is highly comparable to the program bison++, written by Alain Coetmeur: all properly-written bison++ grammars ought to be convertible to bisonc++ grammars after very little or no change. Anyone familiar with bison++ or its precursor, bison, should be able to use bisonc++ with little trouble. You need to be fluent in using the C++ programming in order to use bisonc++ or to understand this manual.
因此,flexc ++/bisonc ++不仅仅是旧的flex/bison实用程序的包装.它们生成完整的C ++类,用于重入扫描/解析.
So flexc++/bisonc++ are more than just wrappers around the old flex/bison utilities. They generate complete C++ classes to be used for re-entrant scanning / parsing.
这篇关于Flex ++ Bisonc ++解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!