|
|
|
|
|
by bishc
4093 days ago
|
|
In my experience, many people will miss the significance of this, or will simply fail to grasp how this is implementing a programming language at all. After all, you're taking advantage of the host language for every single aspect of the new language, even tokenizing/parsing. More interesting for beginners (in my opinion) are examples implementing a simple tokenizer, parser, and compiler to another source language. This seems to be what closes the gap between programming languages as mystical constructs and programming languages as programs themselves. This point of view does tend to displease the traditional SICP crowd though :-). |
|
It uses a hand-rolled state machine for tokenizing. Recursive descent for parsing. And the interpreter uses the visitor pattern to walk the AST.
Mine also, strangely unlike many of these so-called "teaching" toy languages, has documentation. I don't understand the point of a tiny language for people to learn from if you made it tiny by removing all of the comments. :(
And, to try to avoid leading the reader astray, it calls out any shortcuts it makes. Those are hints where you'd want to do something more robust if you weren't trying to be minimal.
It's here:
https://github.com/munificent/jasic
If you work your way through that, you'll be a long way towards being able to find your way around a real-world interpreter.
The main things it doesn't do is:
1. GC. It leans on Java for that.
2. Compile to bytecode or some other representation. It's a simple tree walker, like Ruby 1.8.
If you want to learn more about those, take a look at:
https://github.com/munificent/wren