brainfuck for humans
- Not to be confused with brainfuck 4 humans.
brainfuck 4 humans is a perfectly good esolang, with perfectly good syntax, but I think we can make it easier to read, y’know?
Syntax
Brainfuck for humans has a similar syntax to brainfuck 4 humans, with the important addition of enumerated motions, for example: left 3; is equivalent to left;left;left; in brainfuck for humans, the syntax list is as follows:
(For this example we may assume m is the memory pointer and [m] is a dereference from m, otherwise C like syntax may be assumed)
- right x ; equiv to m += x
- left x ; equiv to m -= x
- zero ; [m] = 0
- add x ; equiv to [m] += x
- subtract x ; equiv to [m] -= x
- input ; equiv to bf(“,”)
- output ; equiv to bf(“.”)
- loop (s) ; while ([m]) { s }
- clear ; loop (subtract 1;);
- set x ; clear; add x;
- set ‘x’ ; set ord(x)
- string “x”; for(I=0; I<strlen(“x”); I++) { set “x”[I]; right 1; }
- read ; file=fopen(m, “r”); fread(m, 1, file_len, file);
- write ; file=fopen(m, “w”); fwrite(m+strlen(m)+1,1,strlen(m+strlen(m)+1),file);
- remark [ x ] ; /* x */
To put multiple statements on the same line use the keyword and or the token &, a line should end with ..
Hello World
The Hello World follows:
zero and right 1. string "Hello World!" and add 10. right 1 zero. left 1 and loop (left 1) and right 1. write.
Which simply embeds a string with a newline at the end with a null terminator at the beginning and end. So that we can go to the beginning of the string by making sure we are inside of it, and then using loop (left 1) and right 1. to go to the left until we reach the introductory NUL and then move forwards to the first character in the string.