Wednesday, March 16, 2011

A good ocaml parser?

Hi, I'm looking for a good ocaml parsing library that isn't a derivative of flex/bison. Ideally, I'd like a monadic combinator library along the lines of parsec, but I can't find anything.

I would use haskell, but making llvm bindings for haskell is proving more tiresome than I originally thought.

Cheers,

Duane

From stackoverflow
  • Here's one library, via Google. (Which also brought up this and this, which lists several more relevant-sounding libraries.)

    When I wrote a combinator parser in ML, it turned out rather cumbersome to use because of the value restriction and eager evaluation, which forced you to eta-expand your grammar rules. Ocaml is said to be more relaxed about the value restriction, though -- maybe you'll be spared some of that pain.

    Mauricio Scheffer : I'm a parser combinator newbie, but in seems that FParsec doesn't force you to eta-expand (and F# has value restriction and eager evaluation). Please correct me if I'm wrong. Thanks.
    Darius Bacon : IIRC this came up with recursive or mutually-recursive productions. Not everything's naturally expressed in a Kleene star. It's been over a decade since I did this, though -- hard to remember the problems.
    John Clements : @Mauricio: F# has the monad-like notion of computation expressions; this syntactic jiggy-wiggy allows you to hide all of the unpleasantness.
  • In the OCaml world, stream-based parsers and Camlp4 are the next two most common alternatives. Both have been described in detail in previous OCaml Journal articles.

    Monadic parser combinators are comparatively rare in OCaml, largely because there are several higher-level and vastly more efficient libraries available.

    Mauricio Scheffer : I'm learning about parser combinators. When you say "several higher-level and vastly more efficient libraries available", which ones do you mean? Thanks.
    Mauricio Scheffer : Also, how would they compare to FParsec?
    Jon Harrop : I'm referring to camlp4, ocamllex, ulex, ocamlyacc, dpygen, menhir, ocfgc, aurochs and others. I found that ocamllex and ocamlyacc were generally several times faster at parsing than anything available for F# such as fslex, fsyacc and FParsec.

0 comments:

Post a Comment