C preprocessing

Tim Bomgardner bomgard at iuvax.cs.indiana.edu
Tue Sep 25 12:13:08 AEST 1990


In article <223 at srchtec.UUCP> johnb at srchtec.UUCP (John T. Baldwin) writes:
}[ellipsis indicates deletion for brevity --jtb] --tab, too.
}
}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.

But it is.  And it has to be, "because the language has been defined that
way."  Assuming of course you still consider what I wrote to be C.

}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).
}
}[...suggestion that I read up on compiler theory]

Boy, give 'em lex and yacc and tell 'em about LALR(1) and they're ready
for the big time.  I've produced a compiler or two.  I don't know about
the "language designers" here, but my parsers have no difficulty at all
with this sort of grammer.  You wanna know what's hard?  The parser I'm
working on right now recognizes graphics.

}#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.

Says you.  In the case of C, I agree.  But I'm not really talking about
C anymore.  Maybe I shouldn't call it a preprocessor, although that's
how I think of it.  Perhaps translator would be a better word.  My
intention is to translate into C the way AT&T does with C++.

}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)' ???"

You see!  It isn't really all that hard at all to recognize what's
going on.  But I don't want a critique; I want it to just do it.  That's
why I use a compiler in the first place instead of an assembler.

}#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.    :-)   :-)   :-)   :-)   :-)

Fortran gave us data abstraction.  Block structured languages gave us
control abstraction.  What I'm looking for now I'll call structure
abstraction.  When I design something, I use little diagrams and pictures
and sometimes raw C code as well.  I then take all that and translate it
into C.  My goal is to have the computer do that for me.  I really don't
care about a nobel prize that much (my ideas aren't really that original),
but I WILL be accepting VISA and Mastercard.

}
}-- 
}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..."

To all who have responded, thank you.  I appreciate the feedback.  This is
helping me refine the concepts.  More to come.

Tim



More information about the Comp.lang.c mailing list