简体   繁体   中英

How was the first C compiler written?

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?

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM