cobrain, another esolang

cobrain. A script, single character read interpret programming tool, ok, toy. …

Well met,

I'm finding single character read interpret programming tools, errr, toys, (script), to be a lot of fun.

Here's some cobrain. Similar to cbrain, but different.


co: 1028
co: help
10-28 received, cobrain v0.21, Apr 2013, expect 42
Daniel B Cristofani posted pbrain.c, modified for cbrain and then cobrian by Brian Tiffin
Tectonics:
cobc -x cobrainmain.c subcranial.cob -lreadline -g -debug -fdebugging-line
cobc -x cobrainrun.cob subcranial.cob cobrain.c -lreadline

and more general help


$ ./cogb
Welcome to cogbrain v0.21
co: help
cobrainhelp received +0000000000 and will stop run

===From bf===
p, increment current cell
m, decrement current cell
>, advance data cell index up 1
<, retreat data cell index down 1
[, if current cell zero, skip source index forward to next ]
], if current cell non-zero, skip source index backwards to previous [
., output current cell
,, accept key value to current cell

===cobrain adds===
digits, 0 though 9, if last operation was digit, scale current cell up by 10 and add in, otherwise zero out and add in digit
_, negate current
(, enter block on true (non zero), till nested close marker )
{, enter block on false (zero), till nested close marker }
+, add current cell into previous cell and retreat
-, subtract current cell from previous cell and retreat
*, multiply current cell by previous cell into previous cell and retreat
/, divide previous cell by current cell leaving quotient in previous and remainder in current, no retreat
^, bitwise xor current cell with previous cell and retreat
&, bitwise and current cell with previous cell and retreat
|, bitwise or current cell with previous cell and retreat
~, bitwise not of current cell into current cell
r, right shift previous cell by current cell bits and retreat
l, left shift previous cell by current cell bits and retreat
%, compute modulus of previous cell by current cell into previous cell and retreat
@, fetch current cell value and place in memory register
$, address of current to memory register
`, dereference current into current
c, compare current cell value to zero and place sign in current
!, store content of memory register in current cell
s, swap current cell with previous
o, copy previous cell over to next and advance
d, duplicate current cell to next cell and advance
n, output current cell as integer
#, output current cell as formatted integer
b, output current cell as base 2
=, input integer and place value in current cell
', scan forward to ', call that COBOL module, passing frame based on current, replacing frame with RETURN-CODE
?, display memory up to current
t, toggle step trace
g, goback
q, quit
reserved word 'help', calls "cbrainhelp", the OpenCOBOL module using cbrain quoted string.
reserved word 'file ' loads script using rest of source text as filename.

This allows for things like


29548 $ > ! 1 'system'

"ls" <[<]>$[>] > ! 1 'system'

which both call the system function with a char* to "ls"

Batch sums (with tests)


0 [S sum back till 0, and T test, ok on zero.]

:S + < [> + <] > ;
:T o - (98. 97. 100.) {111. 107.} 10. ;

0 [Test zero after subtract ok, non-zero bad]
42 42 T

0 [and a bad, just to see it]
42 24 T

0 [Adds up to 1158, we hope]
123 234 345 456 S n 1158 T

01 {Adds up to 45}
0 1 2 3 4 5 6 7 8 9 S n 45 T

0 (Adds up to -42)
0 100 >0 121 - 200 >0 221 - S n >0 42 - T

0 [Sum should be 338350]
0 1 4 9 16 25 36 49 64
81 100 121 144 169 196 225 256 289
324 361 400 441 484 529 576 625 676
729 784 841 900 961 1024 1089 1156 1225
1296 1369 1444 1521 1600 1681 1764 1849 1936
2025 2116 2209 2304 2401 2500 2601 2704 2809
2916 3025 3136 3249 3364 3481 3600 3721 3844
3969 4096 4225 4356 4489 4624 4761 4900 5041
5184 5329 5476 5625 5776 5929 6084 6241 6400
6561 6724 6889 7056 7225 7396 7569 7744 7921
8100 8281 8464 8649 8836 9025 9216 9409 9604
9801 10000 S n 338350 T

q

giving


$ ./cogb sumwithtest.cb
ok
bad
1158ok
45ok
-42ok
338350ok

(the first bad being on purpose)

Source code is at http://opencobol.add1tocobol.com/cobrain/cobrain-0.42.tar.gz

if you noticed cogbrain, it's just an experimental computed goto implementation versus function call cobrain, but still cobrain. (Saved over 6 billion function call overheads running hanoi.cb). but when it's meant as a toy, does it matter?

computus.cb computes Easter for the year entered as input


0 [When is Easter?]
69 97 115 116 101 114 32 102 111 114 32 119 104 97 116 32
89 101 97 114 63 32 >0 <[<]>[.>]<[<]
=

:B <<<<< ;
:F >>>>> ;
:C <B @ F>> ! ;

d 19 % o 100 / o 4 /
<<< @ >>>> ! 8 + 25 / <
> ! o - p 3 / <
C 19 * C + <<<< @ F ! - o - 15 + 30 %
B @ F > ! 4 /
o C + 2 * 32 + <<< @ >>>> ! - o - 7 %
<<< @ >>>> ! 11 * <BB @ FF>> ! + o 22 * + 451 / <
o B @ F > ! + o 7 * - 114 +
d 31 % p
o 31 /

<BBB n FFF> 047 . < n 047 . < n 010 . q

giving


co: file computus.cb
Easter for what Year? 2014
2014/4/20
bye

Fun.

Cheers,
Brian

Leave a Reply

Your email address will not be published. Required fields are marked *