From: Jean-Christophe Filliatre <filliatr@lri.fr>
To: "David Mentr'e" <David.Mentre@irisa.fr>
Cc: caml-list@inria.fr
Subject: Re: ocamlyacc and error messages
Date: Tue, 7 Sep 1999 09:00:02 +0200 (MEST) [thread overview]
Message-ID: <14292.47090.643022.490490@pc89.lri.fr> (raw)
In-Reply-To: <wd8671ow8n0.fsf@parate.irisa.fr>
> 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
prev parent reply other threads:[~1999-09-07 9:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-09-06 12:02 David Mentr'e
1999-09-07 7:00 ` Jean-Christophe Filliatre [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=14292.47090.643022.490490@pc89.lri.fr \
--to=filliatr@lri.fr \
--cc=David.Mentre@irisa.fr \
--cc=Jean-Christophe.Filliatre@lri.fr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox