diff -r c9027db225cc -r 6a43ea9305ba progs/fsharp/re.ml --- a/progs/fsharp/re.ml Fri Mar 18 15:03:54 2016 +0000 +++ b/progs/fsharp/re.ml Sat Mar 19 23:27:29 2016 +0000 @@ -1,7 +1,7 @@ type rexp = - NULL - | EMPTY + ZERO + | ONE | CHAR of char | ALT of rexp * rexp | SEQ of rexp * rexp @@ -9,7 +9,7 @@ | RECD of string * rexp;; type value = - Void + Empty | Chr of char | Sequ of value * value | Left of value @@ -24,7 +24,7 @@ (* some helper functions for rexps *) let rec seq s = match s with - | [] -> EMPTY + | [] -> ONE | [c] -> CHAR(c) | c::cs -> SEQ(CHAR(c), seq cs);; @@ -41,15 +41,15 @@ let ($) x r = RECD(x, r);; let alts rs = match rs with - | [] -> NULL + | [] -> ZERO | [r] -> r | r::rs -> List.fold (++) r rs;; (* size of a regular expressions - for testing purposes *) let rec size r = match r with - | NULL -> 1 - | EMPTY -> 1 + | ZERO -> 1 + | ONE -> 1 | CHAR(_) -> 1 | ALT(r1, r2) -> 1 + (size r1) + (size r2) | SEQ(r1, r2) -> 1 + (size r1) + (size r2) @@ -59,8 +59,8 @@ (* nullable function: tests whether the regular expression can recognise the empty string *) let rec nullable r = match r with - | NULL -> false - | EMPTY -> true + | ZERO -> false + | ONE -> true | CHAR(_) -> false | ALT(r1, r2) -> nullable(r1) || nullable(r2) | SEQ(r1, r2) -> nullable(r1) && nullable(r2) @@ -69,9 +69,9 @@ (* derivative of a regular expression r w.r.t. a character c *) let rec der c r = match r with - | NULL -> NULL - | EMPTY -> NULL - | CHAR(d) -> if c = d then EMPTY else NULL + | ZERO -> ZERO + | ONE -> ZERO + | CHAR(d) -> if c = d then ONE else ZERO | ALT(r1, r2) -> ALT(der c r1, der c r2) | SEQ(r1, r2) -> if nullable r1 then ALT(SEQ(der c r1, r2), der c r2) @@ -86,7 +86,7 @@ (* extracts a string from value *) let rec flatten v = match v with - | Void -> "" + | Empty -> "" | Chr(c) -> System.Convert.ToString(c) | Left(v) -> flatten v | Right(v) -> flatten v @@ -97,7 +97,7 @@ (* extracts an environment from a value *) let rec env v = match v with - | Void -> [] + | Empty -> [] | Chr(c) -> [] | Left(v) -> env v | Right(v) -> env v @@ -111,7 +111,7 @@ (* the value for a nullable rexp *) let rec mkeps r = match r with - | EMPTY -> Void + | ONE -> Empty | ALT(r1, r2) -> if nullable r1 then Left(mkeps r1) else Right(mkeps r2) | SEQ(r1, r2) -> Sequ(mkeps r1, mkeps r2) @@ -127,7 +127,7 @@ | SEQ(r1, r2), Right(v2) -> Sequ(mkeps r1, inj r2 c v2) | ALT(r1, r2), Left(v1) -> Left(inj r1 c v1) | ALT(r1, r2), Right(v2) -> Right(inj r2 c v2) - | CHAR(d), Void -> Chr(d) + | CHAR(d), Empty -> Chr(d) | RECD(x, r1), _ -> Rec(x, inj r1 c v);; (* some "rectification" functions for simplification *) @@ -139,8 +139,8 @@ | Left(v) -> Left(f1 v);; let f_seq f1 f2 = fun v -> match v with Sequ(v1, v2) -> Sequ(f1 v1, f2 v2);; -let f_seq_Void1 f1 f2 = fun v -> Sequ(f1 Void, f2 v);; -let f_seq_Void2 f1 f2 = fun v -> Sequ(f1 v, f2 Void);; +let f_seq_Empty1 f1 f2 = fun v -> Sequ(f1 Empty, f2 v);; +let f_seq_Empty2 f1 f2 = fun v -> Sequ(f1 v, f2 Empty);; let f_rec f = fun v -> match v with Rec(x, v) -> Rec(x, f v);; @@ -151,18 +151,18 @@ let (r1s, f1s) = simp r1 in let (r2s, f2s) = simp r2 in (match r1s, r2s with - NULL, _ -> (r2s, f_right f2s) - | _, NULL -> (r1s, f_left f1s) + ZERO, _ -> (r2s, f_right f2s) + | _, ZERO -> (r1s, f_left f1s) | _, _ -> if r1s = r2s then (r1s, f_left f1s) else (ALT (r1s, r2s), f_alt f1s f2s)) | SEQ(r1, r2) -> let (r1s, f1s) = simp r1 in let (r2s, f2s) = simp r2 in (match r1s, r2s with - NULL, _ -> (NULL, f_right f2s) - | _, NULL -> (NULL, f_left f1s) - | EMPTY, _ -> (r2s, f_seq_Void1 f1s f2s) - | _, EMPTY -> (r1s, f_seq_Void2 f1s f2s) + ZERO, _ -> (ZERO, f_right f2s) + | _, ZERO -> (ZERO, f_left f1s) + | ONE, _ -> (r2s, f_seq_Empty1 f1s f2s) + | _, ONE -> (r1s, f_seq_Empty2 f1s f2s) | _, _ -> (SEQ(r1s, r2s), f_seq f1s f2s)) | RECD(x, r1) -> let (r1s, f1s) = simp r1 in