Commit 5848e24a authored by POTTIER Francois's avatar POTTIER Francois

Change [OnErrorReduce.preferable] to compare two productions.

parent 81c8fbe1
......@@ -1493,14 +1493,22 @@ module OnErrorReduce = struct
open Precedence
let preferable nt1 nt2 =
assert (nt1 <> nt2);
let preferable prod1 prod2 =
(* The two productions that we are comparing must be distinct. *)
assert (prod1 <> prod2);
let nt1 = Production.nt prod1
and nt2 = Production.nt prod2 in
(* If they have the same left-hand side (which seems rather unlikely?),
declare them incomparable. *)
nt1 <> nt2 &&
(* Otherwise, look up the priority levels associated with their left-hand
symbols. *)
let prec1, prec2 =
try
StringMap.find (print nt1) declarations,
StringMap.find (print nt2) declarations
with Not_found ->
(* [compare] should be used to compare two symbols for which
(* [preferable] should be used to compare two symbols for which
there exist [%on_error_reduce] declarations. *)
assert false
in
......
......@@ -530,13 +530,12 @@ module OnErrorReduce : sig
val iter: (Nonterminal.t -> unit) -> unit
(* When two [%on_error_reduce] declarations are applicable in a single
state, they can be compared, using [preferable], to test if one of them
takes precedence over the other. This is a partial order; two symbols may
be incomparable (either because they appear on the same line, or because
they originate in different files). *)
(* When two productions could be reduced, in a single state, due to
[%on_error_reduce] declarations, these productions can be compared, using
[preferable], to test if one of them takes precedence over the other.
This is a partial order; two productions may be incomparable. *)
val preferable: Nonterminal.t -> Nonterminal.t -> bool
val preferable: Production.index -> Production.index -> bool
end
......
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