Ternareso

From Esolang
Jump to navigation Jump to search

Ternareso is an esoteric language taking inspiration from Brainfuck, but focussing on nested ternary statements to implement control flow and looping. The name is a portmanteau of Ternary and Esoteric.

The Java interpreter and in depth README can be found on github

Concept

The language can be described as a single Ternary with the form

<preamble>?success:failure

The preamble is a list of operations as defined below, and the success/failure paths are themselves Ternaries. The ?success:failure section can be omitted to create a simple list of actions in the preamble.

A Ternary is executed by first running the preamble. If the Ternary is a test Ternary (i.e. it has the optional ?success:failure section), then the ? operator indicates testing if the state of the current address on the tape is 0. If the value is 0, the success Ternary is executed, else the failure Ternary is executed.

The program state is represented by an array of integers - the tape - and the current address on the tape. The tape doubles in length when attempting to move beyond the right-hand side, and negative addresses are not supported.

Operators + - Increment the value at the current memory address. - - Decrement the value at the current memory address. < - Move the pointer one address to the left. > - Move the pointer one address to the right. \ - Return 1 level. A single \ indicates that the current ternary will be re-executed, multiple slashes will iterate up the tree. If there are more slashes than layers, the program will exit. All other characters (barring ? and :) are ignored.

Examples

Hello World:

H++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
e>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
l>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
l>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
o>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 >++++++++++++++++++++++++++++++++
W>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
o>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
r>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
l>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
d>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Adding Cell 1 to Cell 0:

+++++>++++?<\\:?<\\\:-<+>\