Skip to content

Abstract Syntax Tree

AST stands for Abstract Syntax Tree.

It is the structured representation of NXL code.

The AST contains concepts such as:

Program
Statement
Expression
LiteralValue

A program contains statements:

Program {
statements: Vec<Statement>
}

For:

let x = 10
let y = 20

the structure is:

Program
├── VariableDeclaration
└── VariableDeclaration

Current statement concepts include:

VariableDeclaration
Expression
Block
If
Function
Return

Current expression concepts include:

Literal
Identifier
Binary
Unary
Assignment
Call

Source:

let result = a + b * 2

AST:

VariableDeclaration
├── name: result
└── initializer
Binary(+)
/ a Binary(*)
/ b 2

This tree is what the interpreter eventually walks.