Commit 6b027bc8 authored by POTTIER Francois's avatar POTTIER Francois Committed by POTTIER Francois
Browse files

New function [Lr0.new_numbering].

parent efc97c8a
......@@ -423,6 +423,28 @@ let subsume ((k1, toksr1) as state1) ((k2, toksr2) as state2) =
loop (Array.length toksr1)
(* A memoizer for the type [lr1state]. This code is simple-minded, but its
efficiency is sufficient: 10000 states are numbered in about 0.01s. *)
module M =
type t = lr1state
let compare s1 s2 =
let c = core s1 - core s2 in
if c <> 0 then c else compare s1 s2
(* A facility for assigning unique numbers to LR(1) states. *)
let new_numbering () =
let m = ref 0 in
let number : lr1state -> int =
M.memoize (fun (_ : lr1state) -> Misc.postincrement m)
and current () =
number, current
(* This function determines whether two (core-equivalent) states are
compatible, according to a criterion that is close to Pager's weak
compatibility criterion.
......@@ -114,6 +114,13 @@ val compare: lr1state -> lr1state -> int
val subsume: lr1state -> lr1state -> bool
(* A facility for assigning unique numbers to LR(1) states. The call
[new_numbering] returns a pair of functions [number, current], where
[number] maps LR(1) states to unique (freshly assigned) numbers and
[current] returns the next available number. *)
val new_numbering: unit -> (lr1state -> int) * (unit -> int)
(* A slightly modified version of Pager's weak compatibility
criterion. The two states must have the same core. *)
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