Why I want to write an interpreter in Javascript

A hobby of mine for the past few years has been writing virtual machines and interpreters. Or should I say – starting to write them, then abandoning them. Regardless, the siren song of “make your own language with all your strongly held beliefs about programming baked in” continues to be alluring to me. And damn it, I’ve decided to cannibalise a recent interpreter attempt and have another go.

After some thought, I decided that javascript is the perfect candidate to write a programming language in. Specifically, to write an interpreter in javascript, and use that interpreter from the browser. That’s right, the browser is going to interpret javascript that in turn interprets another language. Sounds crazy, but I have my reasons.

Web Apps are Convenient

Let’s assume you’re a programmer. You’re fairly open minded, you’ve tried a few languages, and your response to seeing a new programming language isn’t “ugh, why do we need another programming language?”,  but “cool, I wonder if this language is something I’d like”.

Great! You’re the primary audience for people who make their own programming languages. So, how likely are you to download, compile and test some guys prototype interpreter/compiler?

Probably not likely.

If the interpreter is a browser app though, it lowers the effort significantly. You can point your browser and start playing with it straight away. And that’s all the effort you’ll ever have to expend, even as the language continues to be updated and refined.

The performance of an unstable language isn’t important

Unless you’re Apple or Google or even Mozilla, no one is going to bother writing anything remotely useful in your unstable language. The most you can really hope for is that people try it out and implement some known algorithms or toy examples. You want to get as many people doing that kind of thing as possible. Can they do that without experiencing too much difficulty from a slow implementation? Great, you’re fast enough. Feedback on your semantics is the key here.

Javascript is very important (for me)

For a number of reasons, I see my future in web development. While I know some of the language, and I’ve “gotten by” when I’ve needed to use it, I am by no means a great javascript dev. It’s easy to get by when most of what you are doing is manipulating the DOM, but in this era of full blown web applications and thin server architecture that’s not really going to cut it. What better way to get better than to write a non-trivial application that’s mostly logic?

It doesn’t need to stay in Javascript forever

The tools you use for prototyping don’t need to be the same tools you use when things get more serious. I figure once the semantics are defined, writing a faster implementation is going to involve more translation and less exploration. Writing for a moving target in C or C++ is not ideal – but doing a re-write after the fact, with your path laid out a ahead of you, makes things a lot easier.

Of course there is the small matter of needing to write your own garbage collector, but we’ll cross that bridge when we come to it.