precompiler for modifications on c/c++ source code?
i have the following problem where i can't find a suitable solution for.
i'd like to write a small precompiler that knows basic c++ language components like (for, while, do while, switch and if-else if-else). what i try to do is...
for example i make an annotiation in a c++ source code just before a for-loop (just an example) like this:
//@instrument=for
for(int i=0; i<10; i++)
{
printf("just an example");
}
now i wanna run my precompiler with the name of the source code file as argument. the precompiler shall read the source code file and make the following modifications to it:
count();
startTime();
for(int i=0; i<10; i++)
{
countEach();
startTimeEach();
printf("just an example");
stopTimeEach();
}
stopTime();
The inserted function calls are just examples. The precompiler knows the right function calls from a config file.
but how can i get sure that the modifations are made at the right place.
i don't wanna build a huge parser with syntay trees and all the stuff, cause the i have to implement the whole c/c++ syntax and grammar.
i'm only interested in looking for annotations, check if the following statement is accepted and then, finally, make the modifations to it.
can anyone there give me a hint where to start?
i read the manual of lex/flex and i found some interesting things like searching for symbols with regular expressions and performing special actions when a symbol is found. but thats not enough...
any ideas?

