Self-interpreter

Self-interpreter

A self-interpreter, or metainterpreter, is a programming language interpreter written in the language it interprets. An example would be a BASIC interpreter written in BASIC. Conceptually, self-interpreters are closely related to self-hosting compilers.

This may sound paradoxical; how can one implement a language in that language if it doesn't yet exist? However there is little mystery here. Self-interpreters are always "mocked up" in some other existing language and then later converted to the language they interpret. In these cases the early mockups can be used to develop the source code of the interpreter. Once the system is bootstrapped new versions of the interpreter can be developed in the language itself.

A definition of a computer language is usually made in relation to an abstract machine (so-called operational semantics) or as a mathematical function (denotational semantics). A language can also be defined by an interpreter, whereby the semantics of the language in which the interpreter is defined is usually considered as given. The definition of a language by a self-interpreter is not well-founded (i.e., cannot be used to define a language), but a self-interpreter tells a reader a lot about the expressiveness and elegance of a language. It also enables the interpreter to interpret its own source code, the first step towards a reflective interpreter.

There is an important design dimension in the implementation of a self-interpreter, namely whether a language feature in the interpreted language is implemented by using the same feature in the implementation language of the interpreter (the host language). A typical example is whether a closure in a Lisp-like language is implemented using closures in the interpreter language or implemented "manually" using a data structure that stores the environment explicitly. The more features are implemented by the same feature in the interpreter language, the less control the programmer of the interpreter has. For example, a different behavior for dealing with number overflows cannot be realized if the arithmetic operations are just delegated to the corresponding operations in the host language.

There are some languages that have a particularly nice and elegant self-interpreter, such as Lisp or Prolog. Much research on self-interpreters, in particular reflective interpreters, has been conducted in the context of the Scheme programming language, a dialect of Lisp. In general, however, any Turing-complete language allows the writing of its own interpreter.

Clive Gifford introduced a measure quality of self-interpreter - eigenratio. Eigenratio is a ratio between computer time spent to run a stack of N self-interpreters and time spent to run a stack of N-1 self-interpreters, when N goes to infinity. This value does not depend on top-level program being run.

The book Structure and Interpretation of Computer Programs presents a set of interesting examples of meta-circular interpretation for the Scheme programming language and variants thereof.

See also

External links


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать реферат

Look at other dictionaries:

  • Self-hosting — The term: Self hosting was coined to refer to the use of a computer program as part of the toolchain or operating system that produces new versions of that same program mdash;for example, a compiler that can compile its own source code. Self… …   Wikipedia

  • Interpreter of Maladies —   Cover of paperback edition …   Wikipedia

  • Self-modifying code — In computer science, self modifying code is code that alters its own instructions, intentionally or otherwise, while it is executing.Self modifying code is quite straightforward to write when using assembly language (taking into account the CPU… …   Wikipedia

  • Interpreter (computing) — In computer science, an interpreter normally means a computer program that executes, i.e. performs, instructions written in a programming language. An interpreter may be a program that either executes the source code directly translates source… …   Wikipedia

  • Self-organizing map — Carte auto adaptative Carte auto adaptative ou auto organisatrice est une classe de réseau de neurones artificiels fondée sur des méthodes d apprentissage non supervisée. On la désigne souvent par le terme anglais self organizing map (SOM), on… …   Wikipédia en Français

  • Self-induction — Induction électromagnétique Pour les articles homonymes, voir Induction. Chauffage par induction par un solénoïde …   Wikipédia en Français

  • Indirect self-reference — describes an object referring to itself indirectly .For example, define the function f such that f(x) = x(x) . Any function passed as an argument to f is invoked with itself as an argument, and thus in any use of that argument is indirectly… …   Wikipedia

  • Bootstrapping (compilers) — This article is about bootstrapping compilers. For the general concept, see Bootstrapping. In computer science, bootstrapping is the process of writing a compiler (or assembler) in the target programming language which it is intended to compile.… …   Wikipedia

  • PyPy — Infobox Software name = PyPy caption = developer = programming language = Python latest release version = 1.0 latest release date = March 27, 2007 operating system = Cross platform genre = Python interpreter and compiler toolchain license = MIT… …   Wikipedia

  • Meta-circular evaluator — A meta circular evaluator is a special case of a self interpreter in which the existing facilities of the parent interpreter are directly applied to the source code being interpreted, without any need for additional implementation. Meta circular… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”