脚本语言解释器源代码来学习

时间:2021-07-17 17:05:47

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.

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

6 个解决方案

#1


11  

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.

看看lua,您可以浏览编程语言的第一版,看看它是如何演变的。它是用C语言编写的,代码简洁明了。您可以在几乎所有编程语言中编写编译器,但C是大多数程序员选择的编译器。

#2


6  

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

CPython中断器已经存在很长时间了,我想这对你来说非常有用。

#3


4  

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.

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

My second choice would be Lua.

我的第二选择是Lua。

#4


4  

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

作为一个温和的介绍,我建议你看一下LLVM教程。

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

Chris Lattner创建了一个简单的玩具语言Kaleidoscope来展示编译的各个阶段:

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

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

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.

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

(And of course, reading the Dragon Book).

(当然,阅读龙书)。

#5


2  

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.

看一下V8 for JavaScript。每个interpeter都有一个名为tokenizer的组件。 GNU有一个名字叫野牛。继续看看吧。它可能会有所帮助。 Chromium也使用一些tokenizer来解释Webkit上的html,但是V8是javascript解释器。

Claudio M. Souza Junior

Claudio M. Souza Junior

#6


0  

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

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

PHP Source Code

PHP源代码

#1


11  

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.

看看lua,您可以浏览编程语言的第一版,看看它是如何演变的。它是用C语言编写的,代码简洁明了。您可以在几乎所有编程语言中编写编译器,但C是大多数程序员选择的编译器。

#2


6  

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

CPython中断器已经存在很长时间了,我想这对你来说非常有用。

#3


4  

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.

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

My second choice would be Lua.

我的第二选择是Lua。

#4


4  

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

作为一个温和的介绍,我建议你看一下LLVM教程。

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

Chris Lattner创建了一个简单的玩具语言Kaleidoscope来展示编译的各个阶段:

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

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

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.

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

(And of course, reading the Dragon Book).

(当然,阅读龙书)。

#5


2  

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.

看一下V8 for JavaScript。每个interpeter都有一个名为tokenizer的组件。 GNU有一个名字叫野牛。继续看看吧。它可能会有所帮助。 Chromium也使用一些tokenizer来解释Webkit上的html,但是V8是javascript解释器。

Claudio M. Souza Junior

Claudio M. Souza Junior

#6


0  

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

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

PHP Source Code

PHP源代码