Recently I had the great pleasure to be introduced to LOLCode. It’s an idiomatic syntax based on a series of images found at LOLCat and ICanHasCheezeBurger. In any event, currently LOLCode syntax is at specification 1.2. There are several compilers including a LOLCode.NET compiler. I gave it a try, but as of the time of this posting, it didn’t seem to be able to handle if statements too well.Currently in specification 1.2, everything is still procedural, though there are proposals for OOP LOLCode in the proposed 1.3 specification. I thought for fun I’d post up some LOLCode snippets from a tic tac toe program I wrote in LOLCode to see if I could get it to work.
HOW DUZ I CheckForWinningMatch YR index1 AN YR index2 AN YR index3 AN YR array
BOTH SAEM array!!index1 AN array!!index2, O RLY?
YA RLY
BOTH SAEM array!!index1 AN array!!index3, O RLY?
YA RLY
BOTH SAEM array!!index1 AN “X”, O RLY?
YA RLY
FOUND YR WIN
MEBBE BOTH SAEM array!!index1 AN “O”
FOUND YR WIN
OIC
OIC
OIC
FOUND YR FAIL
IF U SAY SO
The above code snippet checks a one dimensional array (I don’t think it supports multidimensional arrays yet, though I could be wrong) for combinations of the letters X and O for any sort of winning combination. Some of LOLCode syntax includes:
- Functions declarations in LOLCode start with “HOW DUZ I” and end with “IF YOU SAY SO”.
- IF statements are equivilent to “O RLY?” and and equivilency is expressed as “BOTH SAEM”.
- “YA RLY” indicates a positive match, and “NO WAI” indicates a negative match on the condition.
- “MEBBE” corresponds to “else if”
- If statements are closed with “OIC” (oh, I see)
- Return statements are expressed as either “FOUND YR”, followed by a value, or as “GTFO” which returns a void
- The !! operator acts as an indexer, though my understanding is that in OOP LOLCode it may be used to access properties and methods as well
- The TROOF data type (boolean), is expressed as either WIN (true) and FAIL (false)
- Other data types include BUKKIT (array), NOOB (null), NUMBAR (float), NUMBR (int), YARN (string)
- The SMOOSH keyword handles string concatenation
- Programs start with HAI and end with KTHXBYE
Here is my “main” method’s code.
HAII HAS A array ITZ A BUKKIT
I HAS A char ITZ “X”
DrawTicTacToe array
IM IN YR LOOP
BOTH SAEM GetWinningCombination array AN WIN, O RLY?
YA RLY
VISIBLE SMOOSH char ” is winnar!!”
GTFO
OIC
GetUserInput char array
DrawTicTacToe array
BOTH SAEM char AN “X”, O RLY?
YA RLY
char R “O”
NO WAI
char R “X”
OIC
IM OUTTA YR LOOP
KTHXBYE
I grabbed a java compiler from the LOLCode website that appears to have support for the proposed 1.3 specs.
OOP LOLCode, here I come!
Post Footer automatically generated by Add Post Footer Plugin for wordpress.
