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

Sketch for a new programming language: Part 2

A solution to inheritance I’ve had some more thought about my programming language “Compost”. It might have its own solution to the old problems of object oriented programming, mainly class inheritance. One of the problems class inheritance tries to solve is code reuse between classes. In OOP, you’d solve this by creating a superclass which contains the methods which are shared between classes. The classes that use those method then need to inheritd from that super class....

October 16, 2022 · 5 min · sytzez

Sketch for a new programming language

I’m coming up with the spec of a new programming language. Working title: “Compost”. Don’t worry, it’s just for fun. For now this is just a first sketch of the ideas I had today. They are subject to change. The main idea of the language is ultimate composability and recomposability. It forces the programmer to think in terms of the minimum amount of dependencies required for each part of the code, and makes each part as reusable as possible....

October 13, 2022 · 6 min · sytzez