创建C / C ++语法分析器/分析仪的好工具 [英] Good tools for creating a C/C++ parser/analyzer

查看:135
本文介绍了创建C / C ++语法分析器/分析仪的好工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是得到一个快速启动解析和分析C / C ++ code一些好的工具?

What are some good tools for getting a quick start for parsing and analyzing C/C++ code?

在特别,我在寻找开源工具处理C / C ++ preprocessor和语言。 preferably,这些工具将使用法/ yacc的(或Flex /野牛)的语法,不要太复杂。他们应该处理最新的ANSI C / C ++的定义。

In particular, I'm looking for open source tools that handle the C/C++ preprocessor and language. Preferably, these tools would use lex/yacc (or flex/bison) for the grammar, and not be too complicated. They should handle the latest ANSI C/C++ definitions.

下面是我到目前为止发现的,但是在细节上并没有看着他们(的想法):

Here's what I've found so far, but haven't looked at them in detail (thoughts?):


  • cscope的 - 老学校C分析仪。似乎并没有做一个全面的解析,虽然。描述为寻找C函数的荣耀的grep'。

  • GCC - 大家最喜欢的开源编译器。很复杂,但似乎做这一切。还有用于创建GCC的扩展名为创业板一个相关的项目,但由于一直没有更新GCC 4.1(2006)。

  • PUMA - 纯粹的机械手。 (从页面:这个项目的目的是
    提供类的C / C ++源代码的分析和操作的库。为了这
    目的PUMA提供类进行扫描,分析,当然操作C / C ++
    来源)。这看起来很有希望,但自2001年以来PUMA显然已被纳入 AspectC ++ ,但即使这样还没有更新项目尚未从2006年开始更新。

  • 各种C / C ++语法原料。你可以得到 C-C ++ - 语法 - 1.2.tar.gz ,但自1997年以来A本已无人维护小谷歌搜索拉起等基本的lex / yacc的语法,可以作为一个起点。

  • 任何其他方面?

  • CScope - Old-school C analyzer. Doesn't seem to do a full parse, though. Described as a glorified 'grep' for finding C functions.
  • GCC - Everybody's favorite open source compiler. Very complicated, but seems to do it all. There's a related project for creating GCC extensions called GEM, but hasn't been updated since GCC 4.1 (2006).
  • PUMA - The PUre MAnipulator. (from the page: "The intention of this project is to provide a library of classes for the analysis and manipulation of C/C++ sources. For this purpose PUMA provides classes for scanning, parsing and of course manipulating C/C++ sources."). This looks promising, but hasn't been updated since 2001. Apparently PUMA has been incorporated into AspectC++, but even this project hasn't been updated since 2006.
  • Various C/C++ raw grammars. You can get c-c++-grammars-1.2.tar.gz, but this has been unmaintained since 1997. A little Google searching pulls up other basic lex/yacc grammars that could serve as a starting place.
  • Any others?

我希望以此为起点,翻译C / C ++源代码到一个新的玩具语言。

I'm hoping to use this as a starting point for translating C/C++ source into a new toy language.

谢谢!
-Matt

Thanks! -Matt

(由2/9):就在澄清:我想提取从preprocessor除了C / C ++ code本身的语义信息。我不希望的#define富42到消失在整数42,但保持附接到名称为foo。这不幸的是,排除先运行preprocessor,只交付的C几种解决方案/ C ++语法树)

(Added 2/9): Just a clarification: I want to extract semantic information from the preprocessor in addition to the C/C++ code itself. I don't want "#define foo 42" to disappear into the integer "42", but remain attached to the name "foo". This, unfortunately, excludes several solutions that run the preprocessor first and only deliver the C/C++ parse tree)

推荐答案

借助 ANTLR 解析器发电机具有的grammar 的C / C ++以及在preprocessor。我从来没有用过它,所以我不能说其C ++的语法分析如何完善将是。 ANTLR本身的一对夫妇的场合是一个有用的工具,我要解析更简单的语言。

The ANTLR parser generator 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. ANTLR itself has been a useful tool for me on a couple of occasions for parsing much simpler languages.

这篇关于创建C / C ++语法分析器/分析仪的好工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆