Linux command
happy 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Generate parser from grammar file
happy [grammar.y] -o [Parser.hs]
Generate with info file for debugging
happy -i [grammar.y]
Generate with GHC extensions for faster code
happy -g [grammar.y]
Generate array-based parser with GHC string encoding
happy -ag [grammar.y]
Generate parser with debugging output at runtime
happy -d [grammar.y]
Generate GLR parser
happy -l [grammar.y]
说明
Happy is a parser generator for Haskell, similar to yacc for C. It takes a grammar specification and produces a Haskell parser module. The tool generates LALR parsers from BNF-like grammars and can also produce GLR parsers. It integrates with the Alex lexer generator for complete parsing solutions.
参数
- -o _FILE_
- Output file name. Defaults to FILE.hs.
- -i _FILE_
- Generate info file with grammar details, parser states, and conflicts.
- -g, --ghc
- Use GHC-specific extensions for faster parsers.
- -a, --array
- Generate array-based parser (smaller but slower). Combined with -g, arrays are encoded as strings for faster performance.
- -c, --coerce
- Use GHC's unsafeCoerce# for smaller, faster parsers. May crash at runtime if grammar has type errors.
- -d, --debug
- Generate a parser that prints shift/reduce debugging info to stderr.
- -l, --glr
- Generate a GLR parser instead of LALR(1).
- -t _DIR_, --template=_DIR_
- Directory for template files.
- -h, --help
- Display help information.
- -v, --version
- Print version information.
FAQ
What is the happy command used for?
Happy is a parser generator for Haskell, similar to yacc for C. It takes a grammar specification and produces a Haskell parser module. The tool generates LALR parsers from BNF-like grammars and can also produce GLR parsers. It integrates with the Alex lexer generator for complete parsing solutions.
How do I run a basic happy example?
Run `happy [grammar.y] -o [Parser.hs]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -o _FILE_ do in happy?
Output file name. Defaults to FILE.hs.