go to previous page   go to home page   go to next page hear noise highlighting

Answer:

Java. The time (and expense) of getting the program to run on other computers is avoided. (Actually, sometimes things do not work out as nicely as this.)


Interpreter

Interpreting a source program

Programs written in a high level language are never directly executed by the processor. You have already seen one way to execute such a program: use a translator to create a machine language program that can be executed directly.

Another way to execute a source program is to use an interpreter for the language. An interpreter is an executable program that runs directly on the processor. An interpreter reads through a source program written in a high level language and performs the actions that the source program asks for.

This is a fairly complicated thought. The figure might help.

In this figure, the source program program.bas has been written in BASIC (a programming language) by a programmer. It is being interpreted by the BASIC interpreter, which is an executable program running on the processor.

The BASIC interpreter works by reading in commands from the BASIC source program one by one. Each time it reads in a command, the interpreter does what the command asks. A BASIC command might ask to add two numbers together. That is fine. The BASIC interpreter is a program, and programs can easily add together two numbers. The BASIC program might then ask to write the sum to the monitor. Still fine. The BASIC interpreter can easily do that.

The BASIC interpreter uses the fundamental machine operations of the processor to perform the actions requested in the BASIC source program. But the source program itself is not translated into machine language.

This is like a cook who can perform basic cooking operations but can't read. How can the cook follow a recipe? The cook hires an assistant who knows how to read. The assistant reads the instructions of a recipe one by one to the cook, who performs them one by one as they are read.

You have probably done this many times without realizing it. It is exactly accurate (although an unusual use of the words) to say that the computer game Free Cell Solitaire (or any computer game) is an interpreter for the commands that you enter using the mouse and keyboard. The commands for the game Free Cell are not the usual commands used in a general-purpose programming language, but none the less, they are commands expressed in a formal language. You enter commands, and the interpreter (the game) executes them one by one. The set of commands and the rules for how to use them correctly form a programming language for the Free Cell interpreter.

In playing a computer game, you are writing a program that solves a problem. (Usually the problem is to get to the end of the game.) If you recorded every move you made, you would have a program that the game, acting as an interpreter, could run to solve the problem.

Some games have a "walk through" which tells you what to do to win the game. The "walk through" is a program, and if you follow it, you are an interpreter.

(Of course, each time you play solitaire, the problem is a randomly selected initial arrangement of cards, so you need a different program for each problem.)


QUESTION 13:

An interpreter runs directly on the processor. What type of instructions must an interpreter consist of?


go to previous page   go to home page   go to next page