Compost update December '22: Match, If and Booleans

It’s been due time to add control flow into Compost. We have it now! Match Expressions Match expressions allow you to use different flows based on some element’s type. Here’s an example: lets StringOrNothing(thing: @String | ?): String match matchedThing: thing @String: matchedThing.String ? : 'Nothing' It takes a thing that implements the String trait or not. If it implements String, it returns that string. Otherwise it returns the String ’nothing'....

December 20, 2022 · 3 min · sytzez

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