Compiler and interpreter both are tools to translate source code from high-level language to machine language. Both does the same task of translation. But the working mechanism of compiler is different from interpreter. Below are some differences between compilers and interpreters
Compiler reads entire source code and translates to machine language at once. If any error is generated during compilation, it terminates the entire process without executing single instruction.
Whereas interpreters translate instruction-by-instruction. It reads single instruction at a time. Translates it to machine language and executes it. This process continues till the last instruction. If any error is generated during the interpretation, it terminates the execution of further instructions.
Compilers reads entire source code at once. It pre-processes, parses, analyses the source code and translates it to machine code at once. Hence, it requires more translation time than interpreters.
Interpreters reads single instruction of source code at a time. Unlike compilers, it doesn’t translate entire source code to machine code at once. Rather it translates the source code, instruction by instruction. Hence, requires less translation time.
Compilers translate entire source code at once. After the compilation process, it generates an executable file containing complete instruction set of the program in binary language. Hence, it doesn’t require any further translation which enhances the program execution speed.
Interpreters translate the source code instruction by instruction. It translates single instruction then executes it. Each time before executing an instruction, it must first translate it to machine language. Which increases the overhead of interpretation, hence decreases the program execution speed.
Compilers usually generate an intermediate code called object code, during the compilation process. Hence it requires more memory than interpreters.
Unlike compilers, interpreters do not generate any intermediate code, during the interpretation process. Thus, interpreters are memory efficient.
Compilers continues to process entire source code also if it contains errors. It generates list of all error messages (if any) at the end of the compilation process. Which makes debugging a little difficult.
Interpreters stops the interpretation process if an error is encountered. It generates the error message as the error is met during the interpretation process.
Compilers generate an executable file of the source code. This executable file is deployed instead of source code. Which increases the security, by hiding the source code from others.
Interpreters do not generate any executable file of the source code. Therefore, in the case of interpreter’s entire source code needs to be deployed. Causing a security concern as the source code is visible to everyone.
0 Comments: