Peter Ammon wrote:
I was watching a video about a new C front end for the LLVM C compiler
(on youtube, of all places), and the author made an interesting claim:
that writing a C preprocessor is much harder, and requires more code,
than a C parser.
Is this true? And if so, why?
Parser can be automatically generated from grammar with tools like Yacc
or Bison.
Preprocessor must be written by hand.
A C preprocessor is nearly a script language on its own.
It must be able to interpret the conditional expression in the #if
statement.
To see if it requires more code than the parser, you should count the
lines in the TCC source code ;-)
http://fabrice.bellard.free.fr/tcc/
Everything has been written from scratch by hand.
( I'm in the process to write my own C complier for my diploma work.
I've made an Open Source C99 preprocessor as a pre-study :
http://www.whoow.org/project/c5/release/c5-0.0.1.zip
It is not clean, it's only designed to determine the feasibility of the
project. )
http://www.oksid.ch