Creating a Compiler for Compost using Rust, Part 1: Lexical Analysis

I’ve set out to write a compiler for Compost, the experimental programming language I came up with about a month ago. The repository for it can be found on GitHub and there is also a playground available where you can try out the language. This is the first part of a series of blogs detailing my experience of writing my first compiler. Structure of a Compiler Before embarking on this journey, I did some research on how compilers normally work....

November 27, 2022 · 7 min · sytzez

Creating a Compiler for Compost using Rust, Part 2: Syntactic Analysis

In the previous post, I described how I implemented lexical analysis for Compost. The next phase in compilation is syntactic analysis, which turns the string of tokens into an ‘abstract syntax tree’. It also throws meaningful errors when wrong syntax is used. The Abstract Syntax Tree An abstract syntax tree (AST) represents the code at the level of statements and expressions. Every type of statement and expression has its own data structure, which can contain other statements or expressions, forming a tree of data structures....

November 27, 2022 · 8 min · sytzez

Creating a Compiler for Compost using Rust, Part 3: Semantic Analysis

In the previous installment of this series, I described how I turned the tokens into an abstract syntax tree (AST). The AST contains all statements, expressions and types of the program, but doesn’t link the together. All the names of variables, modules, traits and functions are simply Rust Strings without any meaning beyond that. To give meaning to these names we can use semantic analysis, which resolves the names into references to the right piece of information in our program....

November 27, 2022 · 10 min · sytzez