views:

209

answers:

5

Programming languages seem to go through several stages. Firstly, someone dreams up a new language, Foo Language. The compiler/interpreter is written in another language, usually C or some other low level language. At some point, FooL matures and grows, and eventually someone, somewhere will write a compiler and/or interpreter for FooL in FooL itself.

My question is this: What is the minimal subset of language features such that someone could implement that language in itself?

+6  A: 

Compiler can be written even using a Turing machine - a Universal Turing Machine is basically a compiler/interpreter of any Turing machine, so any Turing-complete language should be enough :)

Marek
+2  A: 

One option is a read-eval-print loop. This can be used to build many higher-level constructs. I believe this is the path taken by LISP.
I am unsure about the beginnings of C, but I think it started with a few system calls to implement branching, loops, assignment and single-character I/O, and built from there.

Yuval F
+4  A: 

In theory, surprisingly little. A computability theorist would say that all you need is mu-recursion or a Turing machine or the like.

However, from a practical point of view, you're not going to be very happy trying to implement a programming language in a Turing machine. I would say that, at a minimum, you would want to have all the usual control-flow constructs, the primitive datatypes, subroutines, as well as arrays and structs. That should be enough to let you implement that subset of the language in the language itself -- and you can then bootstrap yourself up from there.

Martin B
"In theory, there is no difference between theory and practice. In practice, there is." -- I forget who.
Matthew Scharley
A: 

Id assume a assembler would make the cut.

Recursion
A: 

My question is this: What is the minimal subset of language features such that someone could implement that language in itself?

There is no requirement for the language to be useful for anything other than compiling itself? I present to you Useless, the language in which every text is a proper program and means "a program that takes any input and produces itself" (this is also known as Useless compiler).

Rafał Dowgird
I like Jon Skeet's language better. But for the sake of argument, let's make sure that the language is useful as defined by at the very least being Turing-complere.
Matthew Scharley
That sure is a **`Useless`** programming language.
Brad Gilbert
@Brad: Yes, yes it is.@Matthew: Are you sure that Jon Skeet's language can compile itself?
Rafał Dowgird
@Rafal: You'd have to ask him; I'm pretty sure it does exactly what he wants, out of fear.
Matthew Scharley