DEV Community

Josh Holbrook
Josh Holbrook

Posted on

1

Matanuska ADR 003 - Recursive Descent Parser

This article is a repost of an ADR from Matanuska BASIC, my attempt to write a BASIC interpreter in TypeScript.

Context

My initial strategy for parsing was to use parser combinators. In Rust, this was the nom library. In Typescript, this was typescript-parsec.

This strategy is great for hacking up a simple parser. However, I found that it's a relatively inflexible approach, and requires tuning your interface to match the assumptions of the library.

Crafting Interpreters, meanwhile, details how to write recursive descent parsers. These are "hand-rolled", which on its face can require more work. However, the architecture is relatively straightforward to understand and implement, and it's much more flexible.

Decision

Matanuska BASIC will use recursive descent parsers for both its parser and compiler.

Top comments (0)

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free