Befinde

From Esolang
Jump to navigation Jump to search
Befinde
Paradigm(s) imperative
Designed by User:zseri
Appeared in 2020
Type system static
Memory system tape-based
Dimensions one-dimensional
Computational class Turing complete
Reference implementation Rust implementation
Influenced by &brainfuck,*brainfuck
File extension(s) .bfd

Befinde is a variation of &brainfuck with relative addressing and fixed-sized cells, which makes writing compilers and interpreters easier, but writing programs maybe harder.

Model

Befinde uses a right-unbounded tape of at least 9bit signed integer cells. Trying to use a negative address and decrementing an indirection level that is zero all produce undefined behavior and will probably or deterministically crash the interpreter. The data pointer is mapped to cell 0.

Commands

Command Action
> Increment the data pointer
< Decrement the data pointer
* Increment the level of indirection
& Decrement the level of indirection
[ If the data pointer is zero, jump after matching ]
] If the data pointer is non-zero, jump after matching [
( Like [, but uses the level of indirection as loop condition
) Like ], but uses the level of indirection as loop condition
. Print the value (data pointer & 0xff) as a byte
, Read a byte from stdin, and set the data pointer to it.

The level of indirection begins at zero. At this point all commands behave normally. When the level of indirection is one, > becomes "Increment the cell pointed to by the (data pointer + 0)". When the level of indirection is two, > becomes "Increment the cell pointed to by the cell pointed to by the (data pointer + 0)", and so on. Therefore, + can be represented as *>& and - can be represented as *<&.

BF translation

Brainfuck programs can be transformed to Befinde according to the following table:

BF Befinde
[ *[&
] *]&
. *.&
, *,&
> >
< <
+ *>&
- *<&

Alternatively, the BF code can be wrapped in *code& and the following table could be used:

BF Befinde
[ [
] ]
. .
, ,
> &>*
< &<*
+ >
- <

Useful patterns

    [<]    get to next zero cell
   *[<]&   set current cell to 0
   *[&>*]  point to zero and increase indirection with 1
   [*>&<]  increment all cells until we find the pointer (the pointer must be positive)
   [*<&>]  increment all cells until we find the pointer (the pointer must be negative)

See also