自举仍然需要外部支持 [英] Bootstrapping still requires outside support

查看:95
本文介绍了自举仍然需要外部支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说过引导语言的想法,即为语言本身编写编译器/解释器。我想知道如何做到这一点,环顾四周,看到有人说只能通过以下两种方式来做到这一点

I've heard of the idea of bootstrapping a language, that is, writing a compiler/interpreter for the language in itself. I was wondering how this could be accomplished and looked around a bit, and saw someone say that it could only be done by either


  • 写一个

  • 在Assembly中手动编码一个初始编译器,这似乎是第一个

在我看来,这两个语言实际上都不是 bootstrapping 语言,因为它们都需要外部支持。有没有办法用自己的语言实际编写编译器?

To me, neither of these seem to actually be bootstrapping a language in the sense that they both require outside support. Is there a way to actually write a compiler in its own language?

推荐答案


有没有办法实际使用自己的语言编写编译器?

Is there a way to actually write a compiler in its own language?

必须有一些现有的语言来编写您的如果要编写新的C ++编译器,则只需用C ++编写,然后首先使用现有的编译器进行编译。另一方面,如果您正在为一种新语言创建编译器,我们称其为Yazzleof,则需要首先使用另一种语言编写新的编译器。通常,这是另一种编程语言,但不是必须的。可以是汇编代码,也可以是机器代码。

You have to have some existing language to write your new compiler in. If you were writing a new, say, C++ compiler, you would just write it in C++ and compile it with an existing compiler first. On the other hand, if you were creating a compiler for a new language, let's call it Yazzleof, you would need to write the new compiler in another language first. Generally, this would be another programming language, but it doesn't have to be. It can be assembly, or if necessary, machine code.

如果为Yazzleof引导编译器,通常您不会最初为完整语言编写编译器。取而代之的是,您将为Yazzle-lite(Yazzleof的最小子集)编写一个编译器(至少,一个非常小的子集)。然后,在Yazzle-lite中,您将编写完整语言的编译器。 (显然,这可以迭代而不是一次跳转。)因为Yazzle-lite是Yazzleof的适当子集,所以您现在有了可以自行编译的编译器。

If you were going to bootstrap a compiler for Yazzleof, you generally wouldn't write a compiler for the full language initially. Instead you would write a compiler for Yazzle-lite, the smallest possible subset of the Yazzleof (well, a pretty small subset at least). Then in Yazzle-lite, you would write a compiler for the full language. (Obviously this can occur iteratively instead of in one jump.) Because Yazzle-lite is a proper subset of Yazzleof, you now have a compiler which can compile itself.

真的很好的一篇文章,介绍了如何从最低的级别引导编译器(在现代机器上基本上是十六进制编辑器),标题为从零开始引导简单的编译器。可以在 https:// web上找到。 archive.org/web/20061108010907/http://www.rano.org/bcompiler.html

There is a really good writeup about bootstrapping a compiler from the lowest possible level (which on a modern machine is basically a hex editor), titled Bootstrapping a simple compiler from nothing. It can be found at https://web.archive.org/web/20061108010907/http://www.rano.org/bcompiler.html.

这篇关于自举仍然需要外部支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆