Commit ffa70ca5 authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2003-10-13 21:21:53 by cvscast] Oubli

Original author: cvscast
Date: 2003-10-13 21:21:53+00:00
parent 5b821745
type regexp =
<chr> Char
| <seq> (regexp,regexp)
| <alt> (regexp,regexp)
| <star> regexp
type f = String -> Bool
let loop (re : regexp, k : f) : f = fun (s : String) : Bool = match re with
| <chr> p -> (match s with (c,s) -> (c = p) && (k s) | _ -> `false)
| <seq> (r1,r2) -> loop (r1, (loop (r2,k))) s
| <alt> (r1,r2) -> loop (r1,k) s || loop (r2,k) s
| <star> r -> loop (r,(loop (re,k))) s || k s
let accept (re : regexp) : f =
loop (re, fun (String -> Bool) [] -> `true | _ -> `false)
let re = <seq> (<star> <chr>'a', <star><chr>'b')
let strs = [ "aaabbb" "abba" "aaab" "a" "" ]
let [] = print ((string_of (map strs with x -> (x,accept re x))) @ ['\n'])
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