I basically need to write a C preprocessor with Python, I've search around and since i need to fully custom my code and have a perfect understanding of what's going on, I better writting on my own.
Here's where I am : I first parse some header files (.h) to find #define keyword and build up a dictionnary with all the founded directives (with their values they have one). Then I need to parse source files (.c) depending of the directives I've found earlier.
The mechanism I use at the moment to check if the code need to be processed is the following : I take all my define's name and their values and do a exec("define_name = define_value") (with the value '1' when not specified). Then to resolve a condition such as #if defined DEFINE_1 || defined DEFINE_2 && (DEFINE_3 == 10) .... I remove the C preprocessor keyword to make them Python style wich will produce DEFINE_1 or defined DEFINE_2 and (DEFINE_3 == 10).
And i finally use eval(...) on that string to find out the result.
THE QUESTION is I was wondering if the use of exec / eval is necessary and many people are somekind of reluctant to use them, is there a better solution?