Hacker News new | ask | show | jobs
by d0m 3852 days ago
A toy javascript interpreter is quite easy. But a high-performance, production-ready engine is a totally different story.
1 comments

Anyone have a recommendation for a good place to begin, if I was interested in writing a toy javascript interpreter?
Friends of mine used "Create Your Own Programming Language" to get started learning about interpreters: http://createyourproglang.com

I personally learned with SICP (But reading this book isn't just about interpreter, it will make you a better programmer and blow your mind in so many different ways. I wouldn't say it's for experts only, but this isn't the kind of book that beginners would get excited about. However, if someone is serious about improving as a developer, I can't think of a better book): http://www.amazon.com/Structure-Interpretation-Computer-Prog...

Finally, (How to Write a (Lisp) Interpreter (in Python)) by norvig is a great read if you're getting started with interpreter: http://norvig.com/lispy.html

* The reason the two last links are lisp related is because writing interpreter in Lisp is really straightforward (Since the code is the AST). Similarly, if you wanted to learn about memory management, a language like assembler or C might be more suited than say Python.

You can check this code https://github.com/espruino/Espruino/blob/master/README.md

I quote

"Espruino is a JavaScript interpreter for microcontrollers. It is designed to fit into devices with as little as 128kB Flash and 8kB RAM."

It could be a good example of a small js interpreter. I remember the author said to be 95% compatible with real js. That was a couple of years ago.

You can start with https://github.com/DigitalMars/DMDScript which is an open source (Boost licensed) JavaScript engine written in D.