Interpreter (computer)

From Citizendium
Revision as of 20:16, 24 March 2008 by imported>G. Del Merritt (add some links to existing text)
Jump to navigation Jump to search

Overview

In computer science, an interpreter is anything that turns one set of instructions into another set of instructions that are then immediately (or nearly immediately) executed. In the abstract, "instructions" can be anything. But to most computer scientists, an interpreter can be considered two "steps away" from getting code to run on a particular platform because the command (or instruction or statement) being interpreted must then be mapped to a machine instruction and then executed. Contrast an interpreter with a compiler.

An interpreter is itself a computer program that runs in a loop of:

  1. get a statement
  2. convert the statement into something that can "execute"
  3. execute the statement
  4. go back to #1 and start all over again

Example

An analogy from outside computer science is the homologous "interpreter" of human languages. If Al can only speak in English, and Frank can speak in English or French, and Gretchen can only speak French or German, then Al can only communicate verbally with Gretchen by using Frank as his interpreter. (In this example, Gretchen can can also use Frank communicate back to Al, which, while interesting, is currently less commonly considered as a function of being an interpreter in the computer science domain.) Taken a step further, Al can call Frank and order a product. Frank, in turn, can call Gretchen in order to get the order fulfilled. Notice that there is (usually) an immediacy of translation in the act of interpretation. Contrast this with, for instance, the translation of a book from one language into another.

A more specific example within computer science is the popular Perl language. Perl is itself a program implemented in the C programming language; C is a compiled language. Perl, however, has a set of commands (or statements or instructions or operators) that it "understands" and allows programmers to use. The Perl interpreter will take statements in its language and cause them to be run (or "executed") on the user's system "on the fly". Contrast this with a compiler, which also takes a set of commands but instead generates "object" code that cannot itself be immediately run on the user's system without additional processing.

Deeper look

It is in fact the case that the line between an "interpreter" and a "compiler" can be a bit blurry. An example of this is the Java language. Java statements - which are reminiscent of the C and C++ languages in form - are first compiled into "byte-code". This byte-code is a compact equivalent of the original source. The byte code can then be interpreted by the Java run-time environment and run on the target platform/system. Another blurring of the line is typical of embedded systems, wherein a very complex device - e.g., a printer or a mouse - has one or more interpreters that allow it to communicate with other systems or peripherals.


The ultimate interpreter in a system is the hardware that executes "machine code".

Popular Interpreters

There are many interpreted computer languages. Some may also support being compiled. As noted above, sometimes the line is difficult to draw.

Some common and popular interpreters are:

  • Perl
  • Python
  • Basic (also commonly compilable)
  • Java's byte-code interpreter
  • Javascript
  • The non-GUI command line processor of a "terminal", e.g., bash, sh, csh, tcsh, ksh, (all popular Unix/Linux command shells) and Microsoft's command.exe, which is sometimes called "the DOS prompt"
  • The command interface - GUI or text-based - to databases, e.g., SQL