John Resig (of jQuery fame) has ported the Processing visualization language to JavaScript.

The examples are remarkable, check them out (but check the browser issues John discusses).

John has a little confession:

The first portion of the project was writing a parser to dynamically convert code written in the Processing language, to JavaScript. This involves a lot of gnarly regular expressions chewing up the code, spitting it out in a format that the browser understands.

It works "fairly well" (in that it's able to handle anything that the web site throws at it) but I'm sure its total scope is limited (until a proper parser is involved). I felt bad about tackling this using regular expressions until I found out that the original Processing code base did it in the same manner (they now use a real parser, naturally).

Actually that's quite cool in itself (even if angels weep at this parsing code, I think we on LtU shouldn't cast the first stone). DSLs should be easily built and played with. Cleaning up the implementation comes later, if at all.

Purists may not only object to the regular expression parsing, but also to the central line of code which ties things together, namely: eval(parse(code, p)). But then, DSL lovers are not the sort of people to object to eval...

In the old days of LtU we regularly posted links to cool small interpreters that people could play with. Some of the more amusing ones were javascript based, and the page contained a REPL form (Luke, I am talking to you!). It is a shame we don't post more stuff like this, in between the more highbrow discussions...

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

lowbrow REPL

I'm not sure if it's the "more stuff like this" Ehud was asking for, but here's a beer & pretzels style "literate" turtle graphics interpreter, originally written mainly to play around with automatic generation of inverse functions, à la J. (the impatient can simply head for the interactive webpage itself).

Being somewhat of a purist, I apologized for the rudimentary parser and used an explicit fold instead of eval.

PL Zoo

For what it's worth, at the Programming Language Zoo I am (slowly) publishing a bunch of small interpreters that I use to teach programming languages. I have about a dozen of them, but I need to clean up the code before I publish them.

educational toys for language learning

To extend the subject area somewhat, does anyone know of any "cool small" virtual machines that you can play with?


The Parsing Issue....

I've only been using REGEX for about 6 months, so I am wondering... what are the main pros and cons using REGEX as opposed to another kind of parser?

I think Processing.js is great. I use it a lot. If you want to see some of my Processing.js examples; check out my experiments at: