esolang

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

Expected: Hello cbrain niarbc olleH

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.

CodeDoes
+ - < > . , [ ]Brainfuck
( ... ) :Define a procedure named by the cell; call one
0-9A number; a digit after a digit appends to it
a s m % ^ & \| r lCombine the left cell with this one, store it on the left, move there
dDivide the left cell by this one, quotient left and remainder here
* / ~ xTimes 10, divided by 10, not, swap with the left cell
c oCopy this cell, or the left one, to the next cell and move there
@ !Store the cell in the register, take it back
= n # bRead a number; print in decimal, padded, in binary
{ ... }A comment
g qStop

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

Ideas it shows

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 cbrain

Source

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