C compiler

Discussion in 'C Programming' started by Bill Cunningham, Jul 27, 2013.

  1. How could one write the simplest C compiler possible. Like the one that
    came in Unix V7? I guess some knowledge of binutils development would would
    be needed right?
    Bill Cunningham, Jul 27, 2013
    1. Advertisements

  2. Bill Cunningham

    Öö Tiib Guest

    Simplest compilers typically translate already preprocessed code
    to some lower language like LLVM or assembler. No optimizations
    just one-to-one and no binaries just text-to-text.

    There is no much point to write C compilers because there are
    too lot of excellent open source C compilers available already.

    Try to write things that are missing or are present but inconvenient.
    If you are particularly interested in compilers and translators then
    better write a translator from (subset of) some interpreted language
    into C. Even if you can not ... then it is still better because we are
    humans (cooperative) and so the questions that you ask when trying
    to ... may raise interest of someone who can.
    Öö Tiib, Jul 28, 2013
    1. Advertisements

  3. Hi,
    There exist lots of nice candidates. I myself have collected over the years, over 250 small compiler projects.

    Some suggestions (just the first ones coming in mind):

    - nwcc by Nils Weller
    - pcc (revamped)
    - the compiler projects at ftp://compilers.iecc.com
    - plan9 compilers
    - subc by Nils Holm (t3x.org)
    - Lennart Augustsson's obfuscated compiler to ELF for x86 (otcc)
    - smallc compilers (not ANSI/ISO C per se)
    - tcc

    There are many, many more, with varying level of ANSI/ISO C (89) support.

    For a production-level compiler, I have three suggestions:
    1) GCC
    2) LLVM
    3) COINS (search for COINS compiler infrastructure)

    GCC and LLVM are the dominant open-source compilers. The latter one in the list is a real neglected jewel.

    Best regards
    Nikolaos Kavvadias
    nikolaos.kavvadias, Jul 28, 2013
  4. Do you know if any of them compile C to 16-bit with far pointers - at least
    for data references? I am after one that will run on Linux. I have bcc but
    it only supports short pointers.

    James Harris \(es\), Jul 29, 2013
  5. Bill Cunningham

    Jorgen Grahn Guest

    "The Design and evolution of C++"? I'm afraid it doesn't say a lot
    about compiler construction, beyond the choice of parsing technique.
    A good book though; fun to read even if you're not interested in C++.

    Jorgen Grahn, Aug 3, 2013
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.