What is Menhir?

Menhir is a LR(1) parser generator for the
OCaml programming language. That is,
Menhir compiles LR(1) grammar specifications down to OCaml code.
Menhir was designed and implemented by François Pottier and
Yann Régis-Gianas.

Menhir is 90% compatible with ocamlyacc. Legacy ocamlyacc grammar
specifications are accepted and compiled by Menhir. The resulting
parsers run and produce correct parse trees. However, parsers that
explicitly invoke functions in module Parsing behave
slightly incorrectly. For instance, the functions that provide access
to positions return a dummy position when invoked by a Menhir
parser. Porting a grammar specification from ocamlyacc to Menhir
requires replacing all calls to module Parsing with new
Menhir-specific keywords.

Why prefer Menhir to ocamlyacc?

Menhir allows the definition of a nonterminal symbol to be parameterized by other
(terminal or nonterminal) symbols. Furthermore, it offers a library of
standard parameterized definitions, including options, sequences, and lists. It
offers some support for EBNF syntax, via the ?, +,
and * modifiers.

Documentation

You may also wish to consult
the MenhirLib.Convert API, which offers facilities for converting
back and forth between the traditional parser API (which assumes that the lexical analyzer
is produced using ocamllex) and a revised API (which makes no such assumption).