Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell parsing tools - yacc:lex :: happy:?

So, it seems like Happy is a robust replacement for yacc in Haskell. Is there an equally robust lexer generator to replace lex/flex?

like image 278
Geoff Avatar asked May 01 '09 18:05

Geoff


People also ask

What is Happy Haskell?

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.

What is Lex and YACC for?

Lex is a lexical analysis tool that can be used to identify specific text strings in a structured way from source text. Yacc is a grammar parser; it reads text and can be used to turn a sequence of words into a structured format for processing.

Are Lex and Yacc still used?

Lex and Yacc were created in the 1970s as parts of the Unix programming tool set. Both have a number of incarnations for various environments, and are still among the most widely used in their domain. Flex and Bison are improved, modern versions of Lex and Yacc, standardly distributed with most GNU/Linux variants.

Can yacc parse C?

The input to Yacc is a grammar with snippets of C code (called "actions") attached to its rules. Its output is a shift-reduce parser in C that executes the C snippets associated with each rule as soon as the rule is recognized.


1 Answers

Alex? http://www.haskell.org/alex/

a tool for generating lexical analysers in Haskell, given a description of the tokens to be recognised in the form of regular expressions. It is similar to the tool lex or flex for C/C++...

Alex is part of the Haskell Platform, so if you install the platform you will automatically have a working Alex.

Alex is also on Hackage. If you have the cabal-install tool (which also comes with the Haskell Platform), then you can build and install the latest version of Alex with

    cabal install alex

To find out what the latest version of Alex is, and to download the source separately, go to Alex's HackageDB page.

Alex might also be pre-packaged for your OS...

like image 170
Dave Avatar answered Oct 11 '22 20:10

Dave