开发者

How to build C interpreter using C++ or some other PL

I am looking at creating an interpreter fo开发者_开发百科r the C language.

I have got hold of this link but I would like to know if there is any better way to do it. Right now, I am looking at implementing it using C++. But if there is any other language which is better at this task then I am willing to change to that for this purpose .

I am building the interpreter for static analysis purpose, which would require operations like statement labeling, address storing, Heap address storing and other operations typically required for this analysis.

Any links which would help me in getting started would be great. Please share your thoughts and I would really appreciate it since it is a completely new area for me. Thank you all


A tool to statically analyze some code is not an interpreter.

Anyway, writing such tool is not a trivial thing, it requires a good understanding of how compilers work. Usually such job is split in many tasks: tokenizing the code, parsing it and building an abstract syntax tree first of all

These operations are simple to do once you declare your language (in this case C) rules, and there are many tools to automatize the process. Most famous tool is probably bison (which is for C); there are also many really good and easy-to-use C++ libraries (like boost.spirit), and even some languages which have been designed in order to do these stuff.

My suggestion is thus to improve your knowledge about compilers, and to try and write some parsers for simpler languages. You cannot start analyzing C from nowhere.


May I suggest using a library to do the parsing ?

Clang is a modular project providing (amongst other things) a C parser that yields a AST (Abstract Syntax Tree) that you can freely explore.

It also has a Static Analyzer work in progress, led by Ted Kremenek, that you should perhaps check out... and maybe you'll be able to contribute to it :)


Clang was already mentioned, so for the "other PL" part of the question I'd suggest to take a look at http://cil.sourceforge.net/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜