Interpreted language: Difference between revisions
Lemmon Juice (talk | contribs) |
|||
Line 86: | Line 86: | ||
*[[Lua (programming language)|Lua]] |
*[[Lua (programming language)|Lua]] |
||
*[[.NET Framework]] languages (translated to [[Common Intermediate Language|CIL]] code) |
*[[.NET Framework]] languages (translated to [[Common Intermediate Language|CIL]] code) |
||
**[[C++/CLI|C++/CLI]] |
|||
**[[C Sharp (programming language)|C#]] |
**[[C Sharp (programming language)|C#]] |
||
**[[Visual Basic .NET]] |
**[[Visual Basic .NET]] |
Revision as of 14:31, 23 August 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:
- Java
- Python
- Ruby (similarly, it uses an abstract syntax tree as intermediate representation)
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
- APL A vector oriented language using an unusual character set
- J An APL variant in which tacit definition provides some of the benefits of compiling
- ASP Web page scripting language
- BASIC (although the original version, Dartmouth BASIC, was compiled, as are many modern BASICs)
- ECMAScript
- ActionScript (version 3.0 is not interpreted, that's why eval() function was removed)
- E4X
- JavaScript (first named Mocha, then LiveScript)
- JScript
- Equation manipulation and solving systems
- Euphoria Interpreted or compiled.
- Forth (traditionally threaded interpreted)
- Game Maker Language
- Lava
- Madness Script
- Perl
- PHP
- PostScript
- Python
- Lisp
- MUMPS (traditionally interpreted, modern versions compiled)
- REXX
- Ruby
- JRuby (A Java implementation of Ruby)
- Seed7 Interpreted or compiled.
- Smalltalk (pure object-orientation, originally from Xerox PARC, often supports debugging across machines.)
- Scripting languages
- Spreadsheets
- Excel stores formulas, interprets them from a tokenized format
- S
- Tcl
- XMLmosaic An xml contained C# like programming language interpreted by a console application written in Visual Basic .NET
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.
- Java (frequently translated to bytecode, but can also be compiled to a native binary using an AOT compiler)
- Lua
- .NET Framework languages (translated to CIL code)
- Pike
- Python
- Squeak Smalltalk
- Visual FoxPro
- Lisp