Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 574
Jaskaran S.P Avatar asked Aug 08 '13 12:08

Jaskaran S.P


People also ask

How was the first compiler written?

To directly answer your question: the first compiler was written (by a human) in an assembly language -- a program called an assembler would translate assembly language into binary; this is a much simpler process than compilation because assembly language is just a symbolic form of machine language that uses opcode ...

How was C compiler written?

C was first written in B which was a stripped down BCPL which was a stripped down Algol 60 I believe. B was probably written in a macro assembler though.

What was the original C compiler?

The first C compiler, written by Dennis Ritchie, used a recursive descent parser, incorporated specific knowledge about the PDP-11, and relied on an optional machine-specific optimizer to improve the assembly language code it generated.

How are compilers written?

A very simple compiler can be written from an assembler and machine code. Once you have a software that is able to translate something into binary instructions, you can use the original compiler to write a more sophisticated one (then use a second further refined one to write a third and so on).


2 Answers

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.

like image 177
Hans Passant Avatar answered Sep 24 '22 18:09

Hans Passant


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

like image 44
Belkacem REBBOUH Avatar answered Sep 21 '22 18:09

Belkacem REBBOUH