interpreter


What is an Interpreter?

An interpreter is an entity that assigns meaning to program expressions by a series of machine state transitions. An example of an interpreter is a machine processor. The input program is a sequence of instructions; the machine is defined by the transitions for each of the instructions. Such a state transition might be for a MOV t,s instruction, where the contents of the source register s would be moved to the target register t. Interpreters may also exist for higher-level languages, such as Scheme. As a common example, a Scheme interpreter based on a meta-circular evaluator, such as the one that SICP describes, fundamentally intertwines eval & apply: eval applied to a procedure call expression evaluates the operator of each operand of a function call and then uses apply to apply the operator procedure to each of the arguments; apply in turn interprets with eval the body of the lambda expression that the operator procedure referred to. More explicitly, the state transition for eval on procedure calls involves manipulating a program stack to evaluate the operator & each operand and then transiting to an apply state; the state transition for apply changes the expression to evaluate to be that of the procedure's lambda and the lexical environment of the state to be the one saved in the closure to apply.

See also evaluation for the relation between interpreters & compilers.


An interpreter is one type of program used to implement a language. The other type is called a compiler. The difference is that while a compiler creates executable code to be run (more quickly, if less conveniently) later. The interpreter just runs the code straight up, and any executable code is created on-the-fly, making it a lot simpler to test your programs, and a lot harder to hide the source code. Some language implementations (i.e. Python) use a hybrid system.

A more generic, technical definition of an interpreter is any kind of program (or system) that looks at data and decides what to do with it based on certain rules. A CPU interprets machine language instructions all the time, so really every language implementation is interpreted at some level. Furthermore, Scheme can be used to implement an "interpreter" of an even higher level, such as a simple meta-circular evaluation routine.

It could also be noted that most Schemes are interpreters implemented in a compiled language such as C, which is often itself implemented in another language or itself. It all goes back to machine code at some point...


category-learning-scheme