esolang

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

Expected: Hello, world

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

OpDoesWith nWith 0n
+ -Add or subtract 1Add or subtract nSet the cell to n, or to minus n
> <Move one cellMove n cellsGo to cell n
[ ... ]Loop while the cell is not 0Loop n times
{ ... }Enter only if the cell is 0Enter only if n is 0
. #Print the cell as a character or a numberPrint n# pads to three digits
@Fetch the cell as the next numberFetch the cell n furtherFetch cell n
\Echo the next characterEcho the next n
!Jump to the place in the cellJump n places onJump to place n
:x ... ;Define xDefine the character with code n
"text"Lay the text down from hereFrom cell nIn 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.
Expected: abbbbb abbbbb abbbbb abbbbb
Expected: aabbcc
Expected: ace
Expected: bd

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.

Expected: 3 bottles of beer on the wall, 3 bottles of beer. Take one down and pass it around, 2 bottles of beer on the wall. 2 bottles of beer on the wall, 2 bottles of beer. Take one down and pass it around, 1 bottle of beer on the wall. 1 bottle of beer on the wall, 1 bottle of beer. Take one down and pass it around, no bottles of beer on the wall. No more bottles of beer on the wall, no more bottles of beer. Go to the store and buy some more, 99 bottles of beer on the wall.

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.

Further

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-t

Source

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