progs/re4.scala
changeset 467 b5ec11e89768
parent 455 1dbf84ade62c
child 477 b78664a24f5d
equal deleted inserted replaced
466:9ec26df6d289 467:b5ec11e89768
    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))