简体   繁体   English

可以用该语言编写第二种编程语言实现吗?

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

This question is just something that I have been thinking about lately. 这个问题只是我最近一直在思考的问题。 Can a programming language be written in that language as a second implementation? 可以将编程语言用第二种实现语言编写吗? eg Java. 例如Java。 Is it possible to rewrite the java programming language using the java programming language? 是否可以使用Java编程语言来重写Java编程语言?

Apologies if this is a silly question but I need to know! 抱歉,这是一个愚蠢的问题,但我需要知道!

GF 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 . 查看BootStrapping

Yes for any Turing Complete language. 是的,适用于任何图灵完整的语言。 Lisp comes to mind as one of the easiest languages to write an interpreter/compiler for itself. Lisp是最容易为自己编写解释器/编译器的语言之一。

It can. 它可以。 A recent example is that python has pypy . 最近的例子是python有pypy A little more information is on the Wikipedia page and some good links. 有关更多信息,请参见Wikipedia页面和一些良好的链接。

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. 许多年前,我的第一台家用计算机之一Vic 20带有内置的BASIC解释器,仅此而已。 So I wrote the first version of an assembler for it in BASIC. 所以我用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: 有许多实用的示例,其中一个示例是Oberon语言,在本次讨论中很感兴趣,因为编译器代码可读性很强,可以在Project Oberon一书中免费获得:

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

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

The GCC compilers are written in C. GCC编译器是用C编写的。

It has been a long time since anyone built any C compilers from assembly. 自从有人用汇编程序构建任何C编译器以来已有很长时间了。

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 . 很好的入门指南是Andrew Appel的论文Axiomatic Bootstrapping:A 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. ecj(Eclipse的编译器)就是一个例子,我认为SDK本身带有纯Java编译器,尽管对此我可能是错的。

write a java compiler in java - no problem at all. 用Java编写Java编译器-完全没有问题。 actually I think Sun's javac is written in java. 实际上,我认为Sun的javac是用Java编写的。

however, 'java' usually means more things than just the javac, so your question isn't very clear. 但是,“ java”通常意味着的不仅仅是Javac,因此您的问题不是很清楚。

Sure. 当然。 I've even seen someone write a COBOL compiler written in COBOL! 我什至看到有人用COBOL编写了一个COBOL编译器! (OK, not a full compiler ... but at least a parser.) (好的,不是完整的编译器……至少是解析器。)

查看3-LISP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM