Expand description

A doubly-linked syntax tree.

Offers functionality similar to std::collections::LinkedList.

Example

x = -10
loop
    x = x + 1
    if x
        break
x = 2

can be represented as:

┌──────────┐
│x = -10   │
└──────────┘
│
┌──────────┐
│loop      │
└──────────┘
│           ╲
┌──────────┐ ┌─────────┐
│x = 2     │ │x = x + 1│
└──────────┘ └─────────┘
             │
             ┌─────────┐
             │if x     │
             └─────────┘
                        ╲
                         ┌─────────┐
                         │break    │
                         └─────────┘

Terminology

  • next: loop is the next element of x = -10.
  • previous: x = -10 is the previous element of loop.
  • child: x = x + 1 is the child element of loop.
  • parent: loop is the parent element of x = x + 1.
  • predecessor: All previous elements and parent elements are predecessor elements. A predecessor element may be a previous element or a parent element.
  • successor: The next element if the tree is flattened e.g. x = 2 is the successor of break.

Use-case

I’m using this to contain an AST for compile-time evaluation in my personal WIP language.

Structs

Enums

Constants