Commit 837b9b6d by POTTIER Francois

Renamed the function [view] to [stack].

Defined the type [stack] as an abbreviation for [element stream].
parent ff9d5915
......@@ -95,7 +95,7 @@ module Make
) stack ()
let buffer_env b env =
buffer_stack b (I.view env)
buffer_stack b (I.stack env)
let print_stack stack =
with_buffer buffer_stack stack
......
......@@ -19,8 +19,8 @@ module Make
printer. They use [print_element] if provided by the user; otherwise
they use [print_element_as_symbol]. *)
val buffer_stack: Buffer.t -> I.element I.stream -> unit
val print_stack: I.element I.stream -> string
val buffer_stack: Buffer.t -> I.stack -> unit
val print_stack: I.stack -> string
val buffer_env: Buffer.t -> I.env -> unit
val print_env: I.env -> string
......
......@@ -75,8 +75,8 @@ module P =
(* Debugging. *)
let dump env =
Printf.fprintf stderr "Stack view:\n%s\n%!" (P.print_env env);
begin match Lazy.force (I.view env) with
Printf.fprintf stderr "Stack:\n%s\n%!" (P.print_env env);
begin match Lazy.force (I.stack env) with
| I.Nil ->
()
| I.Cons (I.Element (current, _, _, _), _) ->
......
......@@ -1952,7 +1952,7 @@ At this time, because the type \verb+env+ is opaque, the state of the parser
cannot be inspected by the user. We plan to offer an inspection API in the
near future.
% TEMPORARY view
% TEMPORARY stack
% TEMPORARY symbol
% TEMPORARY document the inspection API
......
......@@ -66,15 +66,6 @@ module type INCREMENTAL_ENGINE = sig
type 'a lr1state
(* 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,
for some type ['a], the type [s] has type ['a lr1state] and the value [v]
has type ['a]. In other words, the type [element] is an existential type. *)
type element =
| Element: 'a lr1state * 'a * Lexing.position * Lexing.position -> element
(* A stream is a list whose elements are produced on demand. *)
type 'a stream =
......@@ -92,12 +83,27 @@ module type INCREMENTAL_ENGINE = sig
val foldr: ('a -> 'b -> 'b) -> 'a stream -> 'b -> 'b
(* The parser's state can be viewed as a stream of elements. This stream is
(* 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,
for some type ['a], the type [s] has type ['a lr1state] and the value [v]
has type ['a]. In other words, the type [element] is an existential type. *)
type element =
| Element: 'a lr1state * 'a * Lexing.position * Lexing.position -> element
(* The parser's stack is (or, more precisely, can be viewed as) a stream of
elements. *)
type stack =
element stream
(* The parser's stack, a stream of elements, can be examined. This stream is
empty if the parser is in an initial state; otherwise, it is non-empty.
The parser's current LR(1) state is the one found in the top element of
this stream. *)
The LR(1) automaton's current state is the one found in the top element
of the stack. *)
val view: env -> element stream
val stack: env -> stack
end
......
......@@ -531,11 +531,14 @@ module Make (T : TABLE) = struct
type element =
| Element: 'a lr1state * 'a * Lexing.position * Lexing.position -> element
type stack =
element stream
(* If [current] is the current state and [cell] is the top stack cell,
then [view cell current] is a view of the parser's state as a stream
then [stack cell current] is a view of the parser's state as a stream
of elements. *)
let rec view cell current : element stream =
let rec stack cell current : element stream =
lazy (
(* The stack is empty iff the top stack cell is its own successor. In
that case, the current state [current] should be an initial state
......@@ -559,11 +562,11 @@ module Make (T : TABLE) = struct
cell.startp,
cell.endp
) in
Cons (element, view next cell.state)
Cons (element, stack next cell.state)
)
let view env : element stream =
view env.stack env.current
let stack env : element stream =
stack env.stack env.current
end
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