progs/re4.scala
changeset 467 3fc9b036321d
parent 455 192f4c59633e
child 477 28e872e7efb3
equal deleted inserted replaced
466:97232962afbb 467:3fc9b036321d
    55   case (Nil, r) => r
    55   case (Nil, r) => r
    56   case (s, ZERO) => ZERO
    56   case (s, ZERO) => ZERO
    57   case (s, ONE) => if (s == Nil) ONE else ZERO
    57   case (s, ONE) => if (s == Nil) ONE else ZERO
    58   case (s, CHAR(c)) => if (s == List(c)) ONE else 
    58   case (s, CHAR(c)) => if (s == List(c)) ONE else 
    59                        if (s == Nil) CHAR(c) else ZERO
    59                        if (s == Nil) CHAR(c) else ZERO
    60   case (s, ALT(r1, r2)) => ALT(ders2(s, r2), ders2(s, r2))
    60   case (s, ALT(r1, r2)) => ALT(ders2(s, r1), ders2(s, r2))
    61   case (c::s, r) => ders2(s, simp(der(c, r)))
    61   case (c::s, r) => ders2(s, simp(der(c, r)))
    62 }
    62 }
    63 
    63 
    64 // main matcher function
    64 // main matcher function
    65 def matcher(r: Rexp, s: String) : Boolean = nullable(ders2(s.toList, r))
    65 def matcher(r: Rexp, s: String) : Boolean = nullable(ders2(s.toList, r))