1. 41

  2. 3

    The article has a section titled “Why are parser combinators useful?”, but I still don’t get why, comparing to the alternative that is parser generators. Is the advantage that it is compositional?

    1. 3

      Another advantage of parser combinators is that you can use them without leaving your programming language. You can also add new combinators on the fly.

      One advantage of parser generators over parser combinators is their ability to analyze the input grammar. Parser generators will stop you from building a parser that might recurse infinitely (e.g., when using left-recursive rules in a top-down parser), whereas parser combinators won’t.

      1. 4

        Yeah, the article is a big mess. The advantages of parser combinators is the compositionality, as you said, which in turn makes them easy to build and reason about. It’s also very elegant to use them because you can return lists of interpretations (and an empty list if the parser failed to parse the data), but that is pretty advanced.

        As so often with functional approaches, though, the downside is that you quickly end up with huge call-stacks.