Interpreter-based Systems
Note
In some software systems, users can write scripts, macros, or rules that access and compose the basic features of the system in new ways.
For example, users can write formulas in Microsoft Excel. A component known as an interpreter is built into the system that allows Excel to carry out the calculation in the formula “at run time”. The interpreter “interprets” the formula into an intermediate representation and “executes” the representation. The end user does not need to know about the underlying implementation of the function. Systems use interpreters to drive programmable actions specified by the user.
Interpreter-based systems allow end users to write scripts, macros, or rules that access, compose, and run the basic features of those systems in new and dynamic ways. It provides users with flexible and portable functionality that can be applicable in a variety of commercial systems.
Interpreters can run scripts and macros. Scripts are often used for automating common tasks, such as scheduling tasks, performing repetitive actions, and composing complex tasks that invoke other commands. Macros are an evolution of scripts that became popular with the introduction of Graphical user interfaces. A macro records keyboard and mouse inputs, so they may be executed later.
With an interpreter, end users can add functionality to a system and extend existing functionality of a system, by composing pre-existing functions together in a specific sequence, in order to create something new. These pre-existing functions are defined by the system architecture and offered to the user. The developer does not need to implement all possible combinations of functionality.
Interpreter-based systems encourage end users to implement their own customizations. This is further supported by systems that offer an easier-to-use language with domain-specific abstractions suited to the needs and thinking of the end users. End users do not have to know the programming languages used in developing the software in order to customize the system for their needs.
Interpreter-based systems offer certain advantages. In particular, interpreters make systems more portable, so they can work on platforms that the interpreter supports. This is an important feature with the growth of virtual machines and virtual environments, more and more services are being hosted in the cloud.
However, interpreter-based systems also offer certain disadvantages. Interpreters can be slow. Basic implementations spend little time analyzing the source code and use a line-by-line translate and execute strategy. This is a trade-off: it may be faster and more flexible for developers and end users to use an interpreted language, but slower for computers to execute interpreted code.
Java also uses interpreters!
In Java, programs are first translated into an intermediate language that is loaded into a Java Virtual Machine (JVM), which executes the intermediate language. The JVM will attempt to optimize the intermediate instructions by monitoring the frequency at which instructions are executed. The instructions that are executed frequently get translated into machine code and executed immediately.
On the next execution of the same intermediate instructions, the JVM uses lazy linking to point the program to the previous machine code translation. Instructions that are not used frequently are left for the interpreter of the JVM to execute.
This decreases execution time since frequently used instructions do not need to be constantly translated and the entire program does not need to be translated all at once. The JVM also provides portability to Java programs, allowing them to run on many operating environments.