Sunday 4 July 2010

LOLCODE

HAI everyone!
I've been stumbling this morning and found a really cool programming language called LOLCODE. I have no idea what compilers are out there, but the syntax is brilliant and I just had to show it to you guys. I will talk about some aspects in this post, but for full specs vizit http://lolcode.com/specs/1.2 .

LOLCODE FILZ !!1
All LOLCODE source files begin with HAI and end with KTHXBYE. = ))
All commands are placed on separate lines, or separated by a comma ",".

COMENTZ !!1
Single line comments are marked by the BTW keyword.
BTW this is a comment.

Multi line comments are marked between OBTW and TLDR (which i just found out means Too Long, Don't Read).
OBTW this is a very long
and boooooring comment
so skip it 
TLDR


VARIABLZ !!1
Variables must start with a letter and are case sensitive, though most people make everything capitalized just for fun. Variables are declared with I HAZ A, initialized with ITZ and assigned with R.
I HAZ A VAR        BTW VAR is null and untyped (or NOOB)
I HAZ A DOG ITZ 4  BTW DOG is 4 and of type NUMBR
VAR R "THREE"      BTW now VAR is "THREE" and of type YARN
VAR R 4.3          BTW now VAR is 4.3 and of type NUMBAR


VARIABL TAIPZ !!1
As you probably figured, untyped variables are NOOB (can ony be interpreted as a boolean false), integers are NUMBR, floats are NUMBAR and strings are YARN. There's also a boolean type called TROOF and can be WIN (true) or FAIL (false).


INPUTZ/OUTPUTZ !!1
Printing is done with the keyword VISIBLE, INVISIBLE prints to stderr (errors...) and input is handled with GIMMEH.

IFZ !!1
The if keyword O RLY? is placed after the expression checked and than you have YA RLY for the true part and NO WAI for the false part. YA RLY is closed by the NO WAI block, and the NO WAI block is cloed by OIC.
BOTH SAEM ANIMAL AN "CAT", O RLY?    BTW WIN if ANIMAL == "CAT"
    YA RLY, VISIBLE "JOO HAZ A CAT"
    NO WAI, VISIBLE "JOO SUX"
OIC


LUPZ !!1
Loops are started by IM IN YR <label> keyword and ended by IM OUTTA YR <label> keyword. This is by default an infinite loop and has to be ended by GTFO keyword = )). There is a more complex way to write a loop. See their site details. The <label> has to be the same for a loop, but i'm not sure if it's used any other way.

FUNCTIONZ !!1
Functions are defined with HOW DUZ I <function name> [YR <argument1> AN YR <argument2> AN YR <argument3> ...] and ended with IF U SAY SO. If the function returns something it can return a variable with the FOUND UR keyword or a NOOB with the obvious GTFO keyword.


Well that about all I planed to say about LOLCODE. Hope you had fun reading this and if you ever try coding in this language and make some trivial code that looks funny you're free to leave a comment with it.


Enjoy everyone!
KTHXBYE
         

No comments:

Post a Comment