From Esolang
Jump to navigation Jump to search

TrivialBrainfuckSubstitution is not a single programming language, but rather a large family of programming languages that are trivial substitutions of the Brainfuck language.


We will pick TrivialBrainfuckSubstitution("a","b","c","d","e","f","g","h") as an example. To write a program in TrivialBrainfuckSubstitution("a","b","c","d","e","f","g","h"), first make a program in BF. Then, convert it to according to this table:

Brainfuck TrivialBrainfuckSubstitution("a","b","c","d","e","f","g","h") Description
> a Move the pointer to the right
< b Move the pointer to the left
+ c Increment the memory cell under the pointer
- d Decrement the memory cell under the pointer
. e Output the character signified by the cell at the pointer
, f Input a character and store it in the cell at the pointer
[ g Jump past the matching h if the cell under the pointer is 0
] h Jump back to the matching g

In addition it's common to replace short sequences of brainfuck instructions with substitutions. For example [-] may be replace by a single instruction or some form of run length encoding might be used.

Example Members of the TrivialBrainfuckSubstitution family

  • Ook! is equivalent to TrivialBrainfuckSubstitution("Ook. Ook?", "Ook? Ook.", "Ook. Ook.", "Ook! Ook!", "Ook! Ook.", "Ook. Ook!", "Ook! Ook?", "Ook? Ook!")
  • Alphuck is equivalent to TrivialBrainfuckSubstitution("a", "c", "e", "i", "j", "o", "p", "s")
  • Brainfuck itself could be described as TrivialBrainfuckSubstitution(">", "<", "+", "-", ".", ",", "[", "]")

There are of course, infinitely many members not listed here.


Interpreters for these languages are also generally trivial to write using a regular expression and a lookup table to convert the language to something that can be executed directly. Two simple examples are below.

Ruby Perl
#!/usr/bin/env ruby
eval ';',
     '>' => 'p+=1;',
     '<' => 'p-=1;',
     '+' => 'm[p]+=1;',
     '-' => 'm[p]-=1;',
     '.' => 'putc m[p];',
     ',' => 'm[p]=STDIN.getbyte if !STDIN.eof;',
     '[' => '(',
     ']' => ')while((m[p]&=255)!=0);')
#!/usr/bin/env perl
%c=qw( > $p++;
       < $p--;
       + $b[$p]++;
       - $b[$p]--;
       . print+chr$b[$p];
       , $b[$p]=ord(getc);
       [ $b[$p]&=255;while($b[$p]){
       ] $b[$p]&=255;} );

External links

  • r-fxxk, a Ruby package that can generate interpreters for arbitrary TrivialBrainfuckSubstitution members.