The program that we write on a computer system is called a source code and the computer system can’t directly understand our program as it can only understand the object code in 0 and 1 format. For this we need translators to convert our source code into object code for successful execution. in this article I will focus on two types of translators, i.e, Compiler and Interpreter used in high level programming languages.
Compiler is a translator that reads the entire program and converts it to source code for successful execution. The compiler also give us the errors and warning if any before the program execution. The source code acts as an input to the compiler and the object code is the output of the compiler.
But the process of compilation takes some time as we need to correct all the errors it gives before program execution. It can also link intermediate classes and subroutines to the source program and act as a linker. Most of the high level languages such as C, C++, JAVA, etc. uses compiler.
Interpreter is also a translator and converts the source code into object code but in a different way than the compiler. The interpreters reads the source code line by line and executes the program directly. The object code is also created line by line.
The interpreters are fast as compered to compilers as they don’t go for error checking at a whole and the error is checked at the run-time. Very high level languages such as C#, F#, etc are interpreter oriented.
You can differentiate between compiler and interpreter as follows,
- Translate the source code into object code
- Reads the entire source code or program
- After the entire source code is read the compiler produces the object code
- It executes the program at last after the entire source code is read
- Provides a list of errors and warnings before execution
- Program execution is slower in compiler
- High level languages such as C, C++, JAVA, etc. are compiler employed
- Translate the source code into object code but in a different way
- Reads the source code or program line by line
- Object code is created line by line by the interpreter
- Executes the program instantly line by line
- Provides errors and warning at the time of execution
- Program execution is faster in an interpreter
- Very high level languages such as VB.NET, C#, F#, etc. are interpreter employed