With OSDC 2010 over, it’s time to dump all my presentations online for another year. I’m in the process of uploading presentations to Slideshare, but I thought I might make a quick follow-up post about my Hugging Abstract Syntax Trees presentation.
The presentation was on using Python’s internal AST structure, and it seems to have gotten a few people interested in playing around with Python ASTs. The main point was to demonstrate that it was both possible — and not all that difficult! — to use Python to build new programming languages for the Python VM.
To prove this, I cobbled together a compiler front end that scanned & parsed source code, constructed an AST, then passed it off to Python’s compile() builtin to generate a Python code object. This code object could then in turn be serialized to a .pyc file, or executed directly using exec/eval(). This was a couple of hours worth of effort.
I called the resulting language viking, which looks a bit like Python with curly braces and semi-colons. viking doesn’t support certain very basic programming language features (arithmetic[!] for example), but you’ll see the sample programs demonstrate that it supports some reasonably cool high-level constructs. Most interesting to existing Python geeks might be its support for “real” anonymous functions i.e. it removes the constraints of the lambda keyword.
Ingy grabbed me after the presentation to help him add a .pyc emitter to C’Dent, so the idea has already found its way outside of my proof of concept. This means you can now translate from any of C’Dent supported languages into a byte-compiled Python file, which is really kind of cool.
Outside of that, I’m hoping to see folks do some experimentation with programming language construction using the Python AST. It’s a great way to prototype new language ideas.
You can clone the viking proof of concept from github, and you can get the presentation slides from Slideshare. You can also grab the slides for my Open Source in Big Business presentation from Slideshare too.
As an aside, the conference itself was fantastic. By far my best OSDC to date. Met lots of cool geeky folks and made a few new friends in the process! Thanks to all the conference organizers, presenters and delegates, and my employer Shine Technologies for giving me the time to attend the conference & support to put this stuff together for yet another year.
Looking forward to next year’s conference!