Interpreters

Lecture



One, often cited advantage of the interpreter implementation is that it allows for "immediate mode". Immediate mode allows you to set a task like PRINT 3.14159 * 3 / 2.1 to your computer and returns the answer to you as soon as you press the ENTER key (this allows you to use a computer costing $ 3000 as a calculator worth $ 10). In addition, interpreters have special attributes that simplify debugging. You can, for example, interrupt the processing of an interpreter program, display the contents of certain variables, skim the program, and then continue execution.

Most of all, programmers like interpreters to get a quick response. There is no need for compiling, as the interpreter is always ready to interfere with your program. Enter RUN and the result of your most recent change appears on the screen.

However, interpretive languages ​​have disadvantages. It is necessary, for example, to have a copy of the interpreter in memory all the time, whereas many possibilities of the interpreter, and therefore its capabilities, may not be necessary for the execution of a particular program.

A weakly discernible disadvantage of interpreters is that they tend to discourage a good programming style. Since comments and other formalized details occupy a significant place of program memory, people tend not to use them. The devil is less violent than a programmer working on interpretive BASIC, trying to get a 120K program in a 60K memory. but worst of all, the interpreters are slow. They spend too much time trying to figure out what to do, instead of actually doing business.

When executing software operators, the interpreter must first scan each operator in order to read its contents (what does this person ask me to do?), And then perform the requested operation. Operators in cycles are scanned too much.

Consider the program: on interpretive BASIC

  10 FOR N = 1 TO 1000 
 20 PRINT N, SQR (N)
 30 NEXT N

When you first switch to this program, the Basic Interpreter should unravel what line 20 means:

1. convert a numeric variable N to a string

2. send a string to the screen

3. Move to the next print area.

4. calculate the square root of N

5. Convert the result to a string

6. send a string to the screen

During the second pass of the cycle, all this guessing is repeated again, since all the results of studying this line are completely forgotten a millisecond ago. And so in all the next 998 passes. Obviously, if you somehow managed to separate the scan / understanding phase from the execution phase, you would have a faster program. And this is exactly what compilers are for.

created: 2014-09-30
updated: 2021-03-13
132485



Rating 9 of 10. count vote: 2
Are you satisfied?:



Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Programming Languages and Methods / Translation Theory

Terms: Programming Languages and Methods / Translation Theory