[Haskell-cafe] ANNOUNCE: Grempa 0.1.0, Embedded grammar DSL and LALR parser generator

Olle Fredriksson fredriksson.olle at gmail.com
Mon Sep 6 13:45:12 EDT 2010

Hello everyone,

I'm pleased to announce the first release of Grempa:

    A library for expressing programming language grammars in a form similar
    to BNF, which is extended with the semantic actions to take when
    a production has been parsed. The grammars are typed and are to be be
    with the LALR(1) parser generator, also part of the library, which can
    generate a parser for the language either at compile time using Template
    Haskell, producing fast parsers with no initial runtime overhead, or
    dynamically, which has the initial overhead of generating the parser,
    can be used for example when the grammar depends on an input.

Here is a small example (from Ex1 in the examples directory) of what a
may look like:

    data E = Plus E E
           | Times E E
           | Var
           | ...

    expr :: Grammar Char E
    expr = do
        e <- rule [ Plus  <@> e <# '+' <#> t
                  , id    <@> t
        t <- rule [ Times <@> t <# '*' <#> f
                  , id    <@> f
        f <- rule [ id    <@ '(' <#> e <# ')'
                  , Var   <@ 'x'
      return e

The corresponding BNF grammar is the following:

    E ::= E + T
        | T
    T ::= T * F
        | F
    F ::= ( E )
        | x

Generating a parser from the grammar is simple:

    parseExpr :: Parser Char E
    parseExpr = $(mkStaticParser expr [|expr|])

There are a few other examples in the examples directory of the package,
notably a grammar and parser for a simple functional language similar to

It is possible to generate random input strings and their expected outputs
for grammars written using Grempa which makes it possible to test the
parsers with QuickCheck.

The package and documentation (should be up soon) can be found here:

Please get in touch with me if you have any comments, issues, questions, bug
reports or would like to contribute to the project. I would love to get some
more people involved in the project, as there are many areas of the library
could be improved.

Thanks to Daniel Gustafsson and everyone else at Chalmers Uni for valuable
input and getting me into Haskell (respectively).

Olle Fredriksson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100906/23ddfa0b/attachment.html

More information about the Haskell-Cafe mailing list