Komputer    
   
Daftar Isi
(Sebelumnya) InterpolationInterruptible operating system (Berikutnya)

Interpreted language

An interpreted language is a programming language that avoids explicit program compilation. The interpreter executes the program source code directly, statement by statement, as a processor or scripting engine does. This can be contrasted with compiled language programs, which the user must explicitly translate into a lower-level machine language executable.

Interpreted languages can also be contrasted with machine languages. Functionally, both execution and interpretation mean the same thing — fetching the next instruction/statement from the program and executing it. Although interpreted bytecode is additionally identical to machine code in form and has an assembler representation, the term "interpreted" is practically reserved for "software processed" languages (by virtual machine or emulator) on top of the native (i.e. hardware) processor.

Theoretically, any language may be compiled or interpreted, emulated or executed natively, so this designation is applied solely based on common implementation practice, rather than representing an essential property of a language. Akin to processor microcoding, many interpreters internally rely on just-in-time compilation.

Avoiding compilation, interpreted programs are easier to evolve during both development and execution (where they can morph themselves). On the other hand, since compilation implies translation into more machine-friendly format, interpreted programs run slower and less efficiently (i.e. waste considerably more energy). This is especially true for higher-level scripting languages, whose statements are complex to analyze compared to machine instruction.

Many languages have been implemented using both compilers and interpreters, including BASIC, C, Lisp, Pascal, and Python. Java and C# are compiled into bytecode, the virtual machine-friendly interpreted language. Lisp implementations can freely mix interpreted and compiled code.

Contents

Historical background of interpreted/compiled

In the early days of computing, language design was heavily influenced by the decision to use compiling or interpreting as a mode of execution. For example, some compiled languages require that programs must explicitly state the data-type of a variable at the time it is declared or first used while some interpreted languages take advantage of the dynamic aspects of interpreting to make such declarations unnecessary. For example, Smalltalk (1980), which was designed to be interpreted at run-time, allows generic objects to dynamically interact with each other.

Initially, interpreted languages were compiled line-by-line; that is, each line was compiled as it was about to be executed, and if a loop or subroutine caused certain lines to be executed multiple times, they would be recompiled every time. This has become much less common. Most so-called interpreted languages use an intermediate representation, which combines compiling and interpreting. In this case, a compiler may output some form of bytecode or threaded code, which is then executed by a bytecode interpreter.

Examples include:

The intermediate representation can be compiled once and for all (as in Java), each time before execution (as in Perl or Ruby), or each time a change in the source is detected before execution (as in Python).

Advantages of interpreting a language

Interpreting a language gives implementations some additional flexibility over compiled implementations. Features that are often easier to implement in interpreters than in compilers include (but are not limited to):

  • platform independence (Java's byte code, for example)
  • reflection and reflective use of the evaluator (e.g. a first-order eval function)
  • dynamic typing
  • smaller executable program size (since implementations have flexibility to choose the instruction code)
  • dynamic scoping

Disadvantages of interpreted languages

The main disadvantage of interpreting is a much slower speed of program execution compared to direct machine code execution on the host CPU. A technique used to improve performance is just-in-time compilation which converts frequently executed sequences of interpreted instruction to host machine code.

Daftar/Tabel -- frequently used interpreted languages

Languages usually compiled to a bytecode

Many interpreted languages are first compiled to bytecode, which is normally interpreted by virtual machine exploiting some just-in-time compilation of bytecode to native code. However, sometimes, bytecode can also be compiled to a native binary using an AOT compiler) or executed natively, by hardware processor.

See also

References

(Sebelumnya) InterpolationInterruptible operating system (Berikutnya)