Ticker

6/recent/ticker-posts

Difference between Compiler vs Interpreter

Compiler vs Interpreter:



today we are going to learn about the main differences between a compiler and an interpreter so at first you should know that both compiler and interpreter are program used for translation each one of them do their job using its own way and this is what we are going to see in this blog

before we start you should know about two important terminologies which will be used later those terms are high level language and low level language . unfortunately computers can just understand binary which refers to zeros and ones the fancy word for binary is machine language which is considered one of the low level languages because it's closer to the understanding of the computer than to humans because it's almost impossible for the human to write code that the computer using only zeros and ones. 

Other intermediate languages are born nowadays the languages that the human uses to write code are pretty close to english and some examples of that are python,  c and java and those are called high-level languages because they are closer to the understanding of humans than to the computer but you may have recognized that there is still a problem the computer can just understand the low-level languages but the human is providing high-level languages how can that be solved 

for that purpose we need a translator to do that job exactly it's here where compiler and the interpreter are used now after this little journey let us go back to where we started so as we mentioned earlier both compiler and interpreter work as translators from high-level language to a low-level language let's now see how each one of them do is the compiler takes the entire program you wrote in a high-level language and translates the whole of it into machine code at once after.

this process an executable file will be ready to run the translation takes some times to be done but after that execution is so fast unfortunately any error in the program will fully stop it from working errors will be displayed at the end of the compilation the interpreter takes each single instruction of the code translate it then execute it on its own the translation step before the program runs is fast because the program will start immediately but execution will run slowly the great thing about interpreters is that the program will fully execute until an error occurs.  errors will be displayed after each instruction that contains it. 

let's see now real examples of compilers and interpreters in the first example we are going to see the intermediate executable file that the compiler creates for this example we have a c language program and we will try to compile it and see what will happen as you can see the compiler has created an intermediate object file test [Applause] this file has the extension.exe which means it is an executable file in this example we are using python interpreter and we want to create a program file and see what will happen as you can see a test file is created without any additional intermediate files and these files has the extension.ui which means it's directly opened by the interpreter for the other example we will see how the errors are displayed which will clarify the way of working we mentioned earlier.

 we are using here the new compiler online which do both compiling and execution in one step to make it easy use the printf function which displays on the screen what's written between the double quotation let us make an error and see the output as you can see the compilation stopped due to the error and no output is displayed in this case we are using the bash interpreter and this echo function is the same as printf let us make an error and see the output in this case you can see that the interpreter executed the first statement and gives an error for the second which clarify how the interpreters work after this long journey let's see this table that summarizes everything we mentioned take your time and read it if you find this blog helpful please don't forget to leave a like a comment and a follow to see every blog we upload in the near future and as always thanks for comming

Post a Comment

0 Comments