Chapter 1. Introduction
Prev |  | Next

## Chapter 1. Introduction

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: you can have several Happy parsers in the same program, and each parser may have multiple entry points. 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). In a future version we hope to include a lexical analyser generator with Happy as a single package.

Parsers generated by Happy are fast; generally faster than an equivalent parser written using parsing combinators or similar tools. Furthermore, any future improvements made to Happy will benefit an existing grammar, without need for a rewrite.

Happy is sufficiently powerful to parse full Haskell - GHC itself uses a Happy parser.

Happy can currently generate four types of parser from a given grammar, the intention being that we can experiment with different kinds of functional code to see which is the best, and compiler writers can use the different types of parser to tune their compilers. The types of parser supported are:

1. `standard' Haskell 98 (should work with any compiler that compiles Haskell 98).

2. standard Haskell using arrays (this is not the default because we have found this generates slower parsers than 1).

3. Haskell with GHC (Glasgow Haskell) extensions. This is a slightly faster option than 1 for Glasgow Haskell users.

4. GHC Haskell with string-encoded arrays. This is the fastest/smallest option for GHC users. If you're using GHC, the optimum flag settings are `-agc` (see Chapter 5, Invoking Happy).

Happy can also generate parsers which will dump debugging information at run time, showing state transitions and the input tokens to the parser.

## 1.1. Compatibility

Happy is written in Glasgow Haskell. This means that (for the time being), you need GHC to compile it. Any version of GHC >= 6.2 should work.

Remember: parsers produced using Happy should compile without difficulty under any Haskell 98 compiler or interpreter[1]

[1] With one exception: if you have a production with a polymorphic type signature, then a compiler that supports local universal quantification is required. See Section 2.4, “Type Signatures”.

Prev |  | Next
Happy User Guide | Home | 1.2. Reporting Bugs