Commit ff3096be authored by POTTIER Francois's avatar POTTIER Francois

Added the generation of a function that maps each state to its set of items.

parent 2949b951
......@@ -108,5 +108,7 @@ module type INSPECTION = sig
val rhs: production -> xsymbol list
val items: 'a lr1state -> (production * int) list
end
......@@ -11,6 +11,9 @@ open Grammar
the bullet position and the rest (usually 24 bits) for the
production index. These widths could be adjusted. *)
(* The function [export] is duplicated in [TableInterpreter]. Do not
modify it; or modify it here and there in a consistent manner. *)
type t = int
let import (prod, pos) =
......@@ -20,6 +23,9 @@ let import (prod, pos) =
let export t =
(Production.i2p (t lsr 7), t mod 128)
let marshal (item : t) : int =
item
(* Comparison. *)
let equal (item1 : t) (item2: t) =
......
......@@ -8,6 +8,12 @@ type t
val import: Production.index * int -> t
val export: t -> Production.index * int
(* An item can be encoded as an integer. This is used in the table
back-end only. The decoding function (really a copy of [export])
is in [TableInterpreter]. *)
val marshal: t -> int
(* Comparison. *)
val equal: t -> t -> bool
......
......@@ -854,6 +854,37 @@ let production_defs () =
(* ------------------------------------------------------------------------ *)
(* A table that maps an LR(1) state to its LR(0) core. *)
let lr0_core () =
assert Settings.inspection;
define_and_measure (
"lr0_core",
marshal1 (Lr1.map (fun (node : Lr1.node) ->
Lr0.core (Lr1.state node)
))
)
(* A table that maps an LR(0) state to a set of LR(0) items. *)
let encode_lr0_item item =
EIntConst (Item.marshal item)
let lr0_items () =
assert Settings.inspection;
define_and_measure (
"lr0_items",
EArray (Array.to_list (Array.init Lr0.n (fun (node : Lr0.node) ->
elist (List.map encode_lr0_item (Item.Set.elements (Lr0.items node)))
)))
)
(* TEMPORARY these lists share suffixes, which in principle could be
physically shared. Or perhaps we could use some form of packed
array? *)
(* ------------------------------------------------------------------------ *)
(* Let's put everything together. *)
open UnparameterizedSyntax
......@@ -905,7 +936,6 @@ let program =
SIModuleDef (more, MStruct (
interface_to_structure (
lr1state_redef ::
tokengadtdef grammar @
nonterminalgadtdef grammar @
symbolgadtdef() @
......@@ -915,13 +945,20 @@ let program =
SIInclude (MVar more) ::
SIInclude (MApp (MVar make_inspection, MStruct [
SIInclude (MVar more);
SIValDefs (false, [
incoming_symbol_def();
production_defs()
])
])) ::
SIInclude (MApp (MVar make_inspection, MStruct (
SIInclude (MVar more) ::
interface_to_structure [
lr1state_redef;
] @
SIValDefs (false,
incoming_symbol_def() ::
production_defs() ::
lr0_core() ::
lr0_items() ::
[]
) ::
[]
))) ::
[]
......
......@@ -119,13 +119,15 @@ end
addition to the above) when [--inspection] is enabled. It is used as an
argument to [TableInterpreter.Inspection]. *)
(* TEMPORARY comment/document *)
module type INSPECTION_TABLES = sig
type 'a lr1state
type 'a symbol
type xsymbol
(* This function maps a state to its incoming symbol. *)
(* A mapping of every (non-initial) state to its incoming symbol. *)
val symbol: 'a lr1state -> 'a symbol
......@@ -134,5 +136,15 @@ module type INSPECTION_TABLES = sig
val production_defs: (xsymbol * xsymbol list) option array
(* A mapping of every (non-initial) state to its LR(0) core. *)
val lr0_core: PackedIntArray.t
(* A mapping of every LR(0) state to its set of LR(0) items.
Each item is represented in its packed form (see [Item])
as an integer. *)
val lr0_items: int list array
end
......@@ -191,4 +191,13 @@ module MakeInspection (T : TableFormat.INSPECTION_TABLES) = struct
let _, rhs = production_def prod in
rhs
(* This is a copy of [Item.export]. *)
let export t =
(t lsr 7, t mod 128)
let items s =
let core = PackedIntArray.get T.lr0_core s in
List.map export T.lr0_items.(core)
end
......@@ -21,7 +21,8 @@ module Make (T : TableFormat.TABLES)
(* This functor is also invoked inside the generated parser. It
constructs the inspection API on top of the inspection tables. *)
module MakeInspection (T : TableFormat.INSPECTION_TABLES)
module MakeInspection (T : TableFormat.INSPECTION_TABLES
with type 'a lr1state = int)
: IncrementalEngine.INSPECTION
with type 'a lr1state := 'a T.lr1state
......
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