Tree

From Esolang
Jump to navigation Jump to search

Tree - taking branching to new heights

Tree is an esoteric programming language designed by Tslil Clingman in 2008. The author's intentions when designing this language were twofold: Create an esoteric language that looks like a tree and Design a language specifically not Turing Complete.

Tree is a stack based (IFOL) and non-recursive language. The Tree in this language is significant of both the aesthetics and the program's flow control.

Syntax

In Tree, there are three types of constructions: Branches, Leaves and Insects. Branches are the building blocks of the program, they direct the flow of the program as well as cause the program to execute instructions (Leaves). Leaves are the stack manipulators and the I/O of the language. Insects are the flow control manipulators of the language.

The Branches are: | \ / and all function identically.

The Leaves are:

+, -, *, % : Pops top two stack elements, applies operator, pushes result (sum, difference, product, quotient)

@  : Pops the top stack element, records its value. Moves the stack element in the position of that value to the top of the stack.

#  : Pops the top stack element and disregards it

~  : Pushes a duplicate of the top stack element

^  : Pops top stack element and outputs it

v  : Pushes input to the stack

The Insects are:

>, =, !=  : Pops top two stack elements, compares then according to the operator (greater than, equal to, not equal to) and branches if true

Anything that is not a Branch, Leaf, or Insect merely pushes its own value to the stack.

Syntax Usage

Each valid tree program must stem from a single, main, vertical branch ( | ). From then on, it is up to the programmer to place further branches stemming from the main branch or from other branches. The order that branches are traced is as follows:

The program starts at the main branch and moves upwards. It then follows the lowest branch it finds off of the main branch. It then follows that branch, choosing always the lowest possible branch first. Finally, when the lowest possible branches have been explored, it returns the the branch from which the current branch stems, and explores the next lowest branches that have not been followed yet.

Leaves may be placed only at the end of branches. They are executed from lowest to highest, left to right.

Insects may only be placed in between two branches and there may only be one per every two branches.

Numbers are treated specially when being pushed. Whenever a number is reached, all the numbers of that branch are read off, from bottom to top, left to right, to form a single decimal number.

For example:

1  
 32
/

would push 321 to the stack.

Examples

Hello world:

      ^
    ^^|^^
   ^^\|/^^
   H^ |/^^^
     \| e
      |/
   ol~|
     \|
  , 32|
   \/ |
    \ |  W
 l   \| /
 \  d |/  o
  \/ !|r /  
   \/ |\/
    \ |/
     \|
      |


Receives two characters as input and outputs the greater of the two inputs (thanks to Eric D. Culver for pointing out the mistake and to Felipe Sabino for providing the corrected programme below):

      ^
   #  |
    \<|
      | @
    0 |/
     \|
      |  ~
    : | /
     \|/  ~
   :  |  /
    \ | /
     \|/
      |

External Resources

- Typescript implementation