small s.c.r.i.p.t.
Brainfuck's tape and loops, read one character at a time, where a number in front of an operator changes what it means.
Brian Tiffin, 2013 · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 9 known programs · Test method
Run it
The idea
Brian Tiffin wrote small s.c.r.i.p.t. in OpenCOBOL in August 2013. He calls it a single character read interpret programming toyol, and a toyol is a toy and a tool. It starts from the brainfuck model of memory and loops, adds Forth's colon definitions, and echoes every character that is not an operator, so a program is mostly the text it prints.
Read the story
The twist is the numbers. Digits before an operator make a value for it. 5[a] repeats five times where [a] tests the cell, 3+ adds three, and 16> moves sixteen cells. A leading zero changes the operator again. 032+ sets the cell to 32 instead of adding, 01> goes to cell 1 instead of moving one cell, and 01"..." lays a string down in ROT13. The specification calls the leading zeros a joke.
The machine
| Op | Does | With n | With 0n |
|---|---|---|---|
+ - | Add or subtract 1 | Add or subtract n | Set the cell to n, or to minus n |
> < | Move one cell | Move n cells | Go to cell n |
[ ... ] | Loop while the cell is not 0 | Loop n times | |
{ ... } | Enter only if the cell is 0 | Enter only if n is 0 | |
. # | Print the cell as a character or a number | Print n | # pads to three digits |
@ | Fetch the cell as the next number | Fetch the cell n further | Fetch cell n |
\ | Echo the next character | Echo the next n | |
! | Jump to the place in the cell | Jump n places on | Jump to place n |
:x ... ; | Define x | Define the character with code n | |
"text" | Lay the text down from here | From cell n | In ROT13 |
Cells and places count from 1. Every other character is echoed, unless it has a colon definition. This implementation leaves out ', which calls a link library such as system, and ?, which randomizes the cell or prints debugging.
Example
The comma in Hello needs a backslash, or it would read input.
The comma in Hello needs a backslash, or it would read input. In the fetch example @ turns the cell holding 2 into the count for the next loop three times, once as the current cell, once as cell 2 and once as the cell one further. In the last one 05! jumps to the fifth character, so a is never echoed, and 2! jumps two places on, past c.
This is the shortest 99 bottles of beer, started at 3 as the specification's own run is. S prints the s of bottles unless the count is 1, by jumping with 3! past the s when a test for zero is entered. 4\ echoes the next four characters, so the 99 at the end is printed and not read as a number.
The ASCII chart is written in the short form the specification gives last, where ~ is defined as one entry of the chart. The longer listing has 0@.# on its last line, which prints /47 where the specification shows 047.
Patterns it teaches
- Encoding tricks: one register of digits and a leading zero give each operator three meanings.
See also
small s.c.r.i.p.t. builds on Brainfuck.
Brainfuck derivatives
Write your own in Run Convert a program from small s.c.r.i.p.t.
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: small-s-c-r-i-p-t.
Command line
shib run small-s-c-r-i-p-t -e '5[a]'shib manual small-s-c-r-i-p-tSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/small-s-c-r-i-p-t.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org