AST from c code with preprocessor directives
How can I build an AST (Abstract Syntax Tree) from gcc C code in order to make some transformations, like below, and reproduce(generate) the code to C syntax again after that? if(condition_1){ //lines of code 1 } #ifdef expression_1 else if(condition_2){ //lines of code 2 } #endif into bool test = condition_1; if(teste){ //lines of code 1 } #ifdef expression_1 if(!(test) && condition_2){ //lines of code 2 } #endif GCC itself will build ASTs, but not before expanding the preprocessor directives. So the preprocessor conditionals are gone. Reinstalling them after you have done the transformations