
Hi I want to implement a little algebraic specification language in Haskell, and I have a working C implementation available which uses yacc/flex. What is the best way of replacing yacc/bison and (f)lex when migrating the project into Haskell? Best Wishes, Johan

On 15 Feb 2005, at 10:36, Johan Glimming wrote:
Hi
I want to implement a little algebraic specification language in Haskell, and I have a working C implementation available which uses yacc/flex.
What is the best way of replacing yacc/bison and (f)lex when migrating the project into Haskell?
I imagine for small languages a lot of people roll their own parser, using the "the grammar is the program" idiom as demonstrated (for example) in one of the final chapters of Paulson's ML book. That's what I've done a couple of times in various functional languages. This approach is simple to write (educational, too, the first time you do it) but not particularly fast. Then there is the parsec project which is a considerably more serious implementation of combinator based parsing. http://www.cs.uu.nl/~daan/parsec.html Jules

Johan Glimming writes:
What is the best way of replacing yacc/bison and (f)lex when migrating the project into Haskell?
My favorite tool for writing parsers is this one: http://www.cs.chalmers.se/~markus/BNFC/ You give it a grammar in BNF notation, and it will generate parsers and appropriate data structures for Haskell, C, Java, etc. Peter

I've used Parsec for small and more complex parsing tasks, and found it works well for both. In the past, I've used parser generators (not with Haskell), but now I find that I prefer to express a parser directly in the main programming language I'm using ... that way, it's easier to "escape" the grammar and do the things that aren't always so easy to do within the BNF-and-stuff formalisms. I find my code using Parsec is close enough to the BNF that the syntax production logic is easy enough to see. A very useful feature of Parsec is that, within what is broadly an LL(1) parsing framework, it provides a controlled limited lookahead capability. Another useful little trick I've found using Haskell+Parsec is that for an interpreted "little language", instead of returning a data structure describing the input sentence, I can return a function that can be applied to appropriate values to execute it directly. #g -- At 11:36 15/02/05 +0100, Johan Glimming wrote:
Hi
I want to implement a little algebraic specification language in Haskell, and I have a working C implementation available which uses yacc/flex.
What is the best way of replacing yacc/bison and (f)lex when migrating the project into Haskell?
Best Wishes, Johan
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
------------ Graham Klyne For email: http://www.ninebynine.org/#Contact
participants (4)
-
Graham Klyne
-
Johan Glimming
-
Jules Bean
-
Peter Simons