Warning! This documentation is for contributors who wish to help out the project.

It details how the project itself works, not how to write code in it. If you would like to know how to write code in Spindle, please look at the user documentation!
With that out of the way, this document will lay out how Spindle works and will help you contribute to it.

From Meaning to a Result: The Interpreter

The Lexer turns your list of tokens into something called an Abstract Syntax Tree (AST).

An AST is a tree-like data structure that represents the syntactic structure of source code written in a formal language, most commonly programming languages. It's a crucial intermediate representation used by compilers and interpreters to analyze, transform, and optimize code.

Key Characteristics of an AST:

Hierarchical Structure: An AST is a tree, meaning it has a root node and branches that extend downward. Each node represents a specific syntactic construct in the source code. Abstractness: Unlike a token list, an AST doesn't represent every syntactic detail of the source code. It focuses on the essential structure and meaning of the code, abstracting away irrelevant details like parentheses and operator precedence.


The interpreter navigates this abstract syntax tree, actually running the program. For example, the lexer just tells the interpreter there's a for loop, how many times it needs to repeat, and the code inside of it to repeat. But the Interpreter is actually what runs that for loop to produce a result. Errors at this stage typically indicate a critical language bug that needs to be fixed immediately. Once it is finished, the interpreter will return the result of the program. If the program runs successfully but does not intentionally return anything, it returns null. This null value will get filtered out by the shell.py file when it displays your result.