Photo by Lionel Pottier

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?

There are other differences, documented in Menhir's reference manual.

Documentation

The reference manual is available in HTML and PDF formats.

The MenhirLib.Convert API 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).

The module MenhirLib.LexerUtil offers facilities for extracting the position of a syntax error out of the lexing buffer and displaying it in a readable way.

The module MenhirLib.ErrorReports offers facilities for constructing syntax error messages.

The incremental API is defined by MenhirLib.IncrementalEngine (and is also explained in the reference manual).

Downloading

Here are the source code releases of Menhir. Compiling and installing requires GNU make and OCaml (version 4.02 or later). Bug reports and suggestions are welcome. Here is a list of recent changes.

Menhir is also available through opam. Once you have installed opam, just type opam install menhir.

Mailing list

There is a mailing list for announcements of new releases and for discussion of problems, bugs, feature requests, and so on. Only subscribers can post.


FrançaisHome Email Last modified: August 10, 2021