4 ms·
I suspect that this is the more common opinion, especially when the desired outcome is real world use. Recursive descent is surprisingly ergonomic and clean if
by fredrikholm 1y ago
I suspect that this is the more common opinion, especially when the desired outcome is real world use.
Recursive descent is surprisingly ergonomic and clean if one gets the heuristics right. Personally I find it way easier than writing BNF and its derivatives as you quickly get into tricky edge cases, slow performance and opaque errors.
- hombre_fatal 1y agoYeah, grammars seem easy at first, but they're full of arcane knowledge like writing your tokens with the right affinity and greediness, ensuring back tracking is performant, and that you'll get good error messages. Same with parser combinators. Not until a bunch of trial and error do you build up the intuitions you need to use them in production, I think. Despite two decades of using those, I've found it much simpler to write my own scanning or RD parser.
- WalterBright 1y agoD was originally designed to require only one token lookahead, but it turns out to get the aesthetic I wanted, that arbitrary lookup was needed. That turned out to be very handy when adapting it to compile C code. Much of the parser code, if you compare the code with the BNF grammar, is a 1:1 correspondence. Super easy to do.