Interpreter (computer): Difference between revisions
imported>G. Del Merritt (Follow style guidelines a little more closely) |
imported>David E. Volk m (Interpreter moved to Interpreter (computer): not main sense of the word) |
(No difference)
|
Revision as of 11:55, 12 April 2008
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. Contrast an interpreter with a compiler.
Overview
To computer scientists, an interpreter is considered two "steps away" from getting code to run on a particular platform. In part, this is because the command (or instruction or statement) being interpreted must then be mapped to a machine instruction and then executed. This view is also a result of the fact that an interpreter is itself is a typically a computer program that runs in a loop of the form:
- get a statement
- convert the statement into something that can "execute"
- execute the statement
- go back to #1 and start all over again
An interpreter, however, can also be part of the larger whole of a computer program or software system. The key quality of an interpreter is its immediacy of action, as is described in the following example.
Example
An analogy from outside computer science is the homologous "interpreter" of human languages. If Ed can only speak in English, and Frank can speak in English or French, and Gretchen can only speak French or German, then Ed can only communicate verbally with Gretchen by using Frank as his interpreter. (In real life, Gretchen can can also use Frank to communicate back to Ed, which, while interesting, is currently less commonly considered a function of an interpreter in the computer science domain.) The role of an interpreter during a speech at the United Nations comes to mind. 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, or the compilation of a number of sources into a thesis or other research article.
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