The Weekly Source Code 11 - LOLCode DLR Edition
During my Friday Keynote at the PNPSummit I did a silly 30 minute PowerPoint that ended with some LOLCats and a few examples of LOLCode. If you're not familiar with LOLCats, they are basically silly pictures of cats that speak a l33tspeak-like language, like IM IN UR BASE KILLIN YUR D00DS.
This language has turned into a Programming Language called LOLCode for which there are already at least TWO .NET implementations. The first implementation of LOLCode.NET is up on Google Code and is by Nick Johnson.
During my talk, unbeknownst to me, literally that minute John Lam was uploading the DLR team's own implementation of LOLCode implemented from scratch on the DLR. The amazing Martin Maly of the DLR team implemented LOLCode on his plane ride to Spain for presentation at TechEd.
I invited John up on stage spontaneously to give a demo of LOLCode and he did...he showed a Fibonacci implementation.
This is great code to read for two reasons. It's two completely separate implementations of the same general idea - an LOLCode compiler. However, they are implemented completely differently. Of course, the DLR team images this as a Dynamic Language so their implementation is a great primer on how to make your own language on the DLR.
HAI CAN HAS STDIO? VISIBLE "HAI WORLD!" I HAS A CODE ITZ "CRAZY" VISIBLE CODE I HAS A NUMBR LOL NUMBR R 2 VISIBLE NUMBR TIEMZ 2 I HAS A FIB I HAS A A ITZ 1 I HAS A B ITZ 0 VISIBLE "Fibonacci: " GIMMEH FIB IM IN YR VISIBLE B IZ FIB SMALR 1? YARLY GTFO KTHX I HAS A TEMP ITZ A UP B LOL A R B LOL B R TEMP NERFZ FIB!! KTHX CAN HAS System? VISIBLE CurrentDirectory ON Environment ON System NJU Hashtable ON Collections ON System I HAS A HT ITZ IT I HAS A DT LOL DT R DateTime ON System VISIBLE Now ON DT COL Add ON HT WIT "LolCode" AN "Rulezz!!" VISIBLE COL get_Item ON HT WIT "LolCode" COL Concat ON String ON System WIT "LolCode " AN "Rulezz!!" VISIBLE IT KTHXBYE
In order to get the DLR Team's implementation running on your own machine, you need to do the following:
- Get the LOLCode sources
- Get IronPython 2.0 Alpha 6
- Get the Gardens Point Parser Generator (GPPG)
- Get the Gardens Point Scanner Generator (GPLEX)
These are kind of Lex and Yacc for C#. Open up the Parser.y and Scanner.l to see the language grammar details.
- Confirm the PostBuild steps point to the right locations and make sure the Microsoft.Scripting.dll reference points to the Microsoft.Scripting.dll from the IronPython download.
Enjoy! If you don't think this is fun, go play with the MVC Demo Source Code from DevConnections and the PNPSummit.