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.




      bf$ = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>->+>>+[<]<-]>>.>" + \
      \     ">---.+++++++..+++.>.<<-.>.+++.------.--------.>+.>++.+++."
      PROCbrainfuck(bf$)
      END
 
      DEF PROCbrainfuck(b$)
      LOCAL B%, K%, M%, P%
      DIM M% LOCAL 65535
      B% = 1 : REM pointer to string
      K% = 0 : REM bracket counter
      P% = 0 : REM pointer to memory
      FOR B% = 1 TO LEN(b$)
        CASE MID$(b$,B%,1) OF
          WHEN "+": M%?P% += 1
          WHEN "-": M%?P% -= 1
          WHEN ">": P% += 1
          WHEN "<": P% -= 1
          WHEN ".": VDU M%?P%
          WHEN ",": M%?P% = GET
          WHEN "[":
            IF M%?P% = 0 THEN
              K% = 1
              B% += 1
              WHILE K%
                IF MID$(b$,B%,1) = "[" THEN K% += 1
                IF MID$(b$,B%,1) = "]" THEN K% -= 1
                B% += 1
              ENDWHILE
            ENDIF
          WHEN "]":
            IF M%?P% <> 0 THEN
              K% = -1
              B% -= 1
              WHILE K%
                IF MID$(b$,B%,1) = "[" THEN K% += 1
                IF MID$(b$,B%,1) = "]" THEN K% -= 1
                B% -= 1
              ENDWHILE
            ENDIF
        ENDCASE
      NEXT
      ENDPROC
 