问题描述
我想对 C 源代码执行一些转换.我需要一个 linux 上的工具来从源代码生成一个完整的 AST 以便我可以在这个 AST 上应用我的转换,然后将它转换回 C 源代码.我试过 ELSA 但它没有被编译.(我使用的是 Ubuntu 8.4).谁能建议一个更好的工具/应用程序?
I want to perform some transformations on C source code. I need a tool on linux that generates a complete AST from the source code so that I can apply my transformations on this AST and then convert it back to the C source code. I tried ELSA but it is not getting compiled. (I am using Ubuntu 8.4). Can anyone suggest a better tool/application?
推荐答案
我推荐 clang.它有一个相当完整的 C 实现,带有大多数 gcc 扩展,代码也很容易理解.他们的 C++ 实现是不完整的,但如果您只关心从 C 代码生成 AST,那应该没问题.根据您想要做什么,您可以使用 clang 作为库并直接使用 AST,或者让 clang 将它们转储到控制台.
I would recommend clang. It has a fairly complete C implementation with most gcc extensions, and the code is very understandable. Their C++ implementation is incomplete, but if you only care about generating ASTs from C code that should be fine. Depending on what you want to do you can either use clang as a library and work with the ASTs directly, or have clang dump them out to console.
这篇关于来自 C 代码的 AST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!