C preprocessing

John T. Baldwin johnb at srchtec.UUCP
Tue Sep 25 00:55:25 AEST 1990


[ellipsis indicates deletion for brevity --jtb]

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
>instead of what I said?
>...
>Code is written two-dimensionally ... why does it have to processed as
> a one-dimensional string of tokens?
>...
>    if (bool_expression)
>        do_something();
>        do_something_else();
>        if (another_bool_expression)
>            do_anything();
>    else
>        do_this_when_bool_expression_is_false();

This begs several questions.

#1  Why does the program have to be processed as a one-dimensional string
    of tokens?

It doesn't.

At least, programs in general do not have to be processed this
way.  Your C programs are, because the language has been defined that way.
The reason why language designers like to do this is because it makes it
easier to write the compiler (i.e. the lexer and parser are easier).

If this is not complete enough for you, I'd suggest learning something
about compilers.  I'm *not* a compiler expert, but a good book to read is
the so-called "Dragon Book" by Aho, Sethi, and Ullman (sp?).
At least it is a widely-known text, and I liked it. :-)

#2  Why can't the compiler "catch" the fact that what was meant (above)
    isn't what was said?

Because a compiler's job is to translate what was *said*.  The only
analysis the compiler is required to perform is whatever is germane
to that task.

If you want a critique, use LINT or a lint-like analyser.  At least
one LINT that I know of "understands" general indentation rules and
will flag the probable error above, i.e.

   "line xxx: do you know you *outdented* the 'else' that goes with
    'if (another_bool_expression)' ???"


#3   Wouldn't it be nice if the compiler would do what I meant, instead
     of what I said?

Yes.

When you (or anyone else) manages to do this, be *sure* to publish.  Quickly.
You'll probably win a Nobel Prize.    :-)   :-)   :-)   :-)   :-)



-- 
John T. Baldwin                      |  johnb%srchtec.uucp at mathcs.emory.edu
Search Technology, Inc.              | 
                                     | "... I had an infinite loop,
My opinions; not my employers'.      |  but it was only for a little while..."



More information about the Comp.lang.c mailing list