4 ms·
While you are correct that packrat parsers aren't often strictly necessary, they are nice to have in the sense that you don't need to worry about restructuring/
by blihp 7y ago
While you are correct that packrat parsers aren't often strictly necessary, they are nice to have in the sense that you don't need to worry about restructuring/optimizing your grammar. Just write it in the most straightforward way and use it. This is very helpful when prototyping and you are trying out different ideas. You can worry about optimizing it later when you finalize your approach rather than up-front on a parser that will very likely be significantly altered or thrown away. So the argument in favor of packrat parsers can also be a trade-off between execution efficiency and developer productivity rather than simply being necessary.
- wahern 7y agoPEGs are already so simple and easy to use that as a practical matter you don't gain that much from relying on packrat parsing. LPeg, the standard PEG library in Lua, doesn't implement packrat and I don't recall anybody ever complaining about that. In fact, LPeg provides exceptionally useful extensions, like match-time captures, that I think might be incompatible with packrat memoization. Those features make it possible to write grammars for things like ASN.1 BER (with a TLV syntax), which otherwise would be impossible (or at least impractical) for PEGs to parse.