Jump to content

Interpreted language: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Zron (talk | contribs)
Add language, which is interpreted or compiled
Line 46: Line 46:
*[[Game Maker Language]]
*[[Game Maker Language]]
*[[Lava (programming language)|Lava]]
*[[Lava (programming language)|Lava]]
*[[Madness Script]]
*Madness Script
*[[Perl]]
*[[Perl]]
*[[PHP]]
*[[PHP]]

Revision as of 19:39, 30 July 2012

Interpreted language is a programming language in which programs are 'indirectly' executed ("interpreted") by an interpreter program. This can be contrasted with a compiled language which is converted into machine code and then 'directly' executed by the host CPU. Theoretically, any language may be compiled or interpreted, so this designation is applied purely because of common implementation practice and not some essential property of a language. Indeed, for some programming languages, there is little performance difference between an interpretive- or compiled-based approach to their implementation.

Many languages have been implemented using both compilers and interpreters, including BASIC, C, Lisp, Pascal, and Python. While Java is translated to a form that is intended to be interpreted, just-in-time compilation is often used to generate machine code. The Microsoft .NET Framework languages always compile to Common Intermediate Language (CIL) which is then just-in-time compiled into native machine code. Many Lisp implementations can freely mix interpreted and compiled code. These implementations also use a compiler that can translate arbitrary source code at runtime to machine code.

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.

List of frequently interpreted languages

Languages usually compiled to a virtual machine code

Many interpreted languages are first compiled to some form of virtual machine code, which is then either interpreted or compiled at runtime to native code.

See also

References