How to implement a programming language

  • Published: 2014-06-08
  • Modified: 2014-06-08 17:42
  • By: Mishoo
  • Tags: javascript, continuations, pltut, cps
  • Comments: 4 (add)
Jun
8
2014

How to implement a programming language

I wrote a tutorial on how to implement a programming language in JavaScript. It got quite involved, and it took embarrassingly long to write. I wanted to write only about parsing, after a discussion with my dad about this problem; but once I had a parser I thought I'd add in a simple interpreter and once that was in place, I thought I'd turn it into continuation-passing style to show how we can workaround the lack of tail call optimization in JavaScript. But this opened the opportunity to talk about continuations. And of course, it was too slow so I thought I'd discuss compiling as well.

Long story short: I describe how to implement a non-trivial programming language. We get to a language that has decent performance, can interface easily with JavaScript and can offer first class continuations. To hell with the callback hell!

Read on and let me know what you think.

4 comments. This is HOT!

Add your comment

# yves
2014-10-02 18:49
Hi Mihai, I'm wondering if iyou could do a series or posts to go through implementing the same programming language, but using LISP to , interpret, parse etc... That would be an interesting comparison to see how the same language would be implemented using different both languages..
# Mishoo
2014-10-02 20:57
I don't have the time for that, I'm afraid… However what I did work on is writing a Lisp → JS compiler, based on the code described in this article (with many fixes + additional Lisp parser). It's functional, but there are no demos and no docs, and I worked on it rather scarcely. Hope to publish it some time soon.
# Jeremy
2015-03-12 23:16
The method your using was first introduced (to my knowledge) by Jack Crenshaw in his "Lets build a compiler" series (http://compilers.iecc.com/crenshaw/). It does make compiler development a piece of cake, and, at the end of the day, what you have built is a compiler. Nice work by the way, would be interesting to see your language released for use and see what happens with it.
# JP
2016-10-10 15:01
Excellent tutorial - I was writing in a different language but it didn't matter, because the code and algorithms were easy to follow.