4 ms·
what considerations are the between choosing parser combinators and using a parser generator?
by platz 3y ago
what considerations are the between choosing parser combinators and using a parser generator?
- solomonb 3y agoCombinators are great for little ad-hoc parsers but if you have gotten to the point of laying out a formal grammar you should go with a parser generator.
- massysett 3y agoThe generator requires that you specify a grammar; combinators don’t. Because the generator has your grammar, it can analyze it and tell you if it’s ambiguous. Combinators can’t. Combinators easily support arbitrary lookahead. The combinator libraries I’ve seen in Haskell can provide excellent error messages while parsing, especially if you spend time tweaking them. The generators I’ve seen don’t have error messages as good. Typically with a generator you use a separate lexer, though I suppose you don’t have to. With combinators, you can use a separate lexer, but this is not typical. Generators require you to run a separate tool to generate the parser and maybe the lexer as well. With combinators you just write them in the host language. This impacts your debugging experience.