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. Advertisements

  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. Advertisements

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:
    466
    Christophe Vanfleteren
    Nov 21, 2003
  2. Talc Ta Matt

    Re: Making pictures harder to steal...

    Talc Ta Matt, Aug 9, 2003, in forum: HTML
    Replies:
    1
    Views:
    418
    William Tasso
    Aug 9, 2003
  3. =?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:
    426
    Toby A Inkster
    Aug 9, 2003
  4. Cronus
    Replies:
    1
    Views:
    921
    Paul Mensonides
    Jul 15, 2004
  5. student08

    Java C Parser/Preprocessor

    student08, Apr 1, 2008, in forum: Java
    Replies:
    11
    Views:
    2,036
    Gordon Beaton
    Apr 9, 2008
  6. James Adam
    Replies:
    0
    Views:
    190
    James Adam
    Nov 2, 2009
  7. James Adam
    Replies:
    0
    Views:
    202
    James Adam
    Mar 22, 2010
  8. Iulian Ilea
    Replies:
    1
    Views:
    483
    pcx99
    Dec 21, 2006
Loading...