Python 1.2 - Types of language Translators
Types of language Translators
Note: Here we will only talk about general
conversion i.e. from source code to direct machine code. We will not talk about
the code forms which we will get between source code and machine code.
1. Compiler
Compiler is a
program or software which converts the source code written in a high level
language into machine code. The compiler reads and executes the entire
source code in one go. If there are any errors in the source code (our
program) then compiler will report all errors together. So if there are 10
errors in our program then the compiler will report all these 10 errors in one
go. Unless we remove all errors, compiler will not execute the code. Once we
remove all the errors then compiler will read and execute the entire code
again. If the source code is error free then the compiler will successfully
execute it and will give the machine code. Languages like C and C++ use
compiler.
2.
Interpreter
It also converts the
source code written in a high level language into machine code. The
interpreter reads and executes the instructions one by one. That is why
compiled code is faster than the interpreted code. The Interpreter reports
only one error at a time since it executes only one instruction at a time. So
if there are 10 errors in our program, then Interpreter will tell these errors
in 10 times. If we remove only first error (now there will be 9 errors in our
program) and run the code, then interpreter will give the output as far as the
code is correct. Then when we remove the second error (now there will be 8
errors in our program) and run the code, then interpreter will give the output as
far as the code is correct and so on. But compiler does not work this way. The
compiler will only output when there is not a single error in our program but
interpreter can give the result even if our program has errors because
interpreter reads and executes only one statement at a time but we have to
remove all the errors from Python program to get the final result. Languages
like Python, and Java use interpreter.
Main difference is
that a compiler will read the entire program together in one go and interpreter
will read only one statement at a time. For example, if there are 10 statements
in a program, then compiler will execute the program in one go whereas the interpreter
will take 10 times.
Wow man! amazing explanation. Keep it up bro.
ReplyDelete