sjlol
Here's an interpreter for lolcode built in Python. Feedback is welcome!
News
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!
Installation
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.
Web Based
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.
Windows Binary
Download sjlol-win.zip and unzip it to a folder of your choice.
Source
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.
Usage
$ ./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).
Support
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!
Code Block Support
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?
Variable Declaration Support
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.
Expression Support
[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.
Assignment Support
LOL [variable] R [value]
Value can be a number, an identifier, a string, or an expression.
Mutator Support
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.
Printing Support
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.
Loop Support
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?
Conditional Support
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.
Input Support
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.
Bugs / Issues
This section lists problems; if you find any others please let me know.
- The “CAN HAS [file]?” feature is not supported (it shouldn't be all that hard though). My implementation also differs from the standard in that you don't need STDIO to print. For now, CAN HASes are ignored.
- Error handling is getting better, but still has room for improvement. I'm open to suggestions.
Change Log
- 12 June 2007
- Created sjlolol (sjlol online); a web-based interface to the interpreter.
- 6 June 2007
- Added version information and the –version option.
- Created a Windows binary.
- Added a LOAD command to the interpreter.
- Removed NO MOAR; the interpreter now just interprets program blocks.
- 5 June 2007
- Implemented logical operators (AND, OR, XOR).
- 4 June 2007
- Implemented mutators.
- Implemented +-*/ operators.
- 3 June 2007
- Slight changes to the error handling.
- Fixed the normalization problem where things like ! and ? inside quoted strings would grow spaces.
- Implemented N and ! for VISIBLE statements.
- Implemented LETTAR, WORD, and LINE for GIMMEH statements.
- 2 June 2007
- Implemented assignment with LOL/R.
- Strings can now be compared in conditionals.
- Error handling has been improved a lot.
- When an error occurs the interpreter will display the line and token that caused the problem.
- The interpreter can now be invoked with a –debug option. This will print stack traces for crashes, which are otherwise hidden.
- Implemented GIMMEH, but only for whole-line input.
- Added NOT support for tests in conditionals.
- 1 June 2007
- CAN HAS and NO MOAR statements are now ignored like comments and no longer crash the interpreter.
- The greater than, less than, and equal to tests were changed to meet v1.0.
- 31 May 2007
- A lot of progress has been made toward making the interpreter work with version 1.0 of the language.
- Statements can now end with a period if desired.
- BYES and DIAF have both been fully implemented.
- GTFO is implemented. KTHXBYE no longer breaks.
- KTHX has been implemented. KTHXBYE now only closes HAI blocks, not conditionals or loops.
- IM OUTTA YR has been removed entirely.
- The new IZ/YARLY/NOWAI construct has been implemented.
- Comments are now supported with BTW.
- 30 May 2007
- I've split up the functionality into three files instead of two.
- The command line interface is now better. Use the ”–help” flag to see details.
- You can now output a parse tree to see how the parser is seeing your code with –tree.
Contact
If you have any questions or comments, you can check out the forum thread, or talk to me directly.
- email: still.life@gmail.com
- AIM: sjl7678