--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app7.scala Thu Sep 27 11:59:41 2012 +0100
@@ -0,0 +1,17 @@
+def matches(r: Rexp, s: String) : Boolean =
+ nullable(derivs(r, s.toList))
+
+
+/* Examples */
+
+println(matches(SEQ(SEQ(CHAR('c'), CHAR('a')), CHAR('b')),"cab"))
+println(matches(STAR(CHAR('a')),"aaa"))
+
+/* Convenience using implicits */
+implicit def string2rexp(s : String) : Rexp = {
+ s.foldRight (EMPTY: Rexp) ( (c, r) => SEQ(CHAR(c), r) )
+}
+
+println(matches("cab" ,"cab"))
+println(matches(STAR("a"),"aaa"))
+println(matches(STAR("a"),"aaab"))