Splash

Abstract Syntax Trees and Evaluation

Like LISP and other homoiconic languages, Splash stores its code as a tree of data objects, just like any other data in the language. This allows compilation to be completely reversible. Syntax parsers can convert code to a syntax tree or read the syntax tree and generate (textual) code. Multiple syntax parsers can exist, each formatting the code in a different way. Instead of debating over tabs vs. spaces, where to place the brackets, and even the general style of the code (C-like, Smalltalk-like, Lisp S-expressions, etc.), Splash lets each programmer view the code however they choose, and also opens up new UI possibilities for code viewing and editing. Scripts to process code can be written easily, since code is stored as objects like all other data.

Node Structure

Code consists of node objects that represent a function call. This tree structure closely mirrors the Abstract Syntax Tree normally involved in compilation.

Call Nodes reference a function and an array of arguments. Evaluation recursively evaluates the arguments from left to right and applies the function with the arguments.

Literal nodes hold a reference to an object that gets returned when the node is evaluated. It can be compared to QUOTE in LISP.

Var nodes contain a variable name. When evaluated, they return the value of that variable in the current environment.

Do nodes have a list of other nodes. The nodes are evaluated in order. If a node is named, the value to which it evaluates is bound to that variable. The expression evaluates to the last evaluated node.

Interpreter

The interpreter walks the node tree, recursively evaluating the nodes.

Last Modified: 2009-08-05
© Kevin Mehall and the Splash Contributors
Creative Commons License