app7.scala
author Christian Urban <urbanc@in.tum.de>
Wed, 14 Nov 2012 00:02:38 +0000
changeset 60 68d664c204d2
parent 7 73cf4406b773
child 66 9215b9fb8852
permissions -rw-r--r--
updated

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