Commit d46683e3 authored by POTTIER Francois's avatar POTTIER Francois

Update [Lr1] to use [Lr1construction].

Also, move [invert] from [Lr1] to [Lr0].
parent 6978b22a
......@@ -1085,7 +1085,7 @@ let rundef s : valdef =
(* There is a reduction for these tokens. *)
TerminalSet.union toks covered,
reducebranch toks prod s :: branches
) (Lr1.invert reductions) (TerminalSet.empty, [])
) (Lr0.invert reductions) (TerminalSet.empty, [])
in
let covered, branches =
......
......@@ -64,7 +64,7 @@ let has_default_reduction, count =
None
else
let reduction = ProductionMap.is_singleton (Lr1.invert (Lr1.reductions s)) in
let reduction = ProductionMap.is_singleton (Lr0.invert (Lr1.reductions s)) in
match reduction with
| Some _ ->
if SymbolMap.purelynonterminal (Lr1.transitions s)
......
......@@ -635,3 +635,22 @@ let reductions_table state =
List.fold_left (fun reductions (toks, prod) ->
add_reductions prod toks reductions
) TerminalMap.empty (reductions state)
(* This inverts a mapping of tokens to productions into a mapping of
productions to sets of tokens. *)
(* This is needed, in [CodeBackend], to avoid producing two (or more)
separate branches that call the same [reduce] function. Instead,
we generate just one branch, guarded by a [POr] pattern. *)
let invert reductions : TerminalSet.t ProductionMap.t =
TerminalMap.fold (fun tok prods inverse ->
let prod = Misc.single prods in
let toks =
try
ProductionMap.lookup prod inverse
with Not_found ->
TerminalSet.empty
in
ProductionMap.add prod (TerminalSet.add tok toks) inverse
) reductions ProductionMap.empty
......@@ -163,3 +163,8 @@ val add_reductions: Production.index -> TerminalSet.t -> reductions -> reduction
(* A table of the reductions at a state. *)
val reductions_table: lr1state -> reductions
(* [invert] inverts a reduction table (that is, a mapping of tokens to lists of
productions), producing a mapping of productions to sets of tokens. *)
val invert : reductions -> TerminalSet.t ProductionMap.t
This diff is collapsed.
......@@ -91,7 +91,9 @@ end
(* This provides access to a node's transitions and reductions. *)
val transitions: node -> node SymbolMap.t
val reductions: node -> Production.index list TerminalMap.t
(* or: node -> Lr0.reductions *)
(* (New as of 2012/01/23.) This tells whether a shift/reduce conflict
in this node was solved in favor of neither (%nonassoc). This implies
......@@ -99,11 +101,6 @@ val reductions: node -> Production.index list TerminalMap.t
val forbid_default_reduction: node -> bool
(* This inverts a mapping of tokens to productions into a mapping of
productions to sets of tokens. *)
val invert : ProductionMap.key list TerminalMap.t -> TerminalSet.t ProductionMap.t
(* [has_beforeend s] tests whether the state [s] can reduce a production
whose semantic action uses [$endpos($0)]. Note that [$startpos] and
[$endpos] have been expanded away already, so we need not worry about
......
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