You’re right. A compiler is itself a program that is compiled — so you need a program to compile it.
You’ve probably worked out, that you can program a computer by using binary codes directly, whether that involves moving wires, flipping switches, punching holes into paper cards… whatever.
So you do that to write a tiny program that turns a really simple language into binary codes (if you’ve heard of assembly language, that’s an example).
Then you use your simple language to write a bigger and more complicated one.
In modern times, when someone creates a processor, they provide a tiny piece of software that copies code to memory and starts running it, and a program to convert text commands into codes for the processor called an assembler.
Any program can be written in assembly language, but it’s hard because it’s pretty much just writing out the binary codes giving the codes names and using decimal numbers instead of 1’s and 0’s. For that reason they often supply a more useful language, C, that people can more easily use to write software. It’s not uncommon that a compiler is written in C.
This is something I couldn’t grasp until the very end of my first computer science class more than two decades ago. It’s a great question. The answer is no, not every program needs to be compiled.
The first programs and later the first compiler was created by programmers working directly with machine code.
Not got much experience with CS, but if I remember correctly, it kind of is a bit like if I was trying to tell a French person how to get to the store when you only speak English and they only speak French.
If your instructions are:
Take the third left
Walk 500 metres
Turn right
You could put it into a translator and get:
Prendre la troisième à gauche
Marcher 500 mètres
Tourner à droite
Your computer in this scenario speaks French and most programmers speak English. The compiler breaks down the code into the language that the machine understands.
Latest Answers