Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Null source transformer for C

4 views
Skip to first unread message

James R. Van Zandt

unread,
Oct 31, 1986, 12:16:34 PM10/31/86
to
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

Jon Leech

unread,
Oct 31, 1986, 8:37:28 PM10/31/86
to
In article <50...@brl-smoke.ARPA> j...@MITRE-BEDFORD.ARPA (James R. Van Zandt) writes:
>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.
>

> replace the operators + - * / with equivalent function calls.

Another example that I badly needed recently is a 'diff'-like program
driven by syntax rather than text; I had two divergent versions of a large
program with differing indentations, preprocessor usage, etc. The idea is
to build parse trees for two sets of source code and compare them function
by function at the syntax level, then reconstruct source code for the


-- Jon Leech (j...@csvax.caltech.edu || ...seismo!cit-vax!jon)
Caltech Computer Science Graphics Group
__@/

Brian Campbell

unread,
Nov 5, 1986, 6:11:23 PM11/5/86
to
The easiest way to 'diff' such files would probably be to run each of
them through the preprocessor and diff the result. I think there is an
option (-b) to diff which ignores blanks (treats any series of blanks as
a single blank) which should solve the indentation problem.
0 new messages