-
Notifications
You must be signed in to change notification settings - Fork 0
Home
It's a programming language loosely based on a Brainf**ck. It has many more features and improvements over the base version.
Anything you want except most things ...
java -jar target/interpreter-1.0-SNAPSHOT-jar-with-dependencies.jar src/test/resources/FILE_NAMEand instead of FILE_NAME select one of the given files ( they will show if you press TAB button on your keyboard ) for example
java -jar target/interpreter-1.0-SNAPSHOT-jar-with-dependencies.jar src/test/resources/expressions.bf2You can also run your own bf2 program and run it with the same command and only changing the last path! For example:
java -jar target/interpreter-1.0-SNAPSHOT-jar-with-dependencies.jar C:/my_programm.bf2 Writing in BF^2 is probably nothing like writing in your favourite language of choice.
Let's imagine an array of size x_rows and y_columns.
In BF^2 you're controlling an agent which is on one of the positions specified by the x and y index.
You can perform different operations on the cell like for example:
- take value from cell
- change value in cell
- etc.
Your agent can move all around the board (even on different levels - we will get to it!).
With BF^2 you have to be very creative, because it only uses type: INT,
yet you can do so many things with it - you will see!
At the start of every program you have to declare the size of the array you'll be using.
Both numbers have to be of type(int) and separated by ,
% Declare size (4,4)
4,4
While we're here let's learn how to write comments.
Comment is preceded by %
% This is a comment!
To move the agent around the board we use:
-
>move right -
<move left -
^move up -
vmove down
To put a value in the specified cell we use = operator
4,4
=0 >=1 >=2 >=3
READ_AS_INT
With BF^2 you can perform different arithmetic operations on cells
-
+addition -
-subtraction -
*multiplication -
/division -
!negation
With BF^2 you can perform different values comparisons
-
<?smaller than -
>?bigger than -
=/equals
With BF^2 there are no normal logical values - instead you get:
-
0false -
!0true
To get value that is specified in a particular cell that agent is on we use . operator
5,5
=.+5
v=3*8
v=2/2
v={^^}. + 7
READ_AS_INT
To print out the value from current cell we use @ operator like so:
4,4
>>=5@You can use if to create conditions like so:
1,7
if( ~~ 3 ){=111}
vThere are basically 2 types of loops in BF^2
- do
- do-while
Here is the syntax for the first one:
do{instruction}(number_of_loops)Here is the syntax for the second one:
do{instruction}if(condition)Now we get to the fun stuff! Here come the mighty functions!
5,3
func:SOME_FUNCTION_FOO{>>>>}As you can see, we define it by:
- typing
funcwith:at the end - then there is a
name - we open curly brackets
{}and type the behaviour.
We have 3 function that are built in and help us visualize the output of the program
-
READ_AS_STRINGprints the array as the string -
READ_AS_INTprints the array with numbers -
READ_AS_COLORScalculates black-white representation of the color and prints the array of colors
If you f**k up you code, you will get an error - we promise! For now there are two that you have to be aware of
outOfBoardExceptionfunctionRedefinition