8

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.

1
  • Try the one you like the most. Commented Oct 18, 2011 at 0:13

6 Answers 6

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.

Sign up to request clarification or add additional context in comments.

2 Comments

You can get the source code for all versions in one package at lua.org/ftp/lua-all.tar.gz. They all compile fine.
The source code for some recent versions of Lua can be browsed with links at lua.org/source. See also lua-users.org/wiki/LuaSource.
6

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

Comments

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.

My second choice would be Lua.

Comments

4

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

Comments

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.

Claudio M. Souza Junior

Comments

0

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

PHP Source Code

2 Comments

Given that 'simple' is the OP's primary criteria, if the PHP source isn't simple then how is this an answer?
@ildjarn: PHP Source Code not simple, but you can benefit from Source Code even a few

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.