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
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
| Command | Does |
|---|---|
int a lint L n | Declare a variable, or a list of n elements numbered from 1 |
set a n copy a b | Set a to a number; copy a into b |
math a + b | Set a to a + b; also -, * and / (floor division) |
lset L i n lsetvar L i a | Write or read an element; vlset, vvlset, lsetvvar take variables |
input a | Read one byte |
output c output# n nl | Print a character, a byte, a line feed |
phrase text | Print the rest of the line |
outvar a outvardec a | Print a variable as a byte or in decimal |
do if a > b ... stopdo | Run once if the condition holds |
loop a < b ... if a < b loop | Enter if the first holds, go round while the second does |
function f ... endfunc func f | Define 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.
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
See also
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 stbfSource
- 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