扫描并分析c代码 [英] scan and analyse a c code

查看:68
本文介绍了扫描并分析c代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何扫描完整的c代码并获取贵重物品和函数之间的关系?结果打印成表?

解决方案

通过编写大量代码,基本上是半个C编译器。


嗯......你可以写一个程序来做我想的。问题在于你本质上是在写一个C编译器的好部分(解析器?lexer?)。请注意,在您运行分析器之前需要对代码进行预处理,否则宏可能会给您带来麻烦。


Hello叶千



你可以开始这里 [ ^ ]。这是一个基于python的c-parser,看起来很有前途。但是我没有使用过它。



周围可能有几个C解析器(肯定有几个yacc语法,例如http://www.lysator.liu.se/c/ANSI-C-grammar-y.html [ ^ ])。与C ++,C#等相比,C语言解析起来并不复杂。



真正的挑战从你想要对解析的AST执行的分析开始。

我不清楚你想从扫描中提取到底是什么。



干杯

岸堤

How can I scan a complete c code and get the relations between valuables and functions?Result printed to be a table?

解决方案

By writing a LOT of code, essentially half a C compiler.


Ummm... you could write a program to do that I suppose. The problem being that you would essentially be writing a good portion (parser? lexer?) of a C compiler. Beware that the code would need to be pre-processed before you run your analyzer on it or macros would probably cause you trouble.


Hello 叶千

you might start here[^]. This is a python based c-parser that looks promising to me. I have not used it, though.

There might be several C parsers around (for sure several yacc grammars, e.g. http://www.lysator.liu.se/c/ANSI-C-grammar-y.html[^]). The C language is not so complex to parse compared to C++, C#, etc.

The real challenge starts with the analysis you want to perform on the parsed AST.
It is not clear to me what exactly you want to extract from the "scan".

Cheers
Andi


这篇关于扫描并分析c代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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