构建您自己的可以充当编译器的解释器

发布于 2024-08-29 01:03:49 字数 43 浏览 10 评论 0原文

我可以构建自己的解释器,然后将其转换为编译器吗?如果是,我该如何构建它?

It is possible for me to build my own Interpreter that could then be transformed into a compiler? If yes, how do I go about building it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

故人如初 2024-09-05 01:03:49

这被称为第二次二村投影。它首先由 Prof. 描述。 Yoshihiko Futamura 在他 1971 年的论文 计算过程的部分评估 - 编译器-编译器的方法(日语)英文版 28 年后重新发布。

它使用部分求值,通过相对于解释器部分求值部分求值器本身,从而产生编译器。

因此,您需要两个要素:目标语言的解释器,用某种宿主语言(可能与目标语言相同或不同)编写,以及能够评估解释器及其本身的部分评估器,换句话说,它需要部分评估宿主语言,并且它本身需要用它可以评估的宿主语言编写。

This is called the Second Futamura Projection. It was first described by Prof. Yoshihiko Futamura in his 1971 paper Partial Evaluation of Computation Process – An approach to a Compiler-Compiler (Japanese), an English version of which was republished 28 years later.

It uses Partial Evaluation, by partially evaluating the partial evaluator itself with respect to the interpreter, thus yielding a compiler.

So, you need two ingredients: an interpreter for your target language, written in some host language (which may or may not be the same as the target language) and a partial evaluator capable of evaluating both the interpreter and itself, in other words it needs to partially evaluate the host language and it needs to itself be written in the host language it can evaluate.

赴月观长安 2024-09-05 01:03:49

已经提到的部分评估是可能的方法之一(一种计算量非常大的方法,但另一方面却相当通用)。另一种方法是元编程:如果一种语言的解释器以针对另一种解释语言的简单翻译器的形式实现,那么以后很容易将其重新定位到某种编译语言,或者用编译器替换目标解释器。

An already mentioned partial evaluation is one of the possible methods (a very computationally intensive one, but quite generic on the other hand). Another approach is metaprogramming: if an interpreter of a language is implemented in a form of a simple translator which targets another interpreted language, it is very easy to re-target it later to some compiled language, or replace the target interpreter with a compiler.

明月夜 2024-09-05 01:03:49

除了 Futaruma 投影之外,另一种方法是元跟踪 jit。元跟踪 jit 不会直接跟踪或 jit 您的程序,而是通过解释器间接跟踪或 jit。
RPython 是一个很酷的元跟踪框架。你用Python的受限版本编写一个解释器,RPython将它变成C语言的jit编译器。

Apart from Futaruma projections, another approach is meta-tracing jit. Meta-tracing jit doesn't directly trace or jit your programs, but indirectly, through the interpreter.
RPython is a cool meta-tracing framework. You write an interpreter in a restricted version of python, and RPython turns it into a jit compiler in C.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文