Įvestis - čionai rašykitPavyzdžiai:
Turėkite omeny, kad čia yra pilnavertė Tiuringo mašina. Tai reiškia, kad jūs visada galite parašyti begalinį ciklą ar rekursiją, kuri jūsų naršyklę pakabins brutualiausiu būdu. Jei taip atsitiks - kaltinkite save ir mokykitės, kad neatsitiktų. Ir žinoma, išsisaugokite kažkur tą savo programą, kad ji, jei pakibs, nedingtų.
Klaidų aptikimas yra prastas, taigi, jei nematote rezultato - tikrinkitės savo programą, nes greičiausiai kažkur interpretatorius pastrigo.
|
Išvestis - čionai skaitykit |
var IT;IT = AI;IT = PLZOPENFILE"LOLCATS.TXT";IT = AWSUMTHX;lolspace_puts(FILE,true);IT = ONOES;IT = INVISIBLE"ERRROR!";
AI CAN HAS STDIO? PLZ OPEN FILE "LOLCATS.TXT"? AWSUM THX VISIBLE FILE O NOES INVISIBLE "ERRROR!"KTHXBYE
NUMBR
NUMBAR
TROOF
YARN
NOOB
BOTH SAEM 1 AN WIN, O RLY?
If you want to make this implementation better/worse or just use it for LOLcat related hilarity on your website (it would be fun to expand it to allow basic DOM manipulation), the code is online and free here.
Note: largely untested on Internet Explorer, whose JavaScript engine is fussy at the best of times.
MAEK PRODUKT OF 1 AN 2 A YARN
Comments can extend until the end of the line if they are opened with BTW:
HAI BTW this is a comment
Or they can be arbitrary length if opened with OBTW:
OBTW this is a multi-line comment TLDR
VISIBLE
VISIBLE
GIMMEH VARNAME
Obviously, being JavaScript, no file IO is available.
I HAS A NUMBER
NUMBER R 12
I HAS A NUMBER ITZ 12
NUMBR
NUMBAR
TROOF
YARN
NOOB
BUKKIT
WIN
FAIL
Type casting works as follows:
I HAS A NUMBER ITZ 12 BTW x_ R MAEK y_ A TYPE is equivalent to x_ = (TYPE)y_ NUMBER R MAEK NUMBER A YARN BTW number == "12" BTW you can also use 'IS NOW A' NUMBER IS NOW A TROOF BTW number == true NUMBER IS NOW A NOOB BTW number == null NUMBER IS NOW A NUMBAR BTW number == 0
Array support is not defined in the LOLCODE 1.2 spec so I have taken a few liberties. An array is declared with:
I HAS A ARRAY ITZ GOT 1 AN 2 AN 3 BTW ARRAY = [1, 2, 3] I HAS A NOTHERARRAY ITZ GOT NOTHING BTW ARRAY = [] I HAS YETANOTHERARRAY ITZ GOT 1 AN NOTHING ELSE BTW ARRAY = [1]
The last construct is redundant, NOTHING ELSE is not required. Assignment after declaration works almost as usual:
ARRAY R GOT 1 AN 2 AN 3 BTW ARRAY = [1, 2, 3]
Array access works with a single '!':
ARRAY R GOT 1 AN 2 AN 3 VISIBLE ARRAY!0 VISIBLE ARRAY!1
these can also be used for assignment directly into the given indices. This also allows for multi-dimensional arrays
I HAS A ARRAY ITZ GOT NOTHING ARRAY!0 R GOT FAIL AN WIN ARRAY!1 R GOT 0 AN 1 BTW ARRAY = [[false, true], [0, 1]]
Arrays and strings have the special 'LEN OF' operator available which returns the number of items they hold (at their first level)
IZ VAR1 [BIGGR|SMALLR] THAN VAR2? .... KTHX
VAR1, O RLY?, YA RLY ... OIC
An example follows:
I HAS A FOOD ITZ "CHEEZBURGER" BOTH SAEM FOOD AN "CHEEZBURGER", O RLY? YA RLY VISIBLE "I LIKE CHEEZBURGER :D" MEBBE BOTH SAEM FOOD AN "COOKIE" VISIBLE "I LIKE COOKIE ::)" NO WAI VISIBLE "I WANT CHEEZBURGER :(" OIC
This could be re-written as a WTF? (switch) expression:
I HAS A FOOD ITZ "CHEEZBURGER" FOOD, WTF? OMG "CHEEZBURGER" VISIBLE "I LIKE CHEEZBURGER :D" GTFO BTW break OMG "COOKIE" VISIBLE "I LIKE COOKIE ::)" GTFO OMGWTF BTW default VISIBLE "I WANT CHEEZBURGER :(" OIC
IM IN YR LOOP ... KTHX
GTFO
IM IN YR LOOP UPPIN YR COUNTER WILE COUNTER SMALLR THAN 10 VISIBLE COUNTER IM OUTTA YR LOOP
or:
IM IN YR LOOP UPPIN YR COUNTER TIL BOTH SAEM COUNTER AN 10 VISIBLE COUNTER IM OUTTA YR LOOP
NERFIN
UPPIN
SUM OF
DIFF OF
PRODUKT OF
QUOSHUNT OF
MOD OF
BIGGR OF
SMALLR OF
BOTH SAEM
DIFFRINT
BOTH OF
EITHER OF
WON OF
NOT
ALL OF
ANY OF
Generally operators use prefix notation and are assembled as follows:
SUM OF 1 AN 2
BOTH SAEM SUM OF 1 AN 2 AN 3 BTW this evaluates to WIN
The expressions' precedence is such that the expressions are evaluate left to right and may nest
SUM OF QUOSHUNT OF 1 AN 2 AN DIFF OF 3 AN 4
(SUM OF (QUOSHUNT OF 1 AN 2) AN (DIFF OF 3 AN 4))
NOT
ALL OF
ANY OF
MKAY
BOTH SAEM X AN [BIGGR|SMALLR] OF X AN Y
IZ X BIGGR THAN Y?
IZ X SMALLR THAN Y?
KTHX
SMOOSH
I HAS A VAR ITZ SMOOSH "STR1" AN "STR2" AN "STR" AN 3 MKAY VISIBLE VAR BTW prints "str1str2str3"
Functions can be defined like this:
HOW DUZ I ADD YR NUM1 AN YR NUM2 I HAS A SUM ITZ SUM OF NUM1 AN NUM2 FOUND YR SUM BTW returns sum IF U SAY SO
This has defined a function 'add' with two arguments. It can be called like so:
I HAS A SUM ITZ ADD 1 2 VISIBLE SUM BTW prints 3
Functions are evaluated in the same way as operators, so the return value of a function may be nested inside an operator and vice versa, e.g.:
I HAS A NUM ITZ ADD 1 AN DIFF OF 1 AN 2 VISIBLE NUM BTW prints NUM = 1 + (1-2) = 0
Further, if one defines a function which takes zero arguments it looks like a constant:
HOW DUZ I PI FOUND YR 3.14159 IF U SAY SO VISIBLE QUOSHUNT OF PI AN 2 BTW prints 1.570795
In LOLCODE escape sequences inside strings begin with a colon ':'. LOLCODE defines the following escape sequences for use inside strings:
":"" BTW An escaped quote ":)" BTW newline ":>" BTW tab ":o" BTW bell (not implemented here) "::" BTW colon character. ":{VAR}" BTW variable interpolation (inserts the string value of VAR) ":(HEX)" BTW inserts a unicode character with the given hex code
Named unicode sequences are not yet supported.
Šis Dibilų kalbos interpretatorius yra paremtas puikiu Mark Asgaard LOLCODE transliatoriumi, kuris visaip perdirbtas čionai jums ir yra demonstruojamas.