LOLCode: 2 1337 4 u n00bs

Reading the blog of Scott Hanselman I found a post on LOLCODE. LOLCODE is a simple and silly programming language, based on 1337-speak (a gamers/hackers slang). There is even an official site on LOLCODE, which has several semi-official specifications of the language. You have to see a fragment of LOLCODE to understand what it is all about. Here’s a hello world example:



HAI


  CAN HAS STDIO?


  I HAS A greetz ITZ “Hello World”


  VISIBLE greetz


KTHXBYE


lolcode


Some characteristics of the language:



  • Lots of keyword that don’t make sense unless you are into that particular scene or have them explained

  • Statements are delimited by new-lines

  • A program is a single routine

  • Functions and subroutines are not available

  • Not case-sensitive

  • Offers four variable types: string, int, array and object

If you want to play around with LOLCODE you can download a .NET implementation on the Dynamic Language Runtime (DLR) made by John Lam and his team. You need to download several additional tools and generators. I have already gone through the trouble of doing that. The attachment includes a Visual Studio 2008 solution that has all sources of the LOLCODE compiler and an accompanying set of generators and libraries. You can edit the Demo.lc file in the solution folder and simply hit Ctrl+F5 to give it a spin.


Be warned though: No IntelliSense, debugging support or whatever. You are on your own here. Still good for a bit of Friday afternoon fun.


What I found particularly interesting is that the DLR implementation shows how to build a language compiler of some sorts. There are some generators involved that parse language definition files (Parser.y and Scanner.l to be exact), but to a guy that has no formal Computer Science background (like myself) a nice chance to see what compilers are about.


Here is my sample program that covers a lot of the possible statements. See if you can figure out what the program does. If not, check below to help you understand how things work in LOLCODE:



HAI


  VISIBLE “I IZ IN YR BRAIN PICKING A NUMBAR”


  I HAS A numbar


  CAN HAS System?


  NJU Random ON System


  I HAS A rnd ITZ IT


  COL Next ON rnd WIT 100


  LOL numbar R IT


  VISIBLE “WANNA GUEZ? (CALL ‘enuf’ TO BE A QUITAH)”


  I HAS A guez


  I HAS A countr ITZ 0


  IM IN YR loop


    UPZ countr!!1 


    GIMMEH guez


    IZ guez LIEK “enuf”?


      YARLY


        BTW BYES -1 “Loosah”


        GTFO


    KTHX


    IZ guez SMALR numbar?


      YARLY


        VISIBLE “Too low”


      NOWAI


        IZ guez BIGR numbar?


          YARLY


            VISIBLE “Too high”


          NOWAI


            GTFO


        KTHX


    KTHX


  KTHX


  VISIBLE “U DA BOMB, U RULEZ, U R 1337”


  VISIBLE countr


KTHXBYE


Because the specification is not very clear on some stuff, let me provide you with a rough translation table:



































































































Category Statements and keywords LOLCODE example C# translation English with explanation
Program scope HAI
  BYES code message
KTHXBYE
HAI 
  BYES -1 “Oops”
KTHXBYE
 
static int Main()
{
  return -1;
}
Hello, Goodbyes
Oke, thanks, goodbye.
Return message not supported in C#
Comments BTW comment
OBTW 
  multi-line comment
TLDR
BTW must fix this
OBTW this is a
  multi-line comment
TLDR
// must fix this
/* this is a
  multi-line comment
*/
(Oh) By the way
Too long, didn’t read
IO VISIBLE VISIBLE x Console.WriteLine(x); Show
  GIMMEH [WORD|LETTAR|LINE] GIMMEH x x = Console.ReadLine(); Give me
Assigment LOL variablename ITZ value LOL x R 100 x = 100; (assignment) Laughing Out Loud
R as in “I are happy”
Declaration I HAS A variablename [ITZ initializer] I HAS A x ITZ 100 var x = 100; (declaration) I have a …
Loops IM IN YR loopname
   …
KTHX
IM IN YR akount 
  …
  GTFO
  …
KTHX
while (true)
{
  …
  break;
}
I am in your …
Get the f*ck out
Okay, thanks

Comes from the LOLCATZ pictures. Check some here and here.
Famous World of Warcraft quote:
IM IN YR AKOUNT SHARDING UR PURPLZ
If IZ x SMALR|BIGR|LIEK
  …
KTHX
IZ x SMALR 1?
  YARLY
     …
  KTHX
  NOWAI
    …
  KTHX
KHTX
if (x < 1)
{
  …
}
else
{
  …
}
Is x smaller 1. Yeah, really. No way.
Okay, thanks
Smaller, bigger, like (as in equals)
 
Logical operators NOT, OR, XOR, AND x AND y  x && y  Essentially the same 
Integer operations TIEMZ, OVAR, UP, NERF
TIEMZD, OVARZ, UPZ, NERFZ
UPZ x!!
NERFZ x!!100
x TIEMZ y
x OVER y
x += 1 (or x++)
x -= 100
x * y
x / y
Nerf: reduce power
Up: increase. Upz as in “He ups a value”
Times, over
!! comes from the inside joke of !!1!!!1!!!! where someone accidentally releases SHIFT during exclamation marks.
Program scope HAI
  BYES code message
KTHXBYE
HAI 
  BYES -1 “Oops”
KTHXBYE
 
static int Main()
{
  return -1;
}
Hello
Goodbyes
Oke, thanks, goodbye.
Method invocation COL methodname ON object WIT x AN y COL Next ON rnd WIT 1000 rnd.Next(1000); Call method with x and y
Object instantiation NJU classname ON namespace NJU Random ON System new System.Random(); Will instantiate a new object
  IT NJU Random ON System
I HAS A rnd ITZ IT
var rnd = new System.Random(); Refers to result of function call or object instantation on previous line
Importing libraries CAN HAS library? CAN HAS System? Add Reference to System.dll Adds a reference to an assembly

Some other links:



Drop me a line if you have your own bit of LOLCODE written. ❤

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s