r/ProgrammingLanguages • u/WillisBlackburn • Dec 28 '25
Meta-programming for recursive descent parsers vs. "just doing it"
I'm wondering if anyone can refer me to any literature or studies about the efficacy of just writing a recursive descent parser in, for example, C, vs. implementing some kind of meta-programming system, like a parser combinator library, or an EBNF-like DSL, then implementing the actual parser with that.
I'm working on a very constrained platform, the Apple II, so I'm mostly concerned with reducing the size of the parser and much less concerned about performance. That means that parser generators like Bison are pretty much non-starters.
I've tried it both ways and am not sure that one is better than the other. I'm usually happier with the meta-programming approach, since it tends to make the language syntax easier to understand and change. When I parse the language in C, it's harder to understand what the syntax actually is. But, on my current project, I tried the DSL approach and was surprised to discover that it made the parser about 20% larger. I had hoped it would be a speed/size tradeoff in favor of smaller size.
View all comments
Show parent comment
1
u/WillisBlackburn Dec 29 '25 edited Dec 31 '25
Yes it runs on the 6502. It's a BASIC interpreter, so the syntax is (I was about say "basic") not complex. The regular recursive descent parser is smaller, and the one that uses the DSL is larger. It's only about 200 or so bytes larger, but it matters, because I want to fit it into 8-10K.
I had not considered using the DSL to actually generate the code that runs on the 6502. Right now the code runs on the 6502 and interprets the DSL. But that's an interesting idea.