Wednesday, December 21, 2011

What is a compiler?


A compiler is a special type of computer program that translates source code from a high-level programming language( human readable text file) into a lower level language (e.g., assembly language or machine code) that is a form that the computer can more easily understand. At its most basic level, a computer can only understand binary(  1 and  0). If a human being was to write an instruction for a computer using the language it understands(binary), that person will write very slowly and find the information contained in the long string of 1s and 0s incomprehensible, the person will also be prone to make a lot of mistakes and introduce errors in the intended instruction. A compiler is a computer program that was created to bridges this gap and make writing computer programs(instruction) more human friendly.
In the beginning when compilers were created, they were very simple programs that could only translate symbols into the bits, the 1s and 0s, the computer understood. Programs were also very simple, composed of a series of steps that were originally translated by hand into data the computer could understand. 

This method of programming was very time consuming and prone to mistakes by the writer of the computer instruction, so portions of this task were automated or programmed, and that was how the first compiler was written. This program assembled, or compiled, the steps required to execute the step by step program.
These simple compilers were used to write a more sophisticated compiler. With the newer version, more rules could be added to the compiler program to allow a more natural language structure for the human programmer to operate with. This made writing programs easier and allowed more people to begin writing programs. As more people started writing programs, more ideas about writing programs were offered and used to make more sophisticated compilers. In this way, compiler programs continue to evolve, improve and become easier to use.

If the compiled program can run on a computer whose CPU or operating system is different from the one on which the compiler runs, the compiler is known as a cross-compiler. On the other hand a decompiler is a program that translates from a low level language to a higher level one. A program that translates between high-level languages (e.g from python to JAVA for example) is usually called a language translator, language converter, or source to source translator. A language rewriter is usually a program that translates the form of expressions without a change of language.
A compiler's function include but may not be limited to the following: 
  • lexical analysis
  • pre-processing ( usually a pre-compiler built in with the compiler run through the code first)
  • parsing of the code for syntax errors
  • semantic analysis (Syntax-directed translation)
  • generation of the code
  • also to optimize the generated code
Hope you have gained some knowledge about compilers(at least the basic understanding). For a more detailed explanation you can check Wikipedia here.

Note:
The faults or errors introduced into the compiled program by an incorrect behavior of a compiler in compiling the source code can be very difficult to track down. 

Season Greetings from Giga Frequency

No comments:

Post a Comment