esolang

STBF

A small BASIC that a Scratch project compiles into brainfuck.

Masldobehere, 2020 · Turing complete: yes · ●○○ easy · esolangs.org

Tested with 5 known programs · Test method

Run it

Expected: Hello, World!

The idea

Masldobehere made STBF, S-CODE To BrainFuck, in 2020. It is a compiler written in Scratch. You write short lines of S-CODE, one command and its arguments split by spaces, and it gives back compact brainfuck that runs on wrapping 8-bit cells. So every variable holds 0 to 255, and 3 minus 5 is 254.

Read the story

Functions share the global variables like everything else. The specification forbids a function inside another one, because it could send the compiler into an endless loop. This implementation lets a function call another, and stops with an error when one would reach itself.

The machine

CommandDoes
int a lint L nDeclare a variable, or a list of n elements numbered from 1
set a n copy a bSet a to a number; copy a into b
math a + bSet a to a + b; also -, * and / (floor division)
lset L i n lsetvar L i aWrite or read an element; vlset, vvlset, lsetvvar take variables
input aRead one byte
output c output# n nlPrint a character, a byte, a line feed
phrase textPrint the rest of the line
outvar a outvardec aPrint a variable as a byte or in decimal
do if a > b ... stopdoRun once if the condition holds
loop a < b ... if a < b loopEnter if the first holds, go round while the second does
function f ... endfunc func fDefine and copy in a function

Conditions compare two variables with =, >, < or ≠. This implementation runs S-CODE directly. It leaves out raw, goto, cellcopy, celllchange and vcellchange, which work on cells of the compiler's own memory layout; a program that uses them stops with an error.

Example

The second is a number comparator.
Expected: input number one: 5 input number two: 3 5>3
Expected: 0123456789

The second is a number comparator. input reads one byte, as brainfuck's , does, so the two digits come in one after the other.

Further

Ideas it shows

Brainfuck

Cell-based

Write your own in Run Convert a program from STBF

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: stbf.

Command line

shib run stbf -e 'phrase Hello, World!'
shib manual stbf

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/stbf.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org