Re: ocamlyacc and error recovery

From: Xavier Leroy (
Date: Mon Feb 24 1997 - 11:50:40 MET

From: Xavier Leroy <>
Message-Id: <>
Subject: Re: ocamlyacc and error recovery
In-Reply-To: <Pine.GSO.3.95.970220200443.872A-100000@octave> from David Monniaux at "Feb 20, 97 08:11:52 pm"
To: (David Monniaux)
Date: Mon, 24 Feb 1997 11:50:40 +0100 (MET)

> I have a small problem with ocamlyacc when I want to handle errors.
> I always have an uncaught Parser_error exception. Does anyone know how to
> handle the "error" token?

The first thing to do is to define a function called "parse_error" in
the header section of the grammar:

let parse_error msg =
  print_string msg

That will allow error recovery to be initiated. (According to the
documentation, defining this function is optional; there is a bug in
the current implementation that makes it necessary.)

Once this is done, "error" rules should work as described in the Yacc

- Xavier Leroy

This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:09 MET