Golfcart is a minimal programming language inspired by Ink, JavaScript, and Python – implemented in Go. It’s a toy programming language that I bui

Creating the Golfcart Programming Language

submited by
Style Pass
2021-07-16 08:30:04

Golfcart is a minimal programming language inspired by Ink, JavaScript, and Python – implemented in Go. It’s a toy programming language that I built to use for Advent of Code 2021.

During this project, I read Crafting Interpreters and implemented the Lox programming language using Python, and partially ported Ink using Rust. Another introduction to interpreters I enjoyed was A Frontend Programmer’s Guide to Languages. The Ink blog is also great.

For Golfcart, I began with a desire to design a small programming language that didn’t use semi-colons or automatic semicolon insertion. So, no statements, and everything should be an expression that evaluates to a value. For example:

However, I didn’t realise how restrictive this design goal was. A problem I ran into early was accessing an item from a literal.

I started small, with numbers and math operators (think 1 + 1 * 2). Whenever I implemented a new type or a piece of syntax, I added a specification program with an assertion. When I came across a bug, I sometimes wrote an error program to purposefully throw an error. This project’s tests go test ./... ensure that the specification programs and example programs run without any errors (an assert() call throws an error and quits) and that the error programs all throw errors.

Leave a Comment