A Compiler is a program or set of programs that converts source code written in a high-level language to low-level language (assembly language or machine language). A programming language can have many compilers. For example – GCC C, Turbo C, Quick C etc. are different compilers for C programming language.
Why do we need a compiler?
A Computer understands only binary language and executes instructions coded in binary language. It cannot execute a single instruction given in any other form. Therefore, we must provide instructions to the computer in binary language. Means we must write computer programs entirely in binary language (sequence of 0s and 1s).
But think for a while, how cumbersome programming would have been, if we have to write every program as a sequence of 0s and 1s? It would have been a nightmare to write complex software's. Humans are good at giving instructions in English language, whereas computers can only process binary language.
So, there was a need of a translator that translates the computer instructions given in English language to binary language. Hence, to accomplish the job of a translator compiler was invented. The world’s first compiler was written by Grace Hopper in 1952 for the A-0 programming language.
What do a compiler do?
Apart from translating source code from high level language to low level language, compiler has other responsibilities too. After reading source code written in high level language it performs below operations -
- Performs a pre-processing of source code. Gather all files required for the source code to compile.
- Parses the entire source code. Checks for any syntax errors in the source code.
- Performs a thorough syntax analysis of the source code. To understand the structure and semantic of the source code.
- Optionally translates the source code in an intermediate code known as object code to enhance the performance.
- Translates the object code to binary language known as executable code.
Some popular compilers
|BASIC||FreeBASIC||FreeBASIC development team|
|C||GCC C||GNU Project|
|Borland Turbo C||Embarcadero|
|Java||javac||Sun Microsystems (Owned by Oracle)|