Skip to content

Instantly share code, notes, and snippets.

@alphazero
Last active March 16, 2017 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alphazero/b036586011957dc5b36cb104fc998fb0 to your computer and use it in GitHub Desktop.
Save alphazero/b036586011957dc5b36cb104fc998fb0 to your computer and use it in GitHub Desktop.
Specfication for BFLX
language specification for level extended brainfuck
rev alpha.0
-- what
Yet another riff on the brainfuck language.
-- program structure
A bflx program is a sequence of byte codes (with ASCII semantics) of minimum length of 1.
-- memory model
- bflx maintains a list of data cell arrays.
- a data cell has unsigned 8-bit integer semantics.
- all bflx programs have at least one data array (index 0).
- data cell array index underflow semantics are the same as a circular buffer.
- Index overflow will dynamically extend the given cell array.
- data cell arrays (levels) are navigated via cursor commands.
- bflx runtime maintains a single register.
-- data cursor commands
^ : level up
- move up to previous data array index.
- if already at level 0, then go to the last.
v : level down
- move down to the next data array index.
- if already at level max, allocate a new layer and move to that.
- data array levels are stateful and maintain their own data index.
< : move back
- decrement data index of current data array.
- if data index is 0, then move index to the last position (per circular buffer semantics).
> : move forward
- increment the data index of current data array.
- if index overflows the array, grow it.
| : initial position
- set data index of current level to 0.
. : final position
- set data index of current level to last position.
-- Data access commands
+ : increment data cell by 1.
- : decrement data cell by 1.
~ : invert bits of current data cell
-- Register commands
# : copy current data cell to register
% : write register to current data cell
-- embedded data
$ : treat all bytes until matching '$' as embedded data. data index incremented by length of embedded data.
-- IO commands
? : read a byte from stdin unto current data cell. data index incremended by 1.
! : write current data cell byte to stdout. data index incremented by 1.
n : write the numeric value of current byte (per printf("%d", b) i.e. byte value 27 -> "27")
N : write the zero-padded numeric value of current byte (per printf("%03d", b) i.e. byte value 27 -> "027")
# control flow
[ : if current cell value is 0, move to next command after the matching ']'.
] : if current cell value is not 0, move to the next command after the matching '['.
-- example: hello world!
$hello world!$|!!!!!!!!!!!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment