Version of brainfuck interpreter with procedures. Usual brainfuck description: https://en.wikipedia.org/wiki/Brainfuck
Tested only on Mac OS X Mojave.
$ ./build.sh all
Now the pbf interpreter should be inside of `bin/` directory.
To run your code:
$ cd bin/
$ ./pbf path/to/your/code.pbf
Command | Description |
---|---|
> |
Move array ptr right. |
< |
Move array ptr left. |
+ |
Add 1 to current array value |
- |
Substract 1 from current array value |
[ |
Begin loop |
] |
End loop |
! |
Exit procedure |
? * |
! if current value is 0 |
; |
States the end of name that should be called |
, |
Read char from stdin |
. |
Put char to stdout |
* โ Not yet tested
Procedure contains some brainfuck code which will be executed when procedure called. Procedure name could containt letters, numbers and underscores. To call porcedure you should put it name and ;
after it. Procedures could call other procedures. You are free to define procedure inside a loop, but this could lead to a severe memory leak.
Definition example:
procedure_name{...}
Call example:
procedure_name;
General usage:
./bin/pbf [--help -h] <filename> [--security none|loop|die]
Argument | Description |
---|---|
-h --help |
Display help message |
<filename> |
Path to filename with code |
--security <arg> |
Set security mode |
Security mode defines what to do when array index is out of range.
To set a security mode put it's name after --security
argument.
Mode | Description |
---|---|
none |
Do none when program exceeds array size. |
loop |
Cycle over array |
die |
Print an error and exit |
Here is code of "Hello, world!" app with use of procdeures.
h{++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++
.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.
------.--------.>+.>.}h;
To test this code:
$ cd bin/
$ ./pbf ../examples/hello_world.pbf
Hello world!
$
You could check out some more examples here
- Implement server mode which will allow to put a sequence of files to run