Thread View: net.lang.c
3 messages
3 total messages
Started by James R. Van Zandt
Fri, 31 Oct 1986 17:16
Null source transformer for C
Author: James R. Van Zandt
Date: Fri, 31 Oct 1986 17:16
Date: Fri, 31 Oct 1986 17:16
26 lines
1604 bytes
1604 bytes
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
Re: Null source transformer for C
Author: Jon Leech
Date: Sat, 01 Nov 1986 01:37
Date: Sat, 01 Nov 1986 01:37
21 lines
1485 bytes
1485 bytes
In article <5058@brl-smoke.ARPA> jrv@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 (jon@csvax.caltech.edu || ...seismo!cit-vax!jon)
Caltech Computer Science Graphics Group
__@/
Re: Null source transformer for C
Author: Brian Campbell
Date: Wed, 05 Nov 1986 23:11
Date: Wed, 05 Nov 1986 23:11
4 lines
877 bytes
877 bytes
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.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads