# Branchback

Branchback is an esolang where data is stored on a complete binary tree.

## Description

The code is written with the root node, then the nodes one level down, left to right, and so on until reaching the bottom. Each node has two children until the second row from the bottom, where some may have one or no children, and none of the nodes at the bottom have any children. This data structure is called a complete binary tree.

Any nodes of the tree which don't have two arguments have at least one empty argument. If the node is an instruction which takes arguments, the empty argument is given a dummy value. Otherwise, the node doesn't care about what's underneath it.

The code is executed starting at the root node. From there, the code moves up and down the left and right branches in the way indicated by the code. Without any jump instructions, and if the root node contains a function, the code will move down the left branch first, continuously moving down the left branch until it reaches a value. Then it will move 1 node up continuously, changing the value accordingly until it reaches the root node. After that, it will go down the right branch, continuously moving down the right branch until it reaches a value. Then it will move 1 node up continuously until it reaches the root node again, and the final answer is this value.

There are four general kinds of instructions which can be in the nodes:

- values, which take no arguments
- input-output instructions, which act like values except for dealing with input and output
- functions, which take only two arguments and return an operation which combines the two arguments in some way
- jump instructions, which

Instruction Token | Action | Value of Empty Argument |
---|---|---|

Values | ||

decimal numbers (digits 1 to 0) | puts that number into the node of the tree | N/A |

strings within quotes | puts that string value within a node, with `""` representing a single quote
| |

na | acts the same as an empty argument | |

Input-Output Instructions | ||

readstring | requests a string as an input value | N/A |

readint | requests an integer as an input value | |

prints left, then right | empty string | |

println | prints left, then right, with a newline at the end | |

Functions | ||

add | left + right | 0 |

sub | left - right | |

mul | left * right | |

div | left / right, no remainder | 1 |

mod | left modulo right (remainder of division) | |

sign | changes sign of left to sign of right | |

max | returns maximum of left and right | |

min | returns minimum of left and right | |

cont | takes in the value which led there and passes it upwards, ignoring the other branch | |

Jump Instructions | ||

jleft-MOV-VAL | jumps MOV nodes down the tree if left value and right value are not equal, with positive values indicating left and negative values indicating right, and acts like the value VAL | N/A |

jright-MOV-VAL | jumps MOV nodes down the tree if left value and right value are not equal, with positive values indicating right and negative values indicating left, and acts like the value VAL | |

jup-MOV-VAL | jumps MOV nodes up the tree if left value and right value are not equal, and acts like the value VAL |

## Computational Class

I know better than to randomly assume the computational class at this point. However, the language doesn't really have any memory, so it's probably not Turing-complete.

## Valid Examples of Code

### Adding One and Two

add 1 2

### Hello World

All of these should print `Hello, World!`

print "Hello, World!"

print na "Hello, World!"

print "Hello, World!" na

print "Hello, " "World!"

print "Hello," " World!" na na na na na na na na na na na na na na na na "Batman!"

print "Hello, " "World!" "na na na na na na na na na na na na na na na na Batman!"