LOLCODE#Language structure and examples

{{Short description|Esoteric programming language}}

{{Infobox programming language

| name = LOLCODE

| logo = LOLCode logo.png

| paradigm = esoteric

| year = 2007

| designer = Adam Lindsay

| file_ext = .lol, .lols

| influenced_by = Lolcats

| website = [https://web.archive.org/web/20250512215003/http://www.lolcode.org/ lolcode.org]

}}

LOLCODE is an esoteric programming language inspired by lolspeak, the language expressed in examples of the lolcat Internet meme.{{cite web

| author = Dwight Silverman

| title = I'm in ur newspaper writin mah colum

| publisher = Chron.com

| date = 2007-06-06

| url = http://www.chron.com/disp/story.mpl/business/silverman/4862013.html

| access-date = 2007-06-06 }} The language was created in 2007 by Adam Lindsay, a researcher at the Computing Department of Lancaster University.{{cite web|url=http://www.comp.lancs.ac.uk/department/news.html |title=Computing Department at Lancaster University – News |publisher=Lancaster University, Computing Department |access-date=2009-06-09|archive-url=https://web.archive.org/web/20090528151824/http://www.comp.lancs.ac.uk/department/news.html|archive-date=2009-05-28}}{{cite news|url=http://edition.cnn.com/2008/TECH/05/01/roflcon/index.html|archive-url=https://web.archive.org/web/20090430233014/http://edition.cnn.com/2008/TECH/05/01/roflcon/index.html|archive-date=2009-04-30|date=2008-05-01|work=CNN|first=Anne|last=Hammock|title=The new fame: Internet celebrity}}

The language is not clearly defined in terms of operator priorities and correct syntax, but several functioning interpreters and compilers exist. One interpretation of the language has been proven Turing-complete.{{cite web

|author = Arachnid

|title = Proof that LOLCode is turing complete:BrainF*** interpreter in LOLCode

|url = http://forum.lolcode.com/viewtopic.php?id=51

|publisher = forum.lolcode.com

|access-date = 2008-10-05

|url-status = dead

|archive-url = https://web.archive.org/web/20070711193759/http://forum.lolcode.com/viewtopic.php?id=51

|archive-date = 2007-07-11

}}

Language structure and examples

LOLCODE's keywords are drawn from the heavily compressed (shortened) patois of the lolcat Internet meme. Here follow a "Hello, World!" program and a simple program to output a file to a monitor.{{cite web

|author = Adam Lindsay

|title = LOLCODE main page

|publisher = lolcode.com

|date = 2007-05-25

|url = http://www.lolcode.com

|access-date = 2007-10-02

|url-status = dead

|archive-url = https://web.archive.org/web/20071002042159/http://lolcode.com/

|archive-date = 2007-10-02

}} Similar code was printed in the Houston Chronicle.

  • {{code|:)}} represents a newline ({{code|\n}})
  • {{code|:>}} represents a tab ({{code|\t}})
  • {{code|:o}} represents a bell character ({{code|\a}})
  • {{code|:"}} represents a literal double quote ({{char|"}})
  • {{code|::}} represents a single literal colon ({{char|:}})
  • {{code|:()}} converts a single hexadecimal Unicode code point to local environment encoding (for example, UTF-8)
  • {{code|:{} }} interpolates the value of the enclosed variable, cast as a string
  • {{code|:[]}} converts normative name of a single Unicode character to local environment encoding

=Example 1=

HAI 1.2

CAN HAS STDIO?

VISIBLE "HAI WORLD!"

KTHXBYE

class="wikitable" width="80%"

! Code

! Comment

HAI [VERSION]

| In all LOLCODE programs, {{mono|HAI}} ("Hi!") introduces the program and specifies the version (although this isn't actually used yet).

CAN HAS [LIBRARY]?

| In many programming languages, one of the first statements will be a library inclusion for common functions such as input and output. Typically this is included by a call such as {{code|#include }} (stdio standing for standard input/output library). This command is a tongue-in-cheek corruption of that, asking if a library is obtainable, obtaining it if possible, and raising an exception if not.{{cite web|url=http://lolcode.com/keywords/can-has|title=keywords:can-has · LOLCODE|access-date=2008-02-10|archive-url=https://web.archive.org/web/20080206072830/http://lolcode.com/keywords/can-has|archive-date=2008-02-06|url-status=dead}} It is there primarily for verisimilitude—in fact, it is ignored in current implementations of LOLCODE.

VISIBLE [MESSAGE]

| Prints a message to the screen.

KTHXBYE

| Just as HAI introduces the program, KTHXBYE (which is "K," "THX," and "Bye" all strung together, meaning "OK, thanks, bye") terminates it.

BTW [MESSAGE]

|To write a single line comment in LOLCODE, you use the BTW keyword. Comments are ignored by the compiler and are written for better understanding of the program.

OBTW [MESSAGE]TLDR

|Similar to the BTW keyword, the OBTW keyword marks a multiline comment, a comment that spans multiple lines. In LOLCODE, the OBTW keyword signifies the start of a multiline comment while the TLDR keyword ends it.

=Example 2=

HAI 1.2

CAN HAS STDIO?

PLZ OPEN FILE "LOLCATS.TXT"?

AWSUM THX

VISIBLE FILE

O NOES

INVISIBLE "ERROR!"

KTHXBYE

In this example, commands to open a file (PLZ OPEN FILE "NAME"?—"Please open this file?"), and error handling (AWSUM THX—"Awesome, thanks!", and O NOES—"Oh no!") are introduced.

=Example 3=

Other commands include I HAS A variable for declaring variables, variable R value ("variable [is/are/being] value") for assigning them, sending error messages to the front end via INVISIBLE instead of VISIBLE, and BTW ("by the way") to denote a comment, making the parser ignore the rest of the line.

Loops are created with IM IN YR label (inspired by the "Im in ur noun, verbing yr related noun" LOLcat meme), and ended with IM OUTTA YR label. Loops can be broken with the keyword ENUF ("enough"), or in older versions, GTFO.{{cite web|url=http://www.sorn.net/~sandyd/blog/lolcode-mono-osx.png |title=SORN.net |access-date=2007-11-07 |url-status=live |archive-url=https://web.archive.org/web/20090216203453/http://www.sorn.net/~sandyd/blog/lolcode-mono-osx.png |archive-date=February 16, 2009 }} Loops can also be ended with the conditional IZ command, as demonstrated in the next example.

HAI 1.0

CAN HAS STDIO?

I HAS A VAR

IM IN YR LOOP

UP VAR!!1

VISIBLE VAR

IZ VAR BIGGER THAN 10? KTHX

IM OUTTA YR LOOP

KTHXBYE

This simple program displays the numbers 1–11 and terminates (as of specification 1.0). The same program as of specification 1.2 is (assuming VAR starts at 0):

HAI 1.2

CAN HAS STDIO?

IM IN YR LOOP UPPIN YR VAR TIL BOTH SAEM VAR AN 10

VISIBLE SUM OF VAR AN 1

IM OUTTA YR LOOP

KTHXBYE

= Example 4 =

HAI 1.0

CAN HAS STDIO?

VISIBLE "U SEE THIS"

BTW VISIBLE "U SEE NOTHING"

OBTW

VISIBLE "U SEE NOTHIN"

VISIBLE "U STIL SEE NOTHIN"

TLDR

VISIBLE "U SEE THIS"

KTHXBYE

The above example will return the following:

U SEE THIS

U SEE THIS

This is because line 3 outputs U SEE THIS but line 5 is ignored due to the fact that it is commented out by the BTW keyword. Lines 8 and 9 aren't run because they are in a multiline comment that starts in line 7, and ends on line 10. Line 12 outputs U SEE THIS and line 13 terminates the program.

Implementations

The most recent and up-to-date interpreter for the LOLCODE language is lci, written in C by Justin Meza. It interprets LOLCODE efficiently on a variety of platforms.{{cite web |url=http://lolcode.org/ |title=LOLCODE + lci}}

The first LOLCODE implementation was a PHP parser written by Jeff Jones.{{cite web |url=http://lindsay.at/blog/archive/2007/05/21/lolcode.html#comment853 |title=First Parser Comment |publisher=Lindsay.at |access-date=2009-06-09 |archive-url=https://web.archive.org/web/20090519191103/http://lindsay.at/blog/archive/2007/05/21/lolcode.html#comment853 |archive-date=2009-05-19 |url-status=dead }}{{cite web |url=http://www.tetraboy.com/lolcode/ |title=Tetraboy's LOLCODE parser |publisher=Tetraboy.com |access-date=2009-06-09 |archive-url=https://web.archive.org/web/20090227045015/http://www.tetraboy.com/lolcode/ |archive-date=2009-02-27 |url-status=dead }} The parser's website was also the first website using LOLCODE as an actual web scripting language. Being open source with a BSD style licence, it has been forked and used by multiple websites to implement LOLCODE scripting. The winning Pecha Kucha presentation at PHP Works 2008 was about this parser.{{cite web|url=http://www.slideshare.net/Tetraboy/the-best-web-language-lolcode |title="The Best Web Language: LOLCODE" Slides |date=7 March 2009 |publisher=Slideshare.net |access-date=2009-06-09}}{{cite web|url=http://phpworks.mtacon.com/|title=PHP Works|publisher=mtacon.com|access-date=4 November 2014}}

There is a .NET compiler for LOLCODE written by Nick Johnson,[http://code.google.com/p/lolcode-dot-net/ LOLCODE .NET compiler] at Google Code and featured in Microsoft developer training seminars, TechEd 2007 Conference (Australia).[http://www.istartedsomething.com/20070809/teched-day-2-lolcode/ TechEd Day 2: Microsoft announces LOLCode support], Long Zheng[http://www.networkworld.com/community/node/18296 LOLcode in next Visual Studio? For young and funny cats], NetworkWorld.com{{cite web |url=http://blip.tv/file/343052 |title=Video of LOLCODE presentation at TechEd 2007 |publisher=Blip.tv |date=2007-08-17 |access-date=2009-06-09 |url-status=dead |archive-url=https://web.archive.org/web/20090205180201/http://blip.tv/file/343052 |archive-date=2009-02-05 }}

PL/LOLCODE, a project headed by Josh Tolley, makes LOLCODE available as a server-side programming language inside PostgreSQL.[http://pgfoundry.org/projects/pllolcode/ PL/LOLCODE] {{Webarchive|url=https://web.archive.org/web/20101128163641/http://pgfoundry.org/projects/pllolcode/ |date=2010-11-28 }}, pgFoundry

Microsoft Dynamic Language Runtime has an implementation of LOLCODE for testing purposes.[http://channel9.msdn.com/showpost.aspx?postid=392011 Deep DLR],

John Lam and Martin Maly

lolcode-java (A Java grammar / interpreter for the LOLCODE programming language) is a project also available{{cite web |url=https://code.google.com/p/lolcode-java/ |title=lolcode grammar interpreter written in Java}} but it appears to not yet be compliant with the version 1.3 specification.

A LOLCODE to JavaScript translator is also available.{{cite web|url=http://fullvolume.co.uk/static/lolcode/ |title=LolCode |publisher=Fullvolume.co.uk |access-date=2009-06-09}}

There is also a LOLCODE compiler included with the Parrot virtual machine as one of the languages demonstrating the use of Parrot's compiler tools.{{cite web |url=http://lolcode.com/news/lightning-parrot |title=Lightning-Parrot |publisher=lolcode.com |access-date=2009-06-20 |archive-url=https://web.archive.org/web/20090322004648/http://lolcode.com/news/lightning-parrot |archive-date=2009-03-22 |url-status=dead }}

A compiler, virtual machine and debugger, created by Piper, for a LoLCode like language, LoLCode 1337, written in C.{{cite web |url=https://sourceforge.net/projects/lolcode-1337/ | title=LoLCode 1337 }}

A version for parallel and distributed computing can be found.{{cite web |url=https://www.parallella.org/2017/04/01/parallel-and-distributed-computing-with-lolcode// | title=Parallel and Distributed Computing with LOLCODE }}

Related projects

LOLCODE has also inspired LOLPython, written by Andrew Dalke. LOLPython uses LOL-inspired syntax similar to that of LOLCODE, but with a Python-like style. It operates by translating the LOLPython source into Python code.{{cite web|url=http://www.dalkescientific.com/writings/diary/archive/2007/06/01/lolpython.html |title=LOLPython |publisher=Dalkescientific.com |date=2007-06-01 |access-date=2009-06-09}}

ArnoldC is an offshoot of LOLCODE that replaces lolspeak with quotes from different Arnold Schwarzenegger movies.{{Cite web|url=https://lhartikk.github.io/ArnoldC/|title = ArnoldC}}

References

{{Reflist|30em}}