An interpreter is a computer program that directly executes instructions written in a programming or scripting language, without requiring them previously to have been compiled into a machine language program). It generally uses one of the following strategies for program execution:
- Parse the source code and perform its behavior directly;
- Translate source code into some efficient intermediate representation or object code and immediately execute that.
Interpreters were used as early as 1952 to ease programming within the limitations of computers at the time, such as a shortage of program storage space, or no native support for floating-point numbers). They were also used to translate between low-level machine languages, allowing code to be written for machines that were still under construction and tested on computers that already existed). The first interpreted high-level language was Lisp).
An interpreter usually consists of a set of known commands it can execute, and a list of these commands in the order a programmer wishes to execute them. Each command (also known as an Instruction) contains the data the programmer wants to mutate, and information on how to mutate the data). For example, an interpreter might read "ADD Books, 5" and interpret it as a request to add five to the Books variable).
The main difference between an interpreter and a compiler is that a compiler takes entire program and converts it into object code which is typically stored in a file, while an interpreter directly executes instructions written in a programming or scripting language without previously converting them to an object code or machine code. Interpreted programs run slower than compiled programs, but interpreters are useful for debugging because they allow the programmer to find out the errors and to correct them before the control moves to the next statement.