Commit 6e4b8abf authored by POTTIER Francois's avatar POTTIER Francois

New function [Lr0.incoming_edges].

parent 2bd96cd5
Pipeline #93297 passed with stages
in 25 seconds
......@@ -244,6 +244,25 @@ let outgoing_edges node : node SymbolMap.t =
let outgoing_symbols node : Symbol.t list =
SymbolMap.domain (InfiniteArray.get _transitions node)
(* Efficient access to the predecessors of an LR(0) state requires building
a reversed graph. This is done on the first invocation of the function
[predecessors]. Our measurements show that it typically takes less than
0.01s anyway. *)
let predecessors : node list array Lazy.t =
lazy (
let predecessors = Array.make n [] in
for source = 0 to n-1 do
SymbolMap.iter (fun _symbol (target, _) ->
predecessors.(target) <- source :: predecessors.(target)
) (InfiniteArray.get _transitions source)
done;
predecessors
)
let incoming_edges (c : node) : node list =
(Lazy.force predecessors).(c)
(* ------------------------------------------------------------------------ *)
(* Help for building the LR(1) automaton. *)
......
......@@ -43,6 +43,7 @@ val items: node -> Item.Set.t
incoming symbol) if and only if it is a start node. *)
val incoming_symbol: node -> Symbol.t option
val incoming_edges: node -> node list
(* The outgoing edges of a node. *)
......
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