Commit f3f7a1cc authored by POTTIER Francois's avatar POTTIER Francois
Browse files

Added a view of the stack as a stream of state/semantic value/position tuples.

parent a9727eff
......@@ -454,5 +454,44 @@ module Make (T : TABLE) = struct
let entry (s : state) lexer lexbuf : semantic_value =
loop (wrap lexer lexbuf) (start s)
(* --------------------------------------------------------------------------- *)
(* Stack inspection. *)
(* This code offers a (read-only) view of the stack as a stream of elements.
Each element contains a pair of a (non-initial) state and a semantic value
associated with (the incoming symbol of) this state. *)
type element =
state * semantic_value * Lexing.position * Lexing.position
let rec view 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
(which has no incoming symbol).
We do not allow the user to inspect this state. *)
let next = in
if next == cell then
(* Construct an element containing the current state [current] as well
as the semantic value contained in the top stack cell. This semantic
value is associated with the incoming symbol of this state, so it
makes sense to pair them together. In the typed API, this state will
have type ['a state] and the semantic value will have type ['a], for
some type ['a]. *)
let element = (
) in
Cons (element, view next cell.state)
let view env : element stream =
view env.stack env.current
......@@ -3,6 +3,17 @@
(* --------------------------------------------------------------------------- *)
(* A vanilla type of streams (lazy lists). *)
type 'a stream =
'a head Lazy.t
and 'a head =
| Nil
| Cons of 'a * 'a stream
(* --------------------------------------------------------------------------- *)
(* It would be nice if we could keep the structure of stacks and environments
hidden. However, stacks and environments must be accessible to semantic
actions, so the following data structure definitions must be public. *)
......@@ -355,4 +366,12 @@ module type ENGINE = sig
and type semantic_value := semantic_value
and type 'a result := 'a result
(* TEMPORARY move/comment *)
type element =
state * semantic_value * Lexing.position * Lexing.position
val view: ('a, 'pc) env -> element stream
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