Happy

[Mr Happy]

The Parser Generator for Haskell


What is Happy?

Happy is a parser generator system for Haskell, similar to the tool `yacc' for C. Like `yacc', it takes a file containing an annotated BNF specification of a grammar and produces a Haskell module containing a parser for the grammar.

Happy is flexible; unlike `yacc', you can have several Happy parsers in the same program. Happy can work in conjunction with a lexical analyser supplied by the user (either hand-written or generated by another program), or it can parse a stream of characters directly (but this isn't practical in most cases).

The current public version of Happy is 0.9a, which was released on February 28, 1996. It is available from

ftp://ftp.dcs.gla.ac.uk/pub/haskell/happy

You can also read online the current Happy manual.


Supported Source and Target Languages for Happy

Compiling Happy

Happy is written in Haskell 1.2, and internally uses the Request/Response streams for IO, which are unfortunately not supported under Yale Haskell. However, Happy will compile under You can also use Gofer 2.30b with the supplied prelude to interpret the Happy src code. However, we recommend that you use one of the above compliers to produce a Happy binary, even if you use the output inside Gofer.

We now have a port of Happy to nhc, thanks to Niklas. Contact <andy@dcs.gla.ac.uk> for a copy.

Using Happy Output

The Happy output is standard Haskell 1.2. It will work under any Haskell compiler. It will also work with Gofer 2.30b, even without our extended prelude. There is also an option for producing even faster parsers that exploit the unboxed types as supported by GHC. (Obviously this is only applicable to GHC users.)


Changes in the latest release of Happy

 o A performance problem was fixed, and Happy should be much faster than before. The largest grammars we have take no more than a few minutes to process.

 o Generated parsers will be 5-10% smaller.

 o Happy now compiles with ghc-0.26. A couple of problems that we fixed here have been the source of about 1 bug report per day over the last few weeks :-)

 o

Support for monadic parsers via %monad. You use it specify a monad, and the whole parser is lifted over this monad. Example: Lift over the error monad, and make happyError return failure in this monad, rather than call error. You now have a bullet proof parser. Full details are in the documentation.

 o

A minor change to the syntax, while the old syntax is still supported.
	f :: { <type> }
	f : ...
	  | ...
	  etc.
can now be written
	f :: { <type> }
	  : ...
	  | ...
	  etc.

 o Miscellaneous bug fixes.


Current Work on Happy

 o
More work will be done on improving the speed with which Happy produces parsers. This is not massively important, however, since it pales into comparison next to the time taken to compile the generated parser.

 o We have ported a Yacc specification of the Haskell grammar to Happy. We plan to release this as a (large) example with the next release of Happy.

 o

We also want to include a simple lexical analysis producer with Happy, Something along the lines of:
>	semicolon	( ; )
>	colon		( : )
>	id		( {letter}{alphanum}+ )
etc.

Of course all changes are backwards compatible :-)

 o

High up on the list of things to do is error recovery, in the yacc style using the error token. Support for this is essential for parsing the Haskell layout rule, amongst other things.

 o We also want a port to Yale Haskell. This should be trivial when the Haskell 1.3 IO standard has been implemented across all compilers.


Frequently Encountered Bugs

A page describing known bugs (and workarounds!) for Happy-0.8 and 0.9 can be found here.

Authors

Happy was written by Andy Gill and Simon Marlow.


Extra

A big thanks to Ben Jones for loaning out his copy of the Roger Hargreaves ``Mr Happy'' Book.


Andy Gill, andy@dcs.gla.ac.uk,
Simon Marlow, simonm@dcs.gla.ac.uk