Ads Area

Interpreter and Compiler

Let's introduce at this point some concepts of execution of programs written in high level programming languages. As we have already seen, the only language that a computer can understand is the so called machine language. These languages are composed of a set of basic operations whose execution is implemented in the hardware of the processor. We have also seen that high level programming languages provide a machine-independent level of abstraction that is higher than the machine language. Therefore, they are more adapted to a human-machine interaction. But this also implies that there is a sort of translator between the high level programming language and the machine languages. There exists two sorts of translators:

An Interpreter is a program that implements or simulates a virtual machine using the base set of instructions of a programming language as its machine language.
You can also think of an Interpreter as a program that implements a library containing the implementation of the basic instruction set of a programming language in machine language.
An Interpreter reads the statements of a program, analyzes them and then executes them on the virtual machine by calling the corresponding instructions of the library.
Interactive interpreter session
During an interactive interpreter session the statements are not only read, analyzed and executed but the result of the evaluation of an expression is alsoprinted. This is also called a READ - EVAL - PRINT loop.

Pay attention, the READ - EVAL - PRINT loop is only entered in an interactive session. If you ask the interpreter to execute code in a file, results of expression evaluations are not printed. You have to do this by yourself.
Compiler is a program that translates code of a programming language in machine code, also called object code. The object code can be executed directly on the machine where it was compiled.

Figure 5.1. Comparison of compiled and interpreted code
So using a compiler separates translation and execution of a program. In contrast of an interpreted program the source code is translated only once.
The object code is machine-dependent meaning that the compiled program can only be executed on a machine for which it has been compiled, whereas aninterpreted program is not machine-dependent because the machine-dependent part is in the interpreter itself.

Post a Comment

* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Top Post Ad