开发者

Can a second implementation of a programming language be written in that language?

This quest开发者_如何学Goion is just something that I have been thinking about lately. Can a programming language be written in that language as a second implementation? e.g. Java. Is it possible to rewrite the java programming language using the java programming language?

Apologies if this is a silly question but I need to know!

GF


Always. Any Turing-Complete language is -- well -- a Turing-Complete language. If you can write the compiler in one complete language, you can write it in any equivalent language.


Yes, it is possible. Check out BootStrapping.


Yes for any Turing Complete language. Lisp comes to mind as one of the easiest languages to write an interpreter/compiler for itself.


It can. A recent example is that python has pypy. A little more information is on the Wikipedia page and some good links.


Sure.

Many many years ago one of my first home computers, a Vic 20, came with a built-in BASIC interpreter but that was it. So I wrote the first version of an assembler for it in BASIC. Then I used my first primitive assembler to write a better assembler.


Yes. As long as the language is Turing Complete, you can implement the language in itself.


There are many practical examples of this, one example is the Oberon Language, which is of interest in this discussion because the compiler code is very readable it's in the book Project Oberon available for free:

http://www.oberon.ethz.ch/bibliography/publications

http://en.wikipedia.org/wiki/Bootstrapping_(compilers)


The GCC compilers are written in C.

It has been a long time since anyone built any C compilers from assembly.


Not just possible, but for native-code compilers, this is the most common implementation technique. A good how-to guide is Andrew Appel's paper Axiomatic Bootstrapping: A Guide for Compiler Hackers.


It not only can, it is. ecj (Eclipse's compiler) is one example, and I think the SDK itself comes with a pure Java compiler, though I could be wrong about that.


write a java compiler in java - no problem at all. actually I think Sun's javac is written in java.

however, 'java' usually means more things than just the javac, so your question isn't very clear.


Sure. I've even seen someone write a COBOL compiler written in COBOL! (OK, not a full compiler ... but at least a parser.)


Check out 3-LISP

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜