简体   繁体   中英

Scripting language interpreter source code to learn from

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.

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.

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

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 .

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 ).

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

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

PHP Source Code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM