Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AST from C code [closed]

Tags:

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?

like image 214
Sachin Khot Avatar asked Oct 27 '08 12:10

Sachin Khot


People also ask

What is AST in C?

In computer science, an abstract syntax tree (AST), or just syntax tree, is a tree representation of the abstract syntactic structure of text (often source code) written in a formal language.

Does GCC use AST?

GCC has a number of AST optimizations that attempt to optimize trees during parsing. These have limited effectiveness, and complicate the parser. It would be better to put these all in one place, where they can be more effective (by being repeated, or using common data).


1 Answers

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.

like image 124
Louis Gerbarg Avatar answered Oct 02 '22 19:10

Louis Gerbarg