Building an interpreter in Go: Scanner

I recently discovered a book that walks through the nitty-gritty of creating a programming language (Crafting Interpreters). So far it's been excellent!

The book walks through implementing a language called Lox in two different ways:

I've started following along with the first implementation, but writing in Go rather than Java, since I already know Java and have wanted to try Go for some time.

Then I realized I could compile my Go program to WebAssembly and call it from a web browser!

Here's the first milestone of my project:

This text box accepts Lox code, sends it to WebAssembly, and the page animates the list of tokens returned by the scanner. Try changing the input to see the resulting tokens!

The scanner is the simplest part of a programming language interpreter, so this first post is really about connecting a few different technologies.

A summary of the parts:

Scanner

Compilation to WebAssembly

Visualization in d3.js

My next project is to visualize the parser as it's parsing the tokens into an AST!