Preprocessor harder to write than parser?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Ammon

    Preprocessor harder to write than parser?

    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
  • Jean-MArc Lienher

    #2
    Re: Preprocessor harder to write than parser?

    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 ;-)

    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 :

    It is not clean, it's only designed to determine the feasibility of the
    project. )


    Comment

    Working...