Preprocessor harder to write than parser?

P

Peter Ammon

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?

Thanks!
-Peter
 
J

Jean-MArc Lienher

Peter said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top