I have source files which contain preprocessor conditional statements. Looking like this:
#if A > 0 && (B < 1 || M == 0)
#if U == 0
do_something()
#endif
do_more()
#elif A == 0
do_somethingelse()
#else
print 'asd';
#endif
#else
and #elif
-statements are optional. Statements can be nested.
I want to match all the blocks, then evaluate the conditions (using eval or something) and then keep the relevant blocks.
I know it can be done using unidef, sunidef, coan - but I'm not allowed to use any of those. I want to avoid using gcc, as it does MUCH more then ONLY evaluating the conditional statements.
I read a lot on SO, it's said that using RegExp is a bad idea with nested statements. So I'm looking for a Python Parser and found quite many, like PyParsing.
Has anyone of you achieved something like that already? I mean not only parsing nested structures and returning the contents of the blocks, but also replacing them in the original string when some condition is met.
Thanks a lot in advance!