derivation.mli 2.78 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
(******************************************************************************)
(*                                                                            *)
(*                                   Menhir                                   *)
(*                                                                            *)
(*                       François Pottier, Inria Paris                        *)
(*              Yann Régis-Gianas, PPS, Université Paris Diderot              *)
(*                                                                            *)
(*  Copyright Inria. All rights reserved. This file is distributed under the  *)
(*  terms of the GNU General Public License version 2, as described in the    *)
(*  file LICENSE.                                                             *)
(*                                                                            *)
(******************************************************************************)

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
open Grammar

(* -------------------------------------------------------------------------- *)

(* This is the type of derivations. Derivations are forests: see inside. *)

type t

(* This is the type of derivations contexts, or derivations with a
   derivation-shaped hole. *)

type context

(* -------------------------------------------------------------------------- *)

(* Construction. *)

(* [empty] is the forest that consists of a single empty tree. *)

val empty: t

(* [tail pos rhs] is the forest: (i) whose first element is the empty tree,
   and (ii) whose remaining elements are the symbols found at positions
   greater than or equal to [pos] in the array [rhs]. *)

val tail: int -> Symbol.t array -> t

(* [build pos rhs forest comment] is the forest: (i) whose first element is
   the tree that has the non-terminal symbol [rhs.(pos)] at its root and the
   forest [forest] below its root, and (ii) whose remaining elements are the
   symbols found at positions greater than [pos] in the array [rhs]. *)

val build: int -> Symbol.t array -> t -> string option -> t

(* [prepend symbol forest] is the forest: (i) whose first element is the
   symbol [symbol], and (ii) whose remaining elements form the forest
   [forest]. *)

val prepend: Symbol.t -> t -> t

(* -------------------------------------------------------------------------- *)

(* Factoring. *)

(* [factor] factors the maximal common derivation context out of a
   nonempty family of derivations. It produces a pair of the context
   and of the residual derivations. *)

val factor: t Item.Map.t -> context * t Item.Map.t

(* -------------------------------------------------------------------------- *)

(* Display. *)

(* [print] prints a derivation. *)

val print: out_channel -> t -> unit

(* [printc] prints a derivation context. *)

val printc: out_channel -> context -> unit