app7.scala
author Christian Urban <urbanc@in.tum.de>
Sun, 14 Oct 2012 23:41:49 +0100
changeset 34 eeff9953a1c1
parent 7 73cf4406b773
child 66 9215b9fb8852
permissions -rw-r--r--
tuned

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"))