Preprocessor harder to write than parser?

Discussion in 'C Programming' started by Peter Ammon, Jul 14, 2007.

  1. Peter Ammon

    Peter Ammon Guest

    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
     
    Peter Ammon, Jul 14, 2007
    #1
    1. Advertising

  2. 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
     
    Jean-MArc Lienher, Jul 14, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marc Twain
    Replies:
    3
    Views:
    342
    Christophe Vanfleteren
    Nov 21, 2003
  2. EightNineThree

    Re: Making pictures harder to steal...

    EightNineThree, Aug 9, 2003, in forum: HTML
    Replies:
    0
    Views:
    404
    EightNineThree
    Aug 9, 2003
  3. Talc Ta Matt

    Re: Making pictures harder to steal...

    Talc Ta Matt, Aug 9, 2003, in forum: HTML
    Replies:
    1
    Views:
    333
    William Tasso
    Aug 9, 2003
  4. =?ISO-8859-1?Q?Fran=E7ois_de_Dardel?=

    Re: Making pictures harder to steal...

    =?ISO-8859-1?Q?Fran=E7ois_de_Dardel?=, Aug 9, 2003, in forum: HTML
    Replies:
    1
    Views:
    352
    Toby A Inkster
    Aug 9, 2003
  5. James Adam
    Replies:
    0
    Views:
    116
    James Adam
    Nov 2, 2009
Loading...

Share This Page