Interpreter (computer)
Overview
In computer science, an interpreter is anything that turns one set of instructions into another set of instructions. In the abstract, "instructions" can be nearly anything. But to most computer scientists, an interpreter can be considered two "steps away" from getting code to run on a particular platform.
Somewhat more formally, an interpreter is itself a computer program that runs in a loop of:
- get a statement
- convert the statement into something that can "execute"
- execute the statement
- 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.
A more specific example within computer science is the popular Perl language. Perl is itself a program implemented in the C computer 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
- The non-GUI command line processor of a "terminal", e.g., bash, sh, csh, tcsh, ksh, (all popular Unix/Linix 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