Implementing a Lox interpreter in Rust
For some time I've been looking for an opportunity to do a stream on writing a parser + interpreter for... something. Anything really. I've wanted to implement a parser following matklad's excellent article on Pratt parsing ( https://matklad.github.io/2020/04/13/simple-but-powerful-pratt-parsing.html ), though honestly anything in the area of parsing would do. Well, CodeCrafters have recently released a new challenge in beta that follows Robert Nystrom's Crafting Interpreters book ( https://craftinginterpreters.com/ ), so I jumped at the opportunity. Join me in working through the challenges, or try it yourself first and compare notes after the fact!
You can access the challenge over at https://app.codecrafters.io/join/interpreter?via=jonhoo , which also gives you 7 days free access, or in free source form (without the nice infrastructure) at https://github.com/codecrafters-io/build-your-own-interpreter .
You can find my solution code over at https://github.com/jonhoo/lox
You can join my Discord at https://discord.jonhoo.eu/
0:00:00 Introduction
0:07:36 What is compilation?
0:28:54 The Lox language
0:44:26 Lexing single-character tokens
1:40:31 Lexing multi-character tokens
2:14:18 Lexing numbers
2:47:54 Lexer errors
3:05:37 Lexing comments
3:15:53 Lexing strings
3:29:13 Printing numbers
3:36:09 Outlining the (Pratt) parser
4:16:41 Parsing expressions
5:01:18 Parsing special statements
5:58:56 Extract out statement parser
6:38:42 Finish up expression parser
6:49:34 Printing token trees
6:59:47 Trying out the parser
7:29:13 Aligning with expected output
7:37:02 Tests falling like dominoes
7:50:41 Outro
Live version with chat:
Other Videos By Jon Gjengset
2025-08-01 | Vibe coding complex changes in Rust |
2025-05-30 | Explaining assembly by playing SHENZHEN I/O |
2025-03-10 | Porting the guff plot device to Rust |
2025-01-02 | January 2025 Q&A |
2024-09-21 | Decrusting the quickcheck crate |
2024-08-25 | Implementing a Lox interpreter in Rust |
2024-07-14 | Open Source Maintenance, 2024-07-14 |
2024-05-18 | What's New in Rust 1.72-1.78 Rustacean Station marathon |
2024-05-04 | Q&A May 2024 |
2024-04-05 | Decrusting the tokio crate |
2024-03-09 | Implementing (parts of) git from scratch in Rust |
2024-02-09 | Decrusting the tracing crate |
2024-02-06 | Jon Gjengset Live Stream |
2024-01-14 | Hardware and software [2024 edition] |
2023-12-16 | Q&A December 2023 |
2023-12-15 | Q&A Session |
2023-11-17 | Making the (partial) Rust BitTorrent client more reasonable |
2023-10-19 | Implementing (part of) a BitTorrent client in Rust |
2023-08-26 | Open Source Maintenance, 2023-08-25 |
2023-08-13 | Open Source Maintenance, 2023-08-13 |
2023-08-06 | Open Source Maintenance, 2023-08-06 |