app7.scala
changeset 7 73cf4406b773
child 66 9215b9fb8852
equal deleted inserted replaced
6:0da19c346e24 7:73cf4406b773
       
     1 def matches(r: Rexp, s: String) : Boolean = 
       
     2   nullable(derivs(r, s.toList))
       
     3 
       
     4 
       
     5 /* Examples */
       
     6 
       
     7 println(matches(SEQ(SEQ(CHAR('c'), CHAR('a')), CHAR('b')),"cab"))
       
     8 println(matches(STAR(CHAR('a')),"aaa"))
       
     9 
       
    10 /* Convenience using implicits */
       
    11 implicit def string2rexp(s : String) : Rexp = {
       
    12   s.foldRight (EMPTY: Rexp) ( (c, r) => SEQ(CHAR(c), r) )
       
    13 }
       
    14 
       
    15 println(matches("cab" ,"cab"))
       
    16 println(matches(STAR("a"),"aaa"))
       
    17 println(matches(STAR("a"),"aaab"))