Differences between Interpreter and Compiler | |
Interpreter translates just one statement of the program at a time into machine code. | Compiler scans the entire program and translates the whole of it into machine code at once. |
An interpreter takes very less time to analyze the source code. However, the overall time to execute the process is much slower. | A compiler takes a lot of time to analyze the source code. However, the overall time taken to execute the process is much faster. |
An interpreter does not generate an intermediary code. Hence, an interpreter is highly efficient in terms of its memory. | A compiler always generates an intermediary object code. It will need further linking. Hence more memory is needed. |
Keeps translating the program continuously till the first error is confronted. If any error is spotted, it stops working and hence debugging becomes easy. | A compiler generates the error message only after it scans the complete program and hence debugging is relatively harder while working with a compiler. |
Interpreters are used by programming languages like Ruby and Python for example. | Compliers are used by programming languages like C and C++ for example. |
How Interpreter and Compiler work?
To start with, a compiler creates the program. It will analyze all the language statements to check if they are correct. If it comes across something incorrect, it will give an error message. If there are no errors spotted, the compiler will convert the source code into machine code. The compiler links the different code files into programs that can be run such as exe. Finally the program runs.
An interpreter creates the program. It neither links the files nor generates machine code. The source statements are executed line by line while executing the program.
Advantages and disadvantages of Interpreter and Compiler
In case of using compilers, the program codes are translated into machine code already and hence the time to execute the code is very less. On the negative side, it is not possible to change the program without going back to the source code while working with a compiler.
Interpreters make working with the source code much easier. Hence they are highly suitable especially for the beginners. On the negative side, interpreted programs can only run on the computers that have the respective interpreters.