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

I am looking for an interpreter for C.

I got a link but I would like to know if there is a better way to do this. Right now, I am considering implementing it using C ++. But if there is any other language that is better suited for this task, then I am ready to change it for this purpose.

I am creating an interpreter for the purposes of static analysis, which will require operations such as marking statements, storing addresses, storing heap addresses and other operations that are usually required for this analysis.

Any links that help me get started will be great. Please share your thoughts, and I would really appreciate it, because this is a completely new area for me. Thanks to everyone.

+4
source share
3 answers

A tool for static analysis of some code is not an interpreter.

In any case, writing such a tool is not a trivial task; it requires a good understanding of how compilers work. Usually, such a task is divided into many tasks: tokenizing the code, parsing it, and building an abstract syntax tree in the first place

These operations are simple as soon as you declare your language (in this case, C), and there are many tools to automate the process. The most famous tool is probably the bison (which is for C); There are also many really good and easy-to-use C ++ libraries (like boost.spirit) and even some languages ​​that were designed to do these things.

My suggestion is to improve your knowledge of compilers and try to write some parsers for simpler languages. You cannot start parsing C from nowhere.

+2
source

May I suggest using a library for parsing?

Clang is a modular project that provides (among other things) a C parser that provides an AST (abstract syntax tree) that you can freely explore.

It also has the work of the Static Analyzer, led by Ted Kremenek, that you should maybe check ... and maybe you can contribute :)

+1
source

Kling has already been mentioned, so for the β€œother PL” part of the question, I would suggest taking a look at http://cil.sourceforge.net/

+1
source

Source: https://habr.com/ru/post/1335960/


All Articles