Commit 697cf750 authored by POTTIER Francois's avatar POTTIER Francois

Added [xfirst] in the inspection API.

parent de9b6d8b
......@@ -181,19 +181,24 @@ module type INSPECTION = sig
state [s]. This set is not epsilon-closed. This set is presented as a
list, in an arbitrary order. *)
val items: 'a lr1state -> item list
val items: _ lr1state -> item list
(* [nullable nt] tells whether the non-terminal symbol [nt] is nullable.
That is, it is true if and only if this symbol produces the empty
word [epsilon]. *)
val nullable: 'a nonterminal -> bool
val nullable: _ nonterminal -> bool
(* [first nt t] tells whether the FIRST set of the nonterminal symbol [nt]
contains the terminal symbol [t]. That is, it is true if and only if
[nt] produces a word that begins with [t]. *)
val first: 'a nonterminal -> 'b terminal -> bool
val first: _ nonterminal -> _ terminal -> bool
(* [xfirst] is analogous to [first], but expects a first argument of type
[xsymbol] instead of [_ terminal]. *)
val xfirst: xsymbol -> _ terminal -> bool
(* [foreach_terminal] enumerates the terminal symbols, including [error].
[foreach_terminal_but_error] enumerates the terminal symbols, excluding
......
......@@ -80,6 +80,30 @@ module Make
assert (T.terminal answer = X (T t)); (* TEMPORARY roundtrip *)
answer
(* Ordering functions. *)
let compare_terminals t1 t2 =
(* Subtraction is safe because overflow is impossible. *)
t2i t1 - t2i t2
let compare_nonterminals nt1 nt2 =
(* Subtraction is safe because overflow is impossible. *)
n2i nt1 - n2i nt2
let compare_symbols symbol1 symbol2 =
match symbol1, symbol2 with
| X (T _), X (N _) ->
-1
| X (N _), X (T _) ->
1
| X (T t1), X (T t2) ->
compare_terminals t1 t2
| X (N nt1), X (N nt2) ->
compare_nonterminals nt1 nt2
let compare_words w1 w2 =
General.compare compare_symbols w1 w2
(* The function [incoming_symbol] goes through the tables [T.lr0_core] and
[T.lr0_incoming]. This yields a representation of type [xsymbol], out of
which we strip the [X] quantifier, so as to get a naked symbol. This last
......@@ -140,6 +164,13 @@ module Make
let first nt t =
decode_bool (PackedIntArray.unflatten1 T.first (n2i nt) (t2i t))
let xfirst symbol t =
match symbol with
| X (T t') ->
compare_terminals t t' = 0
| X (N nt) ->
first nt t
(* The function [foreach_terminal] exploits the fact that the
first component of [B.error] is [Terminal.n - 1], i.e., the
number of terminal symbols, including [error] but not [#]. *)
......@@ -165,28 +196,4 @@ module Make
f (T.terminal i) accu
) accu
(* Ordering functions. *)
let compare_terminals t1 t2 =
(* Subtraction is safe because overflow is impossible. *)
t2i t1 - t2i t2
let compare_nonterminals nt1 nt2 =
(* Subtraction is safe because overflow is impossible. *)
n2i nt1 - n2i nt2
let compare_symbols symbol1 symbol2 =
match symbol1, symbol2 with
| X (T _), X (N _) ->
-1
| X (N _), X (T _) ->
1
| X (T t1), X (T t2) ->
compare_terminals t1 t2
| X (N nt1), X (N nt2) ->
compare_nonterminals nt1 nt2
let compare_words w1 w2 =
General.compare compare_symbols w1 w2
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