5 ms·
My rule of thumb: - If you don't need reasonable performance and reasonable error messages, (and your language is expressive enough) use parser combinators. -
by YorkshireSeason 8y ago
My rule of thumb:
- If you don't need reasonable performance and reasonable error messages, (and your language is expressive enough) use parser combinators.
- If you need at least one of reasonable performance and reasonable error messages, (or your language isn't expressive enough for parser combinators) use a parser generator.
- If the code at hand is the interpreter / compiler for a widely used programming language (like Java or C++), get an expert to produce a hand-written parser.
- smaddox 8y agoLast I checked, Elm uses parser combinators and is hailed as having among the best error messages...
- BoiledCabbage 8y agoHow does Elm do it? Because Elms error messages were actually mind blowing. They fundamentally changed my view of what a language and compiler is capable of. It honestly makes every other language laughable. I seriously want anyone who ever designs a language to spend even one weekend playing with Elm just to see what's possible, because prior to that I would have never even considered a compiler could be so helpful. At times it was so clear and accurate it seems like it could've just fixed my code for me.
- zzzcpan 8y agoHand written parsers are actually pretty slow. And higher order parsers are still hand written parsers and usually perform almost exactly the same (except for languages where higher order programming is slow on itself).
- ascar 8y agoMy personal experience is very contradictionary to that statement. Handoptimizing a slow PEG parser, but still using PEG gave me 10% performance increase. Handwriting it on low level libraries, but in the same high level language, gave me a 50,000% performance increase on the average file it had to parse. Task at hand wasn't a programming language though, but more like YAML with only one level of nesting and a lot of quoted strings (which were the bottleneck for PEG in my case).