From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA31876 for caml-redistribution; Tue, 7 Sep 1999 11:47:04 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA08290 for ; Tue, 7 Sep 1999 09:00:07 +0200 (MET DST) Received: from lri.lri.fr (lri.lri.fr [129.175.15.1]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id JAA18804 for ; Tue, 7 Sep 1999 09:00:05 +0200 (MET DST) Received: from pc89.lri.fr (pc89.lri.fr [129.175.8.108]) by lri.lri.fr (8.9.1a/8.9.1) with ESMTP id JAA12850; Tue, 7 Sep 1999 09:00:04 +0200 (MET DST) Received: by pc89.lri.fr (8.8.7/feuille) id JAA06363 ; Tue, 7 Sep 1999 09:00:02 +0200 X-Authentication-Warning: pc89.lri.fr: filliatr set sender to filliatr@pc89.lri.fr using -f From: Jean-Christophe Filliatre MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <14292.47090.643022.490490@pc89.lri.fr> Date: Tue, 7 Sep 1999 09:00:02 +0200 (MEST) To: "David Mentr'e" Cc: caml-list@inria.fr Subject: Re: ocamlyacc and error messages In-Reply-To: References: X-Mailer: VM 6.49 under Emacs 20.3.1 Reply-To: Jean-Christophe.Filliatre@lri.fr (Jean-Christophe Filliatre) Content-Transfer-Encoding: 8bit Sender: weis > Comment donner le numéro de ligne et le point d'échec dans une grammaire > d'un parser généré par ocamlyacc ? > > What is the simplest way to report an error in a parser generated by > ocamlyacc ? The module Parsing of the ocaml standard library provides two functions ====================================================================== val symbol_start : unit -> int val symbol_end : unit -> int ====================================================================== to get the start and end positions of the left-hand side of the grammar rule that matched (with a ocamlyacc grammar). Those positions are characters count from the beginning of the file. You can store those informations in your syntax tree, together with the name of the rule if you want. Then, if you want to indicate the corresponding line in the file when an error occurs, one possible solution is to re-scan the file from the beginning, counting newline characters until the desired position is found. It is the solution used by the ocaml parser. Have a look in ocaml sources (directory parsing/) for more informations. Another solution is to count the lines in your lexer, in a reference, and to store that information in your syntax tree when building it. -- Jean-Christophe FILLIATRE mailto:Jean-Christophe.Filliatre@lri.fr http://www.lri.fr/~filliatr