引导语言 [英] Bootstrapping a language

查看:154
本文介绍了引导语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说过引导一种语言的想法,也就是为该语言编写一个编译器/解释器。我想知道如何实现这一点,并看看周围有一点,看到有人说,它只能通过

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



对我来说,这两者似乎都不是 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 it's own language?

推荐答案


有没有方法可以用自己的语言编写一个编译器?

Is there a way to actually write a compiler in it's 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天全站免登陆