Numiton

NOTE: To use the advanced features of this site you need javascript turned on.

Home Knowledge Base Software Translation Interpreted Execution

Interpreted Execution

Working in an interactive environment implies a continuous communication between user and computer. Information exchange may be done in various ways, but it usually consists of simple operations. In situations when communication is complex it is more efficient to use commands in conjunction with an interpreted programming language.

Interpreted programming languages are executed as soon as their syntactic and semantic analysis is completed. Due to this feature they allow a conversational work style.

An example of a situation where an interpreted language is the ideal solution is the field of statistics and economic modeling. Complex operations are defined, for example reading series of data, estimating coefficients according to linear regression, correlation analysis, quality analysis of the estimated coefficients, component analysis, charting of registered values and estimated values. Procedures are written for all these operations. A language is thus created, describing procedures with general constructs that allow multiple combinations. Each statistic or modeling problem will be solved by writing programs in the respective language.

Let's consider the extended language Lex and let's assume that there is a specific procedure used for each instruction of this language. The interpreter takes as input program sequences written in Lex language, one by one, and resorts to the appropriate procedure.

For example, working with complex numbers in an interactive environment where an interpreter is used consists of entering instructions into the command line. In order to realize the calculus a library specialized in complex numbers is used. This library offers subprograms for operations with complex numbers: addition, subtraction, multiplying, etc.

There are several mechanisms for developing and running programs written in interpreted languages:

  • inserting and executing commands in an interactive environment,

  • interpreted execution of a program as source text,

  • inserting interpreted code into compiled programs.

For inserting and executing commands in an interactive environment a command line is sufficient. Each instruction is analyzed syntactically and semantically. Any resulting errors are signaled by the environment. In case of successful analysis the next step is executing the instruction, by using the system library and specialized libraries. Execution errors are signaled by the environment. If the execution is successful, control is returned to the interactive environment.

In the case of interpreted execution of a program, the source text is executed one instruction at a time, as shown in the figure below. The interpreter separates individual instructions from the source program, based on the grammar of the input language. The interpreter then analyzes and executes each instruction. When an analysis or runtime error is reported, program execution usually ends.

 

An increasingly widespread usage scenario for interpreters is including interpreted code within compiled programs. In this case, the program compiled in a low-level executable language uses the instructions interpreter. The interpreted code is included as strings of characters. The main reason for this technique is that the string containing the interpreted code is built in a dynamic way by the compiled program. In the case of a Java™ program, for example there could be interpreting of JavaScript, Groovy and others by using the Bean Scripting Framework interpreter from Apache, applying Xpath expressions on XML files by using the API JAXP or interpreting Java™ source code itself using Beanshell.

Advantages of interpreted execution:

  • immediate execution – instructions inserted into an interactive environment are executed instantaneously and the desired results are obtained in a minimum amount of time;

  • easily carrying out one-time-only operations;

  • instructions' simplicity – interpreted languages have a simple syntax.

There are many situations when interpreting is not the best solution. These cases are emphasized by the disadvantages of interpreted execution:

  • reporting analysis errors during the execution of the source program,

  • minimal type analysis,

  • low execution speed,

  • high memory usage.

During interpreted execution, any syntactic or semantic errors are signaled when the erroneous instruction is run. As a result, an interpreted program may contain erroneous instructions that are only executed on certain flows, that will be missed during testing and will only show up for end-users. Testing of an interpreted program is done by knowing the source code structure and implies exploring all possible execution paths.

Interpreted languages have few restrictions on data types. For most interpreters, any data type is seen as a string of characters and type conversions are made when circumstances require it. When the number of variables increases, so does the probability to misuse the declared variables and to generate execution errors. For example, a variable containing a street name written as a string of characters is used unintentionally in a multiplying operation, which makes no sense, and thus an execution error appears. Or worse, the conversion is executed silently and the error is never detected.

An interpreted program runs much slower than native code. Analysis for each instruction is done during the execution. This effect is amplified when the language contains loops and the interpreter is not optimized, because for each iteration each instruction is re-analyzed.

When the interpreted program is executed, the memory contains the program to be executed, the data used by it and the interpreter itself. Also, character strings used as data storage is one of the most inefficient ways to use memory. That is why it is necessary to have a considerably larger RAM memory for the interpreted execution of a certain program, compared to the resources required to execute an equivalent compiled program.

Due to these disadvantages, interpreted execution is only recommended for:

  • an interactive environment with simple processing, that would not use large amounts of data;

  • interpreted execution of a small volume of source code, when it increases development productivity without sacrificing maintenance.