Search This Blog

Wednesday, 5 November 2014

Interpreter

An interpreter is a program that analyzes (parses) program-ming commands or statements in a high-level language (see programming languages), creates equivalent executable instructions in machine code (see assembler) and executes them. An interpreter differs from a compiler in that the lat-ter converts the entire program to an executable file rather than processing and executing it a statement at a time (see compiler).

Many earlier versions of the BASIC programming lan-guage were implemented as interpreters. Since an inter-preter only has to hold one program statement at a time in memory, it could run on early microcomputers that had only a few tens of thousands of bytes of system memory. How-ever, interpreters run programs considerably more slowly than a compiled program would run. One reason is that an interpreter “throws away” each source code statement after it interprets it. This means that if a statement runs repeat-edly (see loop), it must be re-interpreted each time it runs. A compiler, on the other hand, would create only one set of machine code instructions for the loop and then move on. Also, because a compiler keeps the entire program in memory, it can analyze the relationship between multiple statements and recognize ways to rearrange or substitute them for greater efficiency.

Interpretation can also be used to bridge differences in hardware platforms. For example, in the UCSD Pascal system developed in the 1970s, an interpreter first trans-lates the Pascal source code into a standardized “P-code” (pseudocode) for a generic processor called a P-machine. To run the program on a particular actual machine, a second interpreter translates the P-code into specific executable machine instructions for that machine. Today Java uses a similar idea. A Java programming system translates source code into an intermediate “bytecode,” which is interpreted by a Java Virtual Machine, usually running with a Web browser.

In practice, with today’s high-speed computers and graphical operating environments, interpretative and com-pilation functions are often seamlessly integrated into a programming environment where code is checked for syn-tax as it is entered, incrementally compiled (such that only changed code is recompiled), and the programmer receives the same kind of rapid feedback that was the hallmark of the early BASIC interpreters (see programming environ-ment). Purely interpretive systems survive mainly in the form of text command processors for operating systems (see shell).

No comments:

Post a Comment