Interpreter

From LQWiki
(Redirected from Interpreters)
Jump to navigation Jump to search

An interpreter is a program that executes either source code or bytecode by converting each instruction into machine code and then executing it immediately, in contrast to a compiler which converts the entire source program into machine code before any of it is executed.

Some languages are interpreted by default, and no compilers currently exist to compile the language, for example perl, Python and tcl. Interpreted languages are often known as scripting languages, and their programs as scripts, although an interpreted language like Perl is vastly more powerful than the shell scripts provided by bash or sh. The line between interpreted languages and high level languages is often blurry. The difference between a HLL and an interpreted language lies in how the code is used, not the code itself.

The advantages of an interpreted language include:

  • No compilation overhead - changes in the source code are reflected as soon as the interpreter is called to execute the program.
  • Portability - a program written in an interpreted language can be run on any machine that has an interpreter available, rather than compiled machine code which is platform-specific.
  • Source code available - a program in an interpreted language is distributed in source form, there is no binary form available for closed-source distribution.

However interpreted languages do suffer a considerable performance penalty due to the need for real-time conversion into machine code, and the tendency to execute a small part of the program repeatedly but interpret it anew each time. A just-in-time compiler attempts to reduce this problem by compiling the source code into machine code once and retaining this binary in memory.