14

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

gnkdl_gansklgna
  • 2,227
  • 1
  • 16
  • 17
  • Do you want a parser for OCaml as an input language, or a parser generator with OCaml as an implementation language/ – Chris Conway Nov 21 '08 at 03:57
  • 1
    hi duane, as someone interested in the same thing, i would like to know if you found a decent library in the end, and how it worked out for you. – Martin DeMello Nov 01 '09 at 10:10

2 Answers2

11

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.

Thelema
  • 14,257
  • 6
  • 27
  • 35
Darius Bacon
  • 14,921
  • 5
  • 53
  • 53
  • 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 Jan 19 '09 at 01:55
  • 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 Jan 19 '09 at 03:26
  • 1
    @Mauricio: F# has the monad-like notion of computation expressions; this syntactic jiggy-wiggy allows you to hide all of the unpleasantness. – John Clements Mar 16 '10 at 05:24
3

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.

J D
  • 48,105
  • 13
  • 171
  • 274
  • 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 Jan 19 '09 at 01:47
  • Also, how would they compare to FParsec? – Mauricio Scheffer Jan 19 '09 at 01:48
  • 3
    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. – J D Sep 07 '09 at 21:39