C++ parser generator [closed]

六眼飞鱼酱① 提交于 2019-11-29 12:03:05

Try with Flex and Bison. They are good lexical analizers and parser generator usefull to define new languages.

http://en.wikipedia.org/wiki/Flex_lexical_analyser

http://en.wikipedia.org/wiki/Comparison_of_parser_generators

for C/C++: http://epaperpress.com/lexandyacc/

Or look at: Boost.Spirit:

"Spirit is a set of C++ libraries for parsing and output generation implemented as Domain Specific Embedded Languages (DSEL) using Expression templates and Template Meta-Programming."

Dou you really need new language? maybe it would be better to use some well known like Lua, Python?

Lars

It's an old question but still might be relevant: since I was unhappy with the existing options, I recently wrote a template c++ parser generator which doesn't need any external tools (you include a header and define the grammar directly in the c++ source). It uses readable PEG grammars so there is no need for a separate lexing step. You can check it out on Github.

You have two choices: whether you create your own parser by creating an AST (abstract syntax tree), then it will be a good exercise for you but it's very long and hard to implement. Or you can use an open source solution such the ANTLR parser generator which has a grammar for C/C++ as well as the preprocessor. I've never used it so I can't say how complete its parsing of C++ is going to be. Then If you are in hurry and you want to create a good parser, you'd better use the second solution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!