BoolX

From Esolang
Jump to navigation Jump to search
BoolX
Paradigm(s) imperative
Designed by User:Andrea Calligaris
Appeared in 2008
Memory system Cell-based, Queue-based
Dimensions one-dimensional
Computational class Turing complete
Major implementations GitHub
Influenced by brainfuck
File extension(s) .bx

BoolX is an esoteric programming language that works with binary numbers. The cool part is that it allows to do arithmetics and other operations with numbers of theoretically infinite length. Every instruction in BoolX is an ASCII character.

The language has advanced features like if-else statements, labels, jumps and functions.

Compacted program example

_+_+_+_+_+_+^#///////@>>_+_+_+_+_+^+_]=^+^+_
+^+_+^+*]=_+_+_+_+_+^+_]=<^+_+^+^+^#$///////
@>_+_+_+_+_+^+_]=^+_+^+^+^+^+*]=_+_+_+_+_+^+
_]<<#>#$@>>&#$///////@~:&>&</:">">?>^#~!>#~;
!<;;>>?_<<?>?>^>^!>^>_;!>?>^>_!>>^;;!<<?>?>^
>_!>>^;!>?>>^!>>_;;;|+>+>>+<<<':&>&</:">">>#
/@~!<;;>>?_<<?>?>^>^!>_>_;!>?>^>_!>^>^;;!<<?
>?>>_!>>^;!>?>^>^!>>_;;;|+>+>>+<<<':&"#~;/:?
>^<;"!+';>?<!<%_#~;/:?#~!*;-':&>_>^>^+_+_+_+
^+^=>_+_+_+_+^+^=|:"-/'!$>#>#@<&<+$////////'
:>?!+"~;=;$//#>#@<&<?>>>]!>>>>];|-$/////////
'

Output:

1000000 + 11101 = 1011101

(64 + 29 = 93)

Out of the box, like brainfuck, BoolX can only print the corresponding ASCII character of a cell. Because of this, the above program actually contains a function that, calling in turn other functions, manually prints the bits of a cell on screen.

"Hello, world!" program

{ hello_world.bx }
{ Prints "Hello, world!" to standard output. }

_+_+_+^+_+_+^]=  {  72 }
^+_+^+_+_+^+^]=  { 101 }
_+_+^+^+_+^+^]]= { 108 x2 }
^+^+^+^+_+^+^]=  { 111 }
_+_+^+^+_+^+_]=  {  44 }
_+_+_+_+_+^+_]=  {  32 }
^+^+^+_+^+^+^]=  { 119 }
^+^+^+^+_+^+^]=  { 111 }
_+^+_+_+^+^+^]=  { 114 }
_+_+^+^+_+^+^]=  { 108 }
_+_+^+_+_+^+^]=  { 100 }
^+_+_+_+_+^+_]=  {  33 }
_+^+_+^+*]       {  10 }

Official interpreter

The official interpreter is made in C.

To run a program:

boolx <source_file>

from the command line. Program source files are simple text files with the courtesy .bx extension. The interpreter reads Unix (LF) line endings.

The interpreter features a debug mode activable with the -d option which makes it easier to understand what's going on during runtime.

Overview

BoolX works with an array of infinite cells. Every cell can contain from zero to infinite bits. Bits are stored from the least significant bit to the most significant bit. Bits can be either zero or one, but they can also be null (deleted from memory) to indicate the end of the value: if a bit is null, every other bit from there to the most significant bit will also be null (deleted from memory).

At the start of a program every cell has a null value.

The array cursor starts from the first cell. The program can change the value of the cell by manipulating its bits, or it can move to other cells.

BoolX uses if-else statements in order to simplify writing complex programs.

BoolX allows using functions, which when called create a new array of infinite cells. The main program is considered a function. The global queue can be used to store and retrieve values from any point of the program.

The main program starts from the first character of the file. Of course it's possible to create a function intended as "main" and call it at the start of the source. If at the end of some function there is code that's not supposed to be executed, the function must terminate with ~; otherwise there's no need to and the program will terminate once the EOF is reached.

Only recognized symbols are processed, other symbols are ignored; however it's recommended to enclose comments between { and } for readability and future compatibility.

Instructions

Symbol Effect
> go to the next cell
< go to the previous cell
| go to the first cell
+ select the next bit of the current cell
- select the previous bit of the current cell
= select the first bit of the current cell
_ set the selected bit of the current cell to 0
^ set the selected bit of the current cell to 1
* set the selected bit and the following bits (to the most significant bit) of the current cell to null
% set all the bits of the current cell to null and go to the first bit
] print the ASCII character corresponding to the current cell value
[ get an ASCII character from the user and save its corresponding binary value to the current cell
# enqueue in the global queue the value (the bits) of the current cell
& dequeue a value from the global queue and save it to the current cell; = is implicit
? if condition which tests if the current bit is equal to 1; for 0 just have an else condition immediately after: ?!
" if condition which tests if the current bit is null
! else condition
; end of an if statement or an if-else statement
: set a label; its position will be registered in a dedicated array before execution of the code
/ move the global label cursor to the next global label cell
\ move the global label cursor to the previous global label cell
$ move the global label cursor to the first global label cell
' jump to the label pointed to by the label cursor (basically a goto)
@ call a function jumping to the label pointed to by the label cursor (~ will then return)
~ terminate the function / main program
{ start of comment (comments can be nested)
} end of comment

If-else statements example

=? +    { first IF condition: if the first bit is
	  equal to 1: }
  ? * ; { a secound IF condition is done on the next bit;
	  if it's equal to 1, make it null }
  ! > ; { otherwise go to the next cell }
 ;      { end of the first IF condition }

External resources

  • More info and examples: GitHub