Happy User Guide

Simon Marlow

Andy Gill

Abstract

This document describes Happy, the Haskell Parser Generator, version 1.18.


Table of Contents

1. Introduction
1.1. Compatibility
1.2. Reporting Bugs
1.3. License
1.4. Obtaining Happy
2. Using Happy
2.1. Returning other datatypes
2.2. Parsing sequences
2.2.1. Sequences with separators
2.3. Using Precedences
2.3.1. How precedence works
2.3.2. Context-dependent Precedence
2.4. Type Signatures
2.5. Monadic Parsers
2.5.1. Handling Parse Errors
2.5.2. Threaded Lexers
2.5.2.1. Monadic productions with %lexer
2.5.3. Line Numbers
2.5.4. Summary
2.6. The Error Token
2.7. Generating Multiple Parsers From a Single Grammar
3. Generalized LR Parsing
3.1. Introduction
3.2. Basic use of a Happy-generated GLR parser
3.2.1. Overview
3.2.2. The main function
3.2.3. The input
3.2.4. The Parse Result
3.2.5. Compiling the parser
3.3. Including semantic results
3.3.1. Forms of semantics
3.3.2. Tree decoding
3.3.3. Label decoding
3.3.4. Monadic tree decoding
3.4. Further information
3.4.1. The GLR examples
3.4.2. Viewing forests as graphs
3.4.3. Some Applications of GLR parsing
3.4.4. Technical details
3.4.5. The --filter option
3.4.6. Limitations and future work
3.4.7. Thanks and acknowledgements
4. Attribute Grammars
4.1. Introduction
4.2. Attribute Grammars in Happy
4.2.1. Declaring Attributes
4.2.2. Semantic Rules
4.3. Limits of Happy Attribute Grammars
4.4. Example Attribute Grammars
5. Invoking Happy
6. Syntax of Grammar Files
6.1. Lexical Rules
6.2. Module Header
6.3. Directives
6.3.1. Token Type
6.3.2. Tokens
6.3.3. Parser Name
6.3.4. Partial Parsers
6.3.5. Monad Directive
6.3.6. Lexical Analyser
6.3.7. Precedence declarations
6.3.8. Expect declarations
6.3.9. Error declaration
6.3.10. Attribute Type Declaration
6.3.11. Attribute declaration
6.4. Grammar
6.4.1. Parameterized Productions
6.5. Module Trailer
7. Info Files
8. Tips
8.1. Performance Tips
8.2. Compilation-Time Tips
8.3. Finding Type Errors
8.4. Conflict Tips
8.4.1. LALR(1) parsers
8.5. Using Happy with GHCi
Index