Interpreter

Definition
The interpreter serves to execute a program in a domain-specific language. It parses the source code into a format that can be executed, then executes it.
Interpreter architecture diagram

How does it work?

One or more Programs or Scripts are loaded into the Interpreter. They may be converted into an internal representation that can be processed more effectively by the Interpreter. Connections between the Program and the Environment are created.

The Interpreter reads instructions from the Program and processes them. This affects the environment and the call stack. This cycle is executed until the Program is finished.

Examples

  • Java Virtual Machine
  • Rule-based systems
  • Scripting languages, i.e. JavaScript

When should you use it?

  • If you want the users of your application to be able to modify the behaviour of the application (scripting).
  • If the rules of your application need to be extended long after the application is finished.
  • If the Program may not directly access the Environment. The interpreter is a so called sandbox where the Program can play in without being able to do any harm.

Problems

  • Is slower than direct execution
  • Requires a custom made debugger
  • Requires the development and implementation of a feature-rich programming language

Common implementation techniques

  • The interpreter should not run in a separate thread from the environment, because it would create endless synchronisation issues. Emulate parallel processing in stead. Process only a few Program instructions every cycle.

Links