views:

1277

answers:

2

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

+5  A: 

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.

Darius Bacon
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.
Mauricio Scheffer
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.
Darius Bacon
@Mauricio: F# has the monad-like notion of computation expressions; this syntactic jiggy-wiggy allows you to hide all of the unpleasantness.
John Clements
+3  A: 

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.

Jon Harrop
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?
Mauricio Scheffer
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.
Jon Harrop