-
Intended to be minimalistic yet (somewhat?) useable, Bologna is an un-intuitive, ridiculous language.
-
Bologna is a superset of the BrainFuck programming language, and therefore retains the original 8 tokens from BrainFuck (
+-<>[],.
)
That is, somewhat gross, and probably not your first choice.
- Bologna was made to see what could be acheived with a very simple language.
- No conventional variables. All values are stored at some index in the 30,000 signed 8-bit integer array
- No functions
- No data types, as everything is stored as an unsigned 8 bit integer
- Interpreted directly from your file at runtime
- So dumb its cool
- Download the latest Bologna release here
- In the same directory where you downloaded Bologna, run
bash bologna.bash my_bologna_file.bf
Pointer Manipulation | |
---|---|
>x |
Shift pointer right x times |
<x |
Shift pointer left x times |
:x |
Move pointer to memory index x |
Numerical Operations | |
_ |
Set the byte at the pointer to zero |
+x |
Add x to the byte at the pointer value |
-x |
Subtract x from the byte at the pointer |
*x |
Multiplty the byte at the pointer by x |
/x |
Integer division of the byte at the pointer by x |
Input / Output | |
, |
Takes a character input and stores it in the byte at the pointer |
. |
Prints the character at the byte at the pointer |
Loops | |
[ |
If the byte at the pointer is zero, jump past matching ] |
] |
If the byte at the pointer is non-zero, jump back to command after matching [ |
{ }x |
Repeat code inside the braces x times |
Memory Indexing | |
# |
Get the value of the pointer's byte |
#x |
Get value of the byte at index x |
Query Operator | |
?(x<y){} |
If the (boolean statement) is true, run the code inside the {} braces |
Logical Operators | Note: Can only be used inside of the '( )' of a Query |
> |
Greater than |
< |
Less than |
= |
Equal to |
! |
Not equal to |
Other Operators | |
~ |
End program execution |
"comments" |
Comment (By default text is ignored, but comments ignore commands) Ex: "+-.<>" will not execute any of the operators) |
Initially, the program pointer points to the beginning of the memory array at index 0.
<x
Shifts the pointer to the left x
number of times.
>x
Shifts the pointer to the right x
number of times
:x
Shifts the pointer to memory index x
, regardless of its current position.
,
Takes a single character input through stdin
and stores it in the byte at the pointer
.x
Prints the character at the pointer's byte x
times.
Special Case
#x.
Prints out the character value of the byte at memory index x
.
- See memory indexing for more information on this topic.
_
Sets the value of the current pointer to zero
*x
Multiplies current pointer value by x
/x
Divides the current pointer value by x
. Note that all division is integer division.
[ ]
BrainFuck's original loop implementation.
{ }x
Repeats code inside the indices x
times, or { }#5
repeats as many times as the value at memory index 5.
Note that nested loops are not yet supported.
#
Gets value of current pointer (will be treated as if an integer was in the code)
{}#
A for loop that repeats as many times as the value of the current pointer
+#
Adds current pointer value to the current pointer value
#x
Every case from above applies, but rather than referencing the current pointer, it references pointer at memory index x
Memory is an array of signed 8-bit integers
-------------------------------------------
#x Represents the value at memory index x
EX: #1 = mem[1] = some_value
-------------------------------------------
>#1 (Move pointer right #1 times)
<#15 (Move pointer left #15 times)
+#4 (Add #4 to the current pointer)
-#6 (Subtract #6 from the current pointer)
.#91 (Print current pointer #91 times)
#12. (Print the value of #12)
:#7 (Move pointer to index matching the value at memory index 7)
*#2 (Multiply current pointer value by #2)
/#8 (Divide current pointer value by #8)
{}#3 (For loop repeats #3 times)
?(){}
The query operator evaluates the expression inside of the parentheses, and only executes the code inside of the braces if the expression evaluates to true.
- Note that whitespace inside of '()' or between '?, (), {}' is not allowed.
- Example:
?(a < b){+}
is not permitted due to whitespace inside the logical expression ? (a<b) {+}
is also not permitted due to whitespace between the? (
and) {
CODE
====================================
"Set mem[0] to 65 (ASCII A)"
:0 +65
"Set mem[1] to 10"
:1 +10
"Set mem[2] to 10"
:2 +10
"If ('10'='10')then{.}"
?(#1=#2){.}
EXPECTED OUTPUT
====================================
A
<
Less than operator>
Greater than operator=
Equal to operator!
Not equal operator
?(10<11){+} "This is true, the '+' will be executed"
?(10>11){+} "This is false, the '+' will not be executed"
?(10=11){+} "This is false, the '+' will not be executed"
?(10!11){+} "This is true, the '+' will be executed"
~
Terminates program execution immediately.
" "
Ignores commands inside of quotes.
- By default, characters which are not operators are already ignored
- Comments allow usage of operator characters without execution
"Add 6 to memory index 10 with :10 +6" <- The operators here will not be executed
10: +6 <- The operators here will be executed
- Add Nested for loop support
{ { }y }x
(They currently dont work at all...) - Fix while loop
[ ]
bug - currently, while loops will fail to exit under certain conditions.
hello_world.bf
+72._+69._+76._+76._+79._+32._+87._+79._+82._+76._+68._+10.
"EXPECTED OUTPUT:
==========================================================="
HELLO WORLD
An example of a for loop that counts from 0 to 9
counter_example.bf
"Go to memory index 3, then add 10"
:3 +10
"Go to memory index 0, then add 48 (ASCII '0' character)"
:0 +48
"Print value and increment byte by one. Repeat '#3' times, which evaluates to 10 repitions."
{.+}#3
"Zero the index, add 10 (ASCII linebreak), and print it out"
_ +10 .
"Expected Output:
========================================================================================="
0123456789
(Unfinished) Tic Tac Toe example written in Bologna
tic_tac_toe.bf
FULL TIC TAC TOE AVAILABLE IN /bologna_files
"EXAMPLE (PORTION) OF CODE:
===================================================================================="
"Print: Pick a cell 1 - 9) "
+80. _ +105. _ +99. _ +107. _ +32. _ +97. _ +32. _ +67. _ +101. _
+108. _ +108. _ +32. _ +49. _ +32. _ +45. _ +32. _ +57. _ +41. _ #11.
"Take a character input and store in memory index 50"
:50 _ ,
"Move to the index of the character the user specified. Write an 'O' in the cell"
:#50 _ +#13 :0 #10.
"EXAMPLE OUPUT:
===================================================================================="
-------
|X|O|X|
-------
|O|5|6|
-------
|7|8|9|
-------
Player 1 - Pick a Cell 1 - 9) 5
-------
|X|O|X|
-------
|O|X|6|
-------
|7|8|9|
-------