Null source transformer for C

James R. Van Zandt jrv at MITRE-BEDFORD.ARPA
Sat Nov 1 03:16:34 AEST 1986


Several times I've wanted to make a change to some C source code that
would be minor, but requires parsing it.  Some examples are:

       Remove all the comments.

       Add a diagnostic printout at the beginning of each function.

       Compile a list of variables and the functions they're defined in.

       For all variables declared to be a particular type (say, COMPLEX), 
       replace the operators + - * / with equivalent function calls.

Any of these would leave most of the source code unchanged.  It seems
to me that the easiest way to implement one would be to start with LEX
and YACC code for a source to source transformer that would make no
changes.  That is, action routines that would only build a parse tree,
then tree walking routines that would (approximately) reproduce the
original source code.  Does anyone know a public domain source for

     (1) LEX/YACC code for such a null transformer,
     (2) any LEX/YACC code for parsing C, or
     (3) LEX code for C?

Please mail directly to me, as I don't subscribe to all of these groups.

                    - Jim Van Zandt



More information about the Comp.lang.c mailing list