Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

Writing An Interpreter In 15 Minutes With Ruby

By Peter Cooper / June 2, 2009

wal15.png At the last regular London Ruby User Group meetup, James Coglan gave a talk on how to implement a Scheme interpreter in 15 minutes. He recorded a video of the coding in progress beforehand so he could focus on the narration so unfortunately the video (available in a higher resolution here from Vimeo) is without sound. There is, however, a ZIP file of HTML slides available to help you follow along.

Naturally, building an arbitrary interpreter from scratch without having a design in mind in 15 minutes is impossible (except for the most trivial of cases) but James' demo is nonetheless impressive. James' knowledge and examples are built upon his work on Heist, a Ruby-powered Scheme interpreter that has somewhat more functionality than the 15 minute version.

The parsing is taken care of primarily by Treetop, a syntactic analysis / parser creation DSL for Ruby. Without Treetop this would be a three hour demo rather than a 15 minute one, so if you haven't checked out Treetop yet, please do - it deserves a lot more praise than I've seen it get so far.

rupho.pngAlso worth seeing.. Beginning iPhone Programming Workshop For Rubyists. A companion class to the FutureRuby conference. Toronto, July 9-10, $1200$699 through June 9.

Comments

  1. Rob Olson says:

    Treetop is indeed awesome. I used it to create an interpreter for a pseudo assembly language called SimpleSem. More details here: http://thinkingdigitally.com/archive/a-simplesem-interpreter/

  2. Tom says:

    Yesterday?

  3. Taryn says:

    I second Tom's "yesterday?" next LRUG is on the 8th isn't it? Otherwise I've missed it! (again) :(

  4. George Palmer says:

    @Tom the post may be a little late but the talk was fantastic. It should be fairly easy to follow without sound

  5. Peter Cooper says:

    My bad. The post seemed to only become popular yesterday but I now note it was written on May 18th. Thanks for bringing this to my attention.

  6. Phil says:

    Actually parsing s-expressions without treetop is pretty straightforward. Where treetop shines is for grammars that are more complicated than Scheme's. (Not that this wouldn't be a good demo of its capabilities.) Looks like some good stuff.

  7. El Rug says:

    The hosts for the evening, Skills Matter, also filmed the whole talk, so you can get the audio of James's talk here: http://skillsmatter.com/podcast/ajax-ria/implementing-scheme-in-ruby (including his intro slides that explain exactly what Scheme is and what he's going to implement).

Other Posts to Enjoy

Twitter Mentions