脚本语言解释器源码可供学习

发布于 2024-12-10 04:19:17 字数 107 浏览 0 评论 0原文

我想阅读脚本语言解释器/编译器的源代码并从中学习。哪种脚本语言解释器/编译器具有最简单、最干净、最容易阅读的源代码?我更喜欢用 C/C++ 编写(编译器还用什么编写?),因为我计划用 C 编写编译器。

I want to read, and learn from, the source code of a scripting language's interpreter/compiler. What scripting language interpreter/compiler has the simplest, cleanest, and easiest to read source code? I would prefer it to be written in C/C++ (what else are compilers written in anyway?) because I'm planning on writing a compiler in C.

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

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

发布评论

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

评论(6

慕巷 2024-12-17 04:19:17

看一下 lua,您可以浏览该编程语言的第一个版本并了解它是如何演变的。它是用 C 语言编写的,代码干净漂亮。您可以用几乎所有编程语言编写编译器,但 C 是大多数程序员选择的语言。

Take a look at lua, you can go through the firsts versions of the programming language and see how it has evolved. It's written in C and has a clean and nice code. You can write a compiler in almost every programming language, but C has been the one that most programmers chose.

柒夜笙歌凉 2024-12-17 04:19:17

CPython 中断器已经存在相当长一段时间了,我想它对于你。

The CPython interrupter has been around for quite some time and I would imagine that it would be very useful to you.

℉絮湮 2024-12-17 04:19:17

AngelScript 是学习编译器的一个非常好的选择。这是一种具有 C/C++ 熟悉语法、垃圾收集、面向对象、继承和多态性、跨平台、编译为字节码的语言。

我的第二个选择是 Lua

AngelScript is a very good option for learning about compilers. This is a language with C/C++ familiar syntax, garbage collection, it is object-oriented with inheritance and polymorphism, cross-platform and compiles to byte-code.

My second choice would be Lua.

一腔孤↑勇 2024-12-17 04:19:17

作为温和的介绍,我建议您查看 LLVM 教程

Chris Lattner 创建了一种简单的玩具语言万花筒来显示编译的各个阶段:

然后,他演示了如何添加 JIT 功能(对于解释器至关重要)。

玩具语言非常简单,因此生成的代码也很简单,并且很好地演示了架构,而不会让您陷入实现细节之中。

我不确定该教程是否完全是最新的并且可以按最新的 LLVM 版本使用,但我建议至少阅读它。

(当然,还要阅读龙之书)。

I would recommend, as a gentle introduction, having a look at the LLVM Tutorial.

Chris Lattner creates a simple toy language Kaleidoscope to show the various phases of compilation:

He then demonstrates how to add JIT capabilities (essential for an interpreter).

The toy language is extremely simple, and thus the resulting code is simple as well, and demonstrates nicely the architecture without drowning you in implementation details.

I am not sure that the tutorial is fully up-to-date and can be used as is against a recent LLVM version, but I do advise at least reading it.

(And of course, reading the Dragon Book).

二智少女 2024-12-17 04:19:17

查看 JavaScript 的 V8。每个解释器都有一个称为 tokenizer 的组件。 GNU 有一个名字叫野牛(bison)的人。也来看看吧。这可能会有帮助。 Chromium 也使用一些 tokenizer 来解释 Webkit 上的 html,但 V8 是 javascript 解释器。

克劳迪奥·M·苏扎·儒尼奥尔

Take a look on V8 for JavaScript. Every interpeter has a component called tokenizer. GNU has one whose name is bison. Take on look on it too. It can be helpful. Chromium uses some tokenizer for interpreting html on the Webkit too, but V8 is the javascript interpreter.

Claudio M. Souza Junior

素食主义者 2024-12-17 04:19:17

一种著名的语言,但并不简单(PHP 源代码)。
您可以利用源代码。

PHP 源代码

a famous language, but not simple (PHP Source Code).
You can take advantage of the source code .

PHP Source Code

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