Commit 894ed838 by POTTIER Francois

Moved the list and stream functions to a new module [MenhirLib.General].

parent 1fec3725
......@@ -85,6 +85,7 @@ LIBFILES := \
src/IncrementalEngine.ml \
src/engineTypes.ml \
src/engine.{ml,mli} \
src/general.{ml,mli} \
src/inspectionTableFormat.ml \
src/inspectionTableInterpreter.{ml,mli} \
src/tableFormat.ml \
......
......@@ -13,6 +13,7 @@ In the following, "the Library" refers to the following files:
src/tableFormat.ml
src/tableInterpreter.{ml,mli}
src/convert.{ml,mli}
src/general.{ml,mli}
while "the Generator" refers to all other files in this archive.
......
open General
(* This signature describes the incremental LR engine. *)
(* In this mode, the user controls the lexer, and the parser suspends
......@@ -69,23 +71,6 @@ module type INCREMENTAL_ENGINE = sig
type 'a lr1state
(* A stream is a list whose elements are produced on demand. *)
type 'a stream =
'a head Lazy.t
and 'a head =
| Nil
| Cons of 'a * 'a stream
(* The length of a stream. *)
val length: 'a stream -> int
(* Folding over a stream. *)
val foldr: ('a -> 'b -> 'b) -> 'a stream -> 'b -> 'b
(* An element is a pair of a non-initial state [s] and a semantic value [v]
associated with the incoming symbol of this state. The idea is, the value
[v] was pushed onto the stack just before the state [s] was entered. Thus,
......
......@@ -31,3 +31,4 @@
<tableFormat.cmx>: for-pack(MenhirLib)
<tableInterpreter.cmx>: for-pack(MenhirLib)
<convert.cmx>: for-pack(MenhirLib)
<general.cmx>: for-pack(MenhirLib)
......@@ -503,35 +503,6 @@ module Make (T : TABLE) = struct
(* --------------------------------------------------------------------------- *)
(* Streams. *)
type 'a stream =
'a head Lazy.t
and 'a head =
| Nil
| Cons of 'a * 'a stream
(* The length of a stream. *)
let rec length xs =
match Lazy.force xs with
| Nil ->
0
| Cons (_, xs) ->
1 + length xs
(* Folding over a stream. *)
let rec foldr f xs accu =
match Lazy.force xs with
| Nil ->
accu
| Cons (x, xs) ->
f x (foldr f xs accu)
(* --------------------------------------------------------------------------- *)
(* Stack inspection. *)
(* We offer a read-only view of the parser's state as a stream of elements.
......@@ -542,6 +513,8 @@ module Make (T : TABLE) = struct
type element =
| Element: 'a lr1state * 'a * Lexing.position * Lexing.position -> element
open General
type stack =
element stream
......
......@@ -5,6 +5,7 @@ InfiniteArray
LinearizedArray
PackedIntArray
RowDisplacement
General
IncrementalEngine
EngineTypes
Engine
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment