/[svn]/web/regexp.cd
ViewVC logotype

Contents of /web/regexp.cd

Parent Directory Parent Directory | Revision Log Revision Log


Revision 725 - (show annotations)
Tue Jul 10 17:59:03 2007 UTC (5 years, 10 months ago) by abate
File size: 670 byte(s)
[r2003-10-13 21:21:53 by cvscast] Oubli

Original author: cvscast
Date: 2003-10-13 21:21:53+00:00
1 type regexp =
2 <chr> Char
3 | <seq> (regexp,regexp)
4 | <alt> (regexp,regexp)
5 | <star> regexp
6
7 type f = String -> Bool
8
9 let loop (re : regexp, k : f) : f = fun (s : String) : Bool = match re with
10 | <chr> p -> (match s with (c,s) -> (c = p) && (k s) | _ -> `false)
11 | <seq> (r1,r2) -> loop (r1, (loop (r2,k))) s
12 | <alt> (r1,r2) -> loop (r1,k) s || loop (r2,k) s
13 | <star> r -> loop (r,(loop (re,k))) s || k s
14
15 let accept (re : regexp) : f =
16 loop (re, fun (String -> Bool) [] -> `true | _ -> `false)
17
18 let re = <seq> (<star> <chr>'a', <star><chr>'b')
19 let strs = [ "aaabbb" "abba" "aaab" "a" "" ]
20 let [] = print ((string_of (map strs with x -> (x,accept re x))) @ ['\n'])

CVS Admin">CVS Admin
ViewVC Help
Powered by ViewVC 1.1.5