Execute Brain**** is an implementation of Brainf***.
Other implementations of Brainf***.
RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages.

Below are links to each of the versions of RCBF.

An implementation need only properly implement the following instructions:



Command

Description


 > 
 Move the pointer to the right


 < 
 Move the pointer to the left


 + 
 Increment the memory cell under the pointer


 - 
 Decrement the memory cell under the pointer


 . 
 Output the character signified by the cell at the pointer


 , 
 Input a character and store it in the cell at the pointer


 [ 
 Jump past the matching ] if the cell under the pointer is 0


 ] 
 Jump back to the matching [ if the cell under the pointer is nonzero

Any cell size is allowed,   EOF   (End-O-File)   support is optional, as is whether you have bounded or unbounded memory.




fn main() {
    // example program is current Brain**** solution to
    // Hello world/Text task.  only requires 10 bytes of data store!
    bf(10, '++++++++++[>+>+++>++++>+++++++>++++++++>+++++++++>++
++++++++>+++++++++++>++++++++++++<<<<<<<<<-]>>>>+.>>>
>+..<.<++++++++.>>>+.<<+.<<<<++++.<++.>>>+++++++.>>>.+++.
<+++++++.--------.<<<<<+.<+++.---.')
}
 
fn bf(d_len int, code string) {
    mut ds := []u8{len: d_len} // data store
    mut dp := 0               // data pointer
    for ip := 0; ip < code.len; ip++ {
        match code[ip] {
            `>` {
                dp++
            }
            `<` {
                dp--
            }
            `+` {
                ds[dp]++
            }
            `-` {
                ds[dp]--
            }
            `.` {
                print(ds[dp].ascii_str())
            }
            `,` {
                //fmt.Scanf("%c", &ds[dp])
                ds[dp] = -1 //TODO
            }
            `[` {
                if ds[dp] == 0 {
                    for nc := 1; nc > 0; {
                        ip++
                        if code[ip] == `[` {
                            nc++
                        } else if code[ip] == `]` {
                            nc--
                        }
                    }
                }
            }
            `]` {
                if ds[dp] != 0 {
                    for nc := 1; nc > 0; {
                        ip--
                        if code[ip] == `]` {
                            nc++
                        } else if code[ip] == `[` {
                            nc--
                        }
                    }
                }
            }
            else {}
        }
    }
}