How was the first C compiler written?

后端 未结 3 1342
伪装坚强ぢ
伪装坚强ぢ 2020-12-07 15:27

Is it true that the first C compiler was written in C itself? Then, how was it executed and compiled? Or, was this compiler written in assembly language?

相关标签:
3条回答
  • 2020-12-07 16:05

    Reading Dennis Ritchie's note on primevalC indicates that, rather like the chicken and the egg, C evolved from a precursor language along with its own compiler via bootstrapping. The speciation timescales were quicker than for Gallus gallus domesticus.

    One can even see the compiler source code caught in the midst of the evolutionary turmoil. The note links to two snapshots of it restored from tape backups. This code has also been placed on github. These snapshots constitute intermediate fossils, years before K&R syntax. Dennis' description of one of the tapes shows it is a freeze-frame of structs being bootstrapped:

    "prestruct-c" is a copy of the compiler just before I started changing it to use structures itself.

    In other words the compiler had been augmented to support structs but didn't yet use them. A good time to make a tape backup...

    0 讨论(0)
  • 2020-12-07 16:07

    The first C compiler wasn't written in C, usually when writing a compiler we use either assembly language, or another programming language, and it's common that after first compilation, the compiler is rewritten in it's native language.

    There's a lot of programming languages that have been written in C then rewritten in their native language : Java for example, Ada ...

    0 讨论(0)
  • 2020-12-07 16:22

    It is described pretty well in Dennis Ritchie's writeup of the C language history.

    Giving just a summary of what he wrote there, use his article for the finer details. C started with the BCPL language, Ken Thomson had access to a compiler for it that ran on their General Electrics 635 main frame. Unhappy with the language, Thomson used BCPL to write a compiler for the B language, an evolutionary step beyond BCPL that removed some of the technical problems in BCPL.

    They used B to create programs on their PDP-7 minicomputer, although most of them were little more than toy programs, the machine had very restricted hardware capabilities. One important step taken by Thomson was to rewrite the B compiler in B itself. A common bootstrapping step.

    That compiler was then gradually tweaked, through a short-lived intermediary step called NB (New B) to start resembling C. The PDP-11 minicomputer was instrumental in that step, giving them enough room to improve the language and compiler.

    0 讨论(0)
提交回复
热议问题