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

Raise a [DeadBranch] exception when a branch is missing an edge.

This makes almost no difference: it saves 5 nodes out of 25K in
the stars, and saves 10K facts out of 7M facts (on ocaml.mly --lalr).
parent 0b2b21fb
......@@ -171,8 +171,8 @@ end = struct
(* TEMPORARY could insert this branch only if viable -- leads to 12600 instead of 12900 in ocaml.mly --lalr *)
(* [insert] logically consumes its argument [t], which should no
longer be used. *)
exception DeadBranch
let rec insert w prod t =
match w with
| [] ->
......@@ -184,8 +184,9 @@ end = struct
(* Check if there is a transition labeled [a] out of []. If
there is, we add a child to the trie [t]. If there isn't, then it
must have been removed by conflict resolution. (Indeed, it must be
present in a canonical automaton.) The trie remains unchanged in
this case. *)
present in a canonical automaton.) We could in this case return an
unchanged sub-trie. We can do slightly better: we abort the whole
insertion, so as to return an unchanged toplevel trie. *)
match SymbolMap.find a (Lr1.transitions with
| successor ->
(* Find our child at [a], or create it. *)
......@@ -200,14 +201,19 @@ end = struct
(* Update [t]. Again, no need to allocate a new stamp. *)
{ t with transitions = SymbolMap.add a t' t.transitions }
| exception Not_found ->
raise DeadBranch
(* [insert prod t] inserts a new branch, corresponding to production
[prod], into the trie [t]. This function consumes its argument,
which should no longer be used afterwards. *)
let insert prod t =
let w = Array.to_list (Production.rhs prod) in
insert w prod t
let save = !c in
insert w prod t
with DeadBranch ->
c := save;
(* [fresh s] creates a new empty trie whose source is [s]. *)
let fresh source =
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