Bolaga

From Esolang
Jump to navigation Jump to search

Bolaga is a stack-based esoteric programming language created by User:Fly in 2026.

Instructions

Instruction Description
>N Pushes a numeric literal `N` onto the stack.
< Pops (removes) the top value.
+ Pops top two values, pushes their sum.
- Pops top two values (`a` first, then `b`), pushes `a-b`.
@ Pops top value and prints it as an ASCII character.
% Pops top value and prints it as a number.
# Reads a line from input; if not empty, pushes the corresponding ASCII value.
$ Reverses the whole stack.
: ... ; Executes loop body repeatedly while stack is non-empty and top value is not `0`.
? Compares top two values: if equal, continue normally; if different, skips next instruction (or skips whole next loop block if next token is `:`).
= Duplicates the top value.
! Stops the program.

Hello, World!

>72>101>108=>111>32>87>111>114>108>100>33$:@;

Truth-Machine

>48#->1$?:=%;$<>0$?%

Shorter version:

>49#?:=@;>0%

Even shorter version:

>49#?:=@;@

Counter from 1 to 10

>11>1:=%>10@>1+?-;

99 bottles of beer on the wall

>99:
    =%>0>10>108>108>97>119>32>101
    >104>116>32>110>111>32>114>101
    >101>98>32>102>111>32>115>101
    >108>116>116>111>98>32:@;
    <=%>0>10>114>101>101>98>32>102
    >111>32>115>101>108>116>116>111
    >98>32:@;<>0>10>110>119>111>100
    >32>101>110>111>32>101>107>97>84
    :@;<>0>10>100>110>117>111>114>97
    >32>116>105>32>115>115>97>80
    :@;<>1>0-+=%>0>10>108>108>97>119
    >32>101>104>116>32>110>111>32>114
    >101>101>98>32>102>111>32>115>101
    >108>116>116>111>98>32:@;<
;

Stack manipulation and other operations

These are some operations you can do to manipulate the stack or perform logical branching that were found by the Discord user @marr_ales_fios

Rightward rotation

$>0$:>1>0-+$>1+$;<

Leftward rotation

>0$:>1>0-+$>1+$;<$

Duplicate second-to-top element

$>0$:>1>0-+$>1+$;<=>0$:>1>0-+$>1+$;<$

Duplicate bottom element

>0$:>1>0-+$>1+$;<$=$>0$:>1>0-+$>1+$;<

Greater than

-:>1:$>0$:>1>0-+$>1+$;<=>0$:>1>0-+$>1+$;<$=$>0$:>1>0-+$>1+$;<->1+>1?:[code];<<$<>0;;<$

Less than

-:>1:$>0$:>1>0-+$>1+$;<=>0$:>1>0-+$>1+$;<$=$>0$:>1>0-+$>1+$;<+>1+>1?:[code];<<$<>0;;<$

Swap first two elements of the stack

=$>0$:>1>0-+$>1+$;<->0-=>0$:>1>0-+$>1+$;<$+=$>0$:>1>0-+$>1+$;<->0$:>1>0-+$>1+$;<$

Duplicate top two elements of the stack

$>0$:
    >1>0-+$>1+$;<=>0$:>1>0-+
    $>1+$;<$=$>0$:>1>0-+$>1+
    $;<->0-=>0$:>1>0-+$>1+$;
    <$+=$>0$:>1>0-+$>1+$;<->
    0$:>1>0-+$>1+$;<>0$:>1>0
    -+$>1+$;<=>0$:>1>0-+$>1+
    $;<$=$>0$:>1>0-+$>1+$;<-
    >0-=>0$:>1>0-+$>1+$;<$+=
    $>0$:>1>0-+$>1+$;<->0$:>
    1>0-+$>1+$
;<$

Shorter version:

$>2:
    >1>0-+>0$:>1>0-+$>1+$;<=
    >0$:>1>0-+$>1+$;<$=$>0$:
    >1>0-+$>1+$;<->0-=>0$:>1
    >0-+$>1+$;<$+=$>0$:>1>0-
    +$>1+$;<->0$:>1>0-+$>1+$
;<;<$

Multiply the top two values

$>0$:
    >1>0-+$>1+$;<>1>0-+>0$
    :>1>0-+$>1+$;<$=$>0$:>
    1>0-+$>1+$;<$>0$:>1>0-
    +$>1+$;<:>1>0-+>0$:>1>
    0-+$>1+$;<$>0$:>1>0-+$
    >1+$;<$=$>0$:>1>0-+$>1
    +$;<+$>0$:>1>0-+$>1+$;
    <;<>0$:>1>0-+$>1+$
;<<$

Divide the top two values (only integer division)

$>0$:
    $>0$:>1>0-+$>1+$;<=>0$
    :>1>0-+$>1+$;<$-$>1+$;
    <<>0$:>1>0-+$>1+$
;<$

Computational class

Bolaga is Turing Complete, via BCT:

10 --> >1?:$2$0;<
11 --> >1?:$1$0;<
0 --> <

wrapping the whole program in : ... ;.
Q.E.D

alternately, one may use a Brainfuck translation, that uses 3 cells. This proof does unlike the above, not use $:

[ --> :
] --> ;
> --> >0$:>1>0-+$>1+$;<$
< --> $>0$:>1>0-+$>1+$;<
+ --> >1+
- --> >1=$>0$:>1>0-+$>1+$;<->0-=>0$:>1>0-+$>1+$;<$+=$>0$:>1>0-+$>1+$;<->0$:>1>0-+$>1+$;<$-

starting the program with:

>0>0>0

where the cell being pointed at by the pointer is the top of the stack

Implementations

Python Interpreter

https://github.com/mmmmosca/Bolaga/blob/main/interpreter.py

D Interpreter

https://github.com/mmmmosca/Bolaga/blob/main/interpreter.d

Rust Interpreter

https://github.com/mmmmosca/Bolaga/blob/main/interpreter.rs