Tuesday, March 20, 2012

YOUZ CAN HAS LOLZCDE - Welcome to the LOLCode Parser

Chris Cavanagh's Blog - LOLCode Parser

On the second Thursday of the month at 5pm, the Rochester, MN .NET User Group meets at Mann Hall. You’re very welcome to join us if you’re in the area. 
We often have someone interesting presenting something exciting, but occasionally that doesn’t work out and I’ll present something instead. This is where the LOLCode Parser was born… 
First you should try it out here. It’ll ask you to write some LOLCode and optionally give it some inputs to pass in. Let’s start with “Hai World”…
HAI
CAN HAS STDIO?
VISIBLE "HAI WORLD!" N " I SLEEPIN"
KTHXBYE

Paste that and click the “PLZ RUN THE CODE 4 ME” button. This demonstrates the VISIBLE statement and the N concatenation operator.

Let’s step it up a bit and add some conditions (to see this work its magic, you’ll need an input value in the second textbox):
HAI
CAN HAS STDIO?
I HAS A VAR
VISIBLE "GIMMEH INPUTZ!..."
GIMMEH VAR
VISIBLE "U SEZ " N VAR
IZ VAR BIGR THAN 10?
YARLY
BTW this is true
VISIBLE VAR N " IZ BIG NUMBER!"
NOWAI
BTW this is false
VISIBLE VAR N " IZ LITTLE NUMBER!"
KTHX
VISIBLE "I IZ DONE"
KTHXBYE

...
If you’re thinking this isn’t very impressive, you’re right. Still, it does have some cool points:
  • It’s using a parser generated by TinyPG (awesome tool on CodeProject by Herre Kuijpers).
  • The LOLCode is being parsed into a LINQ expression tree (similar to this old post, but no DLR and much simpler).
  • Because it’s an expression tree, it can be compiled and cached on the server. This should run as fast as C#, so your cat will be happy. For this demo, if you don’t change the code between requests it’ll just run the cached, pre-compiled code. Anything in the Inputs box is passed as a parameter.
  • This isn’t just an expression returning a value; it’s building a full LOLCode program (with conditions, loops etc).
  • It allows your program to run for up to two seconds; if it overstays its welcome, it will be brutally terminated (putting your cat in an infinite loop is animal cruelty).
You’re unlikely to want LOLCode in your own apps, but some of the ideas could be useful. For example, you could use it to provide a custom scripting language for clients to automate aspects of your apps.
..."
And not only can you try this online, but Chris has made the C# source code available too (click through for a link for that).

image

I think I'm going to make this the default scripting language for one of my solutions... :|

Okay, only for our bug reporting system. LOL  :P

No comments: