LinuxCommandLibrary

happy

Performs no operation

SYNOPSIS

happy [OPTION...] [infile.y]

PARAMETERS

-a, --array
    Generate compact array-based parser tables

-b DIR, --bindir=DIR
    Set output directory for generated files

-c, --cpp
    Preprocess input with C preprocessor

-d, --debug
    Output debugging information to .info file

-g, --ghc
    Generate GHC-optimised parser code

-h, --help
    Display help and exit

-i, --info
    Output parser statistics and information

-l, --legacy
    Enable legacy (pre-1.20) syntax

-n, --strict
    Disallow ambiguous rules and conflicts

-o FILE, --output=FILE
    Output to specified file

-p PREFIX, --prefix=PREFIX
    Set prefix for generated identifiers

-t TEMPLATE, --template=TEMPLATE
    Use custom template file

-v, --version
    Output version information

-y MODULE, --yacc=MODULE
    Set name of generated module

-E, --extra
    Generate extra output for debugging

-V, --verbose
    Increase verbosity

DESCRIPTION

Happy is a sophisticated parser generator for Haskell, inspired by tools like yacc and bison. It reads a grammar specification file (typically with a .y extension) describing a context-free grammar and produces a Haskell source module implementing an efficient parser for that grammar.

Parsers generated by Happy use a monadic interface, allowing seamless integration with Haskell's functional paradigm. They support lookahead, precedence declarations, and semantic actions in Haskell code. Happy employs the LR(1) parsing algorithm, generating compact parser tables for high performance.

Key features include array-based or functional parser tables, GHC optimizations, debugging output, and compatibility with the C preprocessor for complex grammars. It's an essential tool in the Haskell ecosystem for building compilers, interpreters, and domain-specific languages. Happy integrates well with Alex, the lexical analyzer generator, forming a complete parser/lexer toolchain.

Usage involves writing a grammar file with directives, terminals, non-terminals, rules, and attributes, then running Happy to generate the parser module, which is compiled with GHC.

CAVEATS

Requires GHC/Haskell environment; generated parsers need compilation with GHC. Large grammars may produce big tables. Not for non-Haskell projects.

BASIC USAGE EXAMPLE

happy -g -o Parser.hs grammar.y
Generates GHC-optimized Parser.hs from grammar.y

GRAMMAR FILE STRUCTURE

Consists of header, directives (%name, %tokenizer), tokens, precedence, rules with actions in braces {}.

HISTORY

Developed by Andy Gill and Simon Marlow in 1995-1996 at the University of Glasgow. Part of GHC tools since early versions; current maintainer is Herbert Valerio Riedel. Evolved from Simon Peyton Jones' initial work, with major releases aligning with GHC versions (e.g., 1.20 in 2015 introduced new syntax). Widely used in Haskell projects like GHC itself.

SEE ALSO

alex(1), ghc(1), yacc(1), bison(1)

Copied to clipboard