C preprocessing

Alvin E. Sylvain asylvain at felix.UUCP
Thu Sep 27 02:48:51 AEST 1990


In article <18102 at haddock.ima.isc.com> karl at kelp.ima.isc.com (Karl Heuer) writes:
>In article <59770 at iuvax.cs.indiana.edu> bomgard at iuvax.cs.indiana.edu (Tim Bomgardner) writes:
>>Wouldn't it be nice, if ... the compiler would do what I meant [by
>>interpreting the indentation] instead of what I said?
>
>I personally like the idea, but it's not C (nor any other language I use,
>though I understand Occam has it).  So, being realistic, let's say instead:
>Wouldn't it be nice if the compiler (or some related tool) would provide
>(optional!) warnings for possibly misindented code?
>
>Things to worry about: (a) whitespace caused by macro expansion; (b) how to
>count tabs vs. spaces; (c) accepting all plausible personal indentation styles
>(or making it user-configurable).

Just write a PRE-pre-processor.  If the original C code is processed
before the C pre-processor gets it, you'll truly have "what you mean",
in terms of the actual code written, BEFORE any macro expansion.  Tabs
vs. spaces would have to be configured, similarly to your editor.
Indentation styles would have to be standardized by the tool ...
there is an infinite number of styles, and it would be difficult to
try to implement more than 1 or 2.

Since indentation is used for nearly all structured languages, the
tool could produce different constructs for different languages,
e.g., for *.c files, produce {} around indented code, for *.p (*.PAS)
produce begin-end, etc.  There may be some problem in deciding
when to include semi-colons.

This is definately creating a new 'language', much the same way the C
pre-processor allows 'extensions' to C.  If you REALLY want one, it
should be a relatively trivial task to build using 'lex' and 'yacc'.
It can have options for code-generation, or simple verification.

Otherwise, just suffer along with the rest of us, and BE CAREFUL!
(Note:  I always use the '%' command in 'vi', which verifies the
matching of () and {}.  This should be standard practice for all
programmers, along with other standard desk-checking procedures.
Too bad you can't use '%' in Pascal.)
--
------------------------------------------------------------------------
"I got protection for my    |               Alvin "the Chipmunk" Sylvain
affections, so swing your   |   Natch, nobody'd be *fool* enough to have
bootie in my direction!"    |   *my* opinions, 'ceptin' *me*, of course!



More information about the Comp.lang.c mailing list