Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

0xf104a/procedural-brainfuck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

procedural-brainfuck

Description

Version of brainfuck interpreter with procedures. Usual brainfuck description: https://en.wikipedia.org/wiki/Brainfuck
Tested only on Mac OS X Mojave.

Building it

$ ./build.sh all

Now the pbf interpreter should be inside of `bin/` directory.

Running your code

To run your code:

$ cd bin/ 
$ ./pbf path/to/your/code.pbf

Command table

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

Procedures

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;

Arguments

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

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

Hello, world!

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

ToDo

  • Implement server mode which will allow to put a sequence of files to run