Here's an interpreter for lolcode built in Python. Feedback is welcome!
I've created a web-based version so you don't have to download or install anything to try out lolcode!
Except for a few minor things I think I'm pretty much up to the 1.0 standard. If anyone sees anything I missed please let me know!
The web-based version should work with any browser and should let you try out things without installing anything. If you need more flexibility you'll need to download and install the interpreter on your own machine.
If you're using Windows you can use the Windows binary version or the source. OS X and Linux users will need to use the source.
To use the web-based interpreter just go to sjlolol. Put your lolcode program in the first box, any input in the second box, and hit the button to run it.
Note: to avoid the possibility of people running infinitely looping programs on my machine and bringing it to a halt, programs can only run for a maximum of four seconds. After four seconds they are terminated. If this time is too short I'll think about increasing it; email me and let me know.
Download sjlol-win.zip and unzip it to a folder of your choice.
Install Python if you need to. If you're using Linux or OS X it's probably already installed.
Install PLY according to the instructions on the PLY site.
Download sjlol.zip and unzip it to a folder of your choice.
$ ./sjlol.py --help Usage: sjlol.py [options] [source.lol] If no source file is given the program will work in interactive mode. Options: -h, --help show this help message and exit -t, --tree output the parse tree. -d, --debug output more debugging information on a crash -v, --version output the version information and exit
If no source file is given the program can be used in interactive mode. You can load a source file form interactive mode using “LOAD source.lol” or you can type in a code block. Here's an example:
lol> LOAD hello.lol HAI WORLD! lol> HAI ...> VISIBLE 1337 ...> KTHXBYE 1337 lol>
Use ^D to exit entirely (^Z on Windows).
So far the interpreter supports a decent portion of the 1.0 standard. Not everything is supported but then again not everything is terribly well documented. If you have suggestions for what I should implement next please let me know!
HAI ... KTHXBYE
Nested code blocks are supported (though they don't do anything (yet)). Should they?
Empty code blocks are not supported. Should they be?
I HAS A [variable]
This declares a variable. Simple enough.
ITZ is not implemented and will throw an error. I'll implement it once it's in the standard.
[value] UP [value] [value] NERF [value] [value] TIEMZ [value] [value] OVAR [value]
Precedence is not defined at the moment because the 1.0 standard does not define it. For now, use intermediate variables to ensure the precedence you want.
LOL [variable] R [value]
Value can be a number, an identifier, a string, or an expression.
UPZ [variable]!![number] NERFZ [variable]!![number] TIEMZD [variable]!![number] OVARZ [variable]!![number]
These are the equivalent of +=, etc. Right now they only support numbers after the bangs, not expressions, etc. If nothing is given it defaults to 1.
VISIBLE [item] [N [item2] ...][!]
The item(s) may be a variable name, a quoted string, or a number. N may be used to print multiple, space-separated items.
If the statement ends with a bang no newline is printed, otherwise a newline is printed at the end.
IM IN YR [label] ... KTHX
This creates an infinite loop. Hopefully there's a GTFO or BYES/DIAF in there somewhere to break out of it.
Loop labels are supported, but don't do anything special. Should they?
Conditionals currently have limited functionality.
IZ [item] [test] [item][?]
[YARLY]
[statements]
[NOWAI]
[statements]
KTHX
Items can be numbers, variables, strings, or expressions.
For now the only tests are “BIGR THAN”, “SMALR THAN”, and “LIEK”. Putting a “NOT” in front of the test (“NOT BIGR THAN”) will negate the result.
Tests can be combined with AND, OR, and XOR. Precedence for these is not defined yet.
The question mark is optional, as is the NOWAI clause. YARLY is optional if there is no NOWAI clause.
GIMMEH [input type] [variable]
The input type can be LETTAR, WORD, or LINE. The rules for where whitespace gets cut are a bit cloudy right now because they're not nailed down in the standard.
It can only read from STDIN at the moment.
This section lists problems; if you find any others please let me know.
If you have any questions or comments, you can check out the forum thread, or talk to me directly.