tbf

From Esolang
Jump to navigation Jump to search

tbf is a language that can be used to write Brainfuck programs in a simpler way. Programs written in tbf are compiled to Brainfuck, where they then can be compiled using any BF compiler.

Syntax

tbf includes the following constructs:

General:

  • Everything is case insensitive (“hello” is the same as “Hello” as “HELLO” etc)
  • Every command has to end with a ”;”
  • You can do comments by using ”%” to start a comment. The comment will end at the end of the line (as in Bash for example).
  • All new identifiers (variables) will be automatically allocated and initialized as zero.

Basic commands:

  • “moveto <identifier>;” moves the tape at the place designed by <identifier>
  • “inc;” increment the current position
  • “dec;” decrement the current position
  • “put;” output the current position as a character on the screen
  • “get;” read a character from keyboard into the current position
  • “zero;” set the current position to zero
  • “print;” output the string that starts at the current position (yes tbf has strings. I'll get into more detail later)
  • “Add <identifier>” adds the value stored at <identifier> to the current cell. Be carefull, there still might be a bug that makes your program go into an infinite loop when you add an identifier to itself. I meant to fix it, nut I am not sure if I ever did.
  • “Sub <identifier>” similar to add, but does subtraction
  • “Store <identifier>” store the value that is designated by <identifier> at a the current position
  • “Retrieve <identifier>” restore the value of an <identifier> from the current cell

Identifier can consist of the following:

  • names of variables in the form [A-Z a-z _][A-Z a-z _ 1-9]*
  • integer literals (e.g 10, 11, -1234 etc)
  • single characters in ' '
  • Strings in ” ”
  • “new” this identifier always indicates a newly produced value
  • ”.” to current position
  • ”&<identifier>” yes this works to, take a c-guess what it does

More complex constructs:

  • “While <test> do <expr>” Loops. When you enter the loop the tape will point to identifier that was used in the test
  • “Begin <expr>;[<expr>;…] end” blocks of code, used to group several instructions
  • “declare <identifier> as <identifier>” this introduces an alias for a previously used identifier

Tests:

  • “isneg <identifier>” tests whether an identifier is negative
  • “ispos <identifier>” tests whether an identifier is positive
  • ”<identifier>” tests for zero


Example Programs

Hello World

    moveto "Hello World!\n";
    print;


(Yes, strings are this simple)

Output all chars from 255 backwards

    while 255 do begin
       put;
       dec;
    end 


Cat program

    moveto new;
    inc;
    while . do begin
       get;
       put;
    end


Multiplication of two numbers as a macro

   define mult(a,b) as begin
      zero;
      moveto hlp;
      add a;
      while hlp do begin
         dec;
         moveto mult;
         add b;
      end
   end
   moveto new;
   mult(10,9);
   put;


See also

External resources