cbrain
Brainfuck with procedures and numbers, built to be called from COBOL.
Brian Tiffin, 2013 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
Brian Tiffin took Daniel B Cristofani's C interpreter for Paul M. Parks's pbrain in 2013 and made it part of the OpenCOBOL toolkit. pbrain had already added procedures to brainfuck; ( defines one named by the current cell and : calls it. cbrain adds what C programmers type without thinking. Numbers can be written in decimal, and most letters are C's compound assignments between the current cell and the one on its left, which then becomes current. a is +=, m is *=, % is %=.
Read the story
The result reads like a small stack machine on a tape. > 19 % takes the cell to the left modulo 19 and steps back onto it.
The machine
A tape of 64-bit integers.
| Code | Does |
|---|---|
+ - < > . , [ ] | Brainfuck |
( ... ) : | Define a procedure named by the cell; call one |
0-9 | A number; a digit after a digit appends to it |
a s m % ^ & \| r l | Combine the left cell with this one, store it on the left, move there |
d | Divide the left cell by this one, quotient left and remainder here |
* / ~ x | Times 10, divided by 10, not, swap with the left cell |
c o | Copy this cell, or the left one, to the next cell and move there |
@ ! | Store the cell in the register, take it back |
= n # b | Read a number; print in decimal, padded, in binary |
{ ... } | A comment |
g q | Stop |
Example
The hello program spends its arithmetic on the letters.
The hello program spends its arithmetic on the letters. > 7 o a copies 101 next to the 7 and adds them to make 108, l. Procedure 0 moves ten cells left, and : calls it from the 0 at the end. The text is then printed forwards and backwards.
The Easter program reads a year and works out Easter Sunday with the anonymous Gregorian algorithm, all of it in %, d, m and a. For 2014 it prints 2014/4/20.
Further
- esolangs.org/wiki/Cbrain
- pbrain, the language it extends
Ideas it shows
See also
cbrain builds on Brainfuck.
Brainfuck derivatives
Cell-based
Write your own in Run Convert a program from cbrain
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: cbrain.
Command line
shib run cbrain -e '0 (<<<<< <<<<<)
> 72 > 101 > 7 o a c c +++ > 32 > 99 c - > 114 o - > 105 c > 5 a > 32 > 0
: <<< [. >] << [. <] 10 .'shib manual cbrainSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/cbrain.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org