Skip to content

Commit f1ab468

Browse files
committed
Added codec: lolcode
1 parent 95226ea commit f1ab468

5 files changed

Lines changed: 759 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ This category also contains `ascii85`, `adobe`, `[x]btoa`, `zeromq` with the `ba
394394
- [X] `befunge`: Befunge-93, two-dimensional esoteric language (encoding generates a program printing the text)
395395
- [X] `brainfuck`: well-known esoteric programming language (encoding generates a program printing the text)
396396
- [X] `cow`: esoteric language made of variations of "moo" (Brainfuck-like, with a register and integer output)
397+
- [X] `lolcode`: esoteric language inspired by lolcats (encoding generates a program printing the text), also with lowercase keywords
397398
- [X] `ook`: Brainfuck derivative for orang-utans (`Ook.`, `Ook?` and `Ook!`), also in its short form
398399
- [X] `pikalang`: Brainfuck derivative using Pikachu's vocabulary
399400

‎docs/pages/enc/esoteric.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,30 @@ COW is made of 12 variations of the word "moo". Its memory is a tape of integer
5959

6060
-----
6161

62+
### LOLCODE
63+
64+
[LOLCODE](https://esolangs.org/wiki/LOLCODE) programs start with `HAI` and end with `KTHXBYE`, and work on dynamically typed variables (`I HAS A <var> ITZ <value>`, `<var> R <value>`) holding untyped values (`NOOB`), booleans (`WIN` and `FAIL`), integers, floats or strings (with escapes such as `:)` for a newline). The language has prefix operators (`SUM OF <x> AN <y>`, `BOTH SAEM <x> AN <y>`, `SMOOSH <x> AN <y> MKAY`, ...), conditionals (`O RLY?` and `WTF?`), loops (`IM IN YR <label> ... IM OUTTA YR <label>`) and functions (`HOW IZ I <name> ... IF U SAY SO`), and prints with `VISIBLE` (with a newline, unless ended with `!`). Encoding generates an ASCII program with one `VISIBLE` per line of the text. Programs are run according to the [1.2 specification](https://github.com/justinmeza/lolcode-spec/blob/master/v1.2/lolcode-spec-v1.2.md), with the behavior of the [reference interpreter](https://github.com/justinmeza/lci) (lci) where the specification says nothing.
65+
66+
**Codec** | **Conversions** | **Aliases** | **Comment**
67+
:---: | :---: | --- | ---
68+
`lolcode` | text <-> LOLCODE program | `lol` | syntax and runtime errors reported whatever the errors handling ; programs that do not halt within 1000 steps per token (with a minimum of 1 million) are stopped
69+
`lolcode-lower` | text <-> LOLCODE program with lowercase keywords | `lol_lower`, `lolcode-lowercase` | also decodes uppercase keywords ; lowercase keywords (e.g. `i` or `a`) cannot be used as identifiers
70+
71+
!!! note "Differences with the reference interpreter"
72+
73+
Features of LOLCODE 1.3 (`BUKKIT` arrays, `SRS`, `'Z`, ...) are not supported. Without input, `GIMMEH` gives an empty string. The version after `HAI` is optional (as in former versions of the language). As in the specification, variables have the scope of the main program or of the function (instead of the block), and casting a string that is not a number (e.g. `"abc"` or `" 12"`) to a number is an error (lci gives 0 or parses it leniently). `WIN` and `FAIL` are printed as such (lci reports an error).
74+
75+
```python
76+
>>> codext.encode("Hello\nWorld!", "lolcode")
77+
'HAI 1.2\nVISIBLE "Hello"\nVISIBLE "World!"!\nKTHXBYE'
78+
>>> codext.encode("Hello\nWorld!", "lolcode-lower")
79+
'hai 1.2\nvisible "Hello"\nvisible "World!"!\nkthxbye'
80+
>>> codext.decode('HAI 1.2\nIM IN YR loop UPPIN YR n TIL BOTH SAEM n AN 3\n VISIBLE "KTHX " SUM OF n AN 1\nIM OUTTA YR loop\nKTHXBYE', "lolcode")
81+
'KTHX 1\nKTHX 2\nKTHX 3\n'
82+
```
83+
84+
-----
85+
6286
### Ook!
6387

6488
[Ook!](https://www.dangermouse.net/esoteric/ook.html) is an esoteric programming language derived from Brainfuck, designed to be read and written by orang-utans: each Brainfuck command is a pair of the words `Ook.`, `Ook?` and `Ook!` (e.g. `Ook. Ook?` for `>` and `Ook! Ook.` for `.`). Short Ook! only keeps the punctuation marks (e.g. `.?` for `>`). Encoding generates a program that prints the text (as UTF-8), while decoding runs the program (with 8-bit cells and no input) and returns its output.

‎src/codext/esoteric/__init__.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
from .befunge import *
33
from .brainfuck import *
44
from .cow import *
5+
from .lolcode import *
56
from .ook import *
67
from .pikalang import *

0 commit comments

Comments
 (0)