[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jean-Christophe Filliatre <filliatr@l...> |
| Subject: | Re: ocamlyacc and error messages |
> 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