What is the advantage of using a parser generator like happy as opposed to using parser combinators?

后端 未结 5 1264
情歌与酒
情歌与酒 2021-01-31 17:44

To learn how to write and parse a context-free grammar I want to choose a tool. For Haskell, there are two big options: Happy, which generates a parser from a grammar descriptio

5条回答
  •  生来不讨喜
    2021-01-31 18:21

    External vs internal DSL

    The parser specification format for Happy is an external DSL, whereas with Parsec you have the full power of Haskell available when defining your parsers. This means that you can for example write functions to generate parsers, use Template Haskell and so on.

    Precedence rules

    With Happy, you can use precedences to simplify your grammar, whereas with Parsec you have to nest the grammar rules correctly yourself. Changing the precedence of an operator is therefore much more tedious in Parsec.

    Static checking

    Happy will warn you about ambiguities in your grammar at compile time. (Though it's not great at telling you where they are.) With Parsec, you get no warning until your parser fails at run time.

提交回复
热议问题