progs/re3.scala
changeset 453 36e5752fa191
parent 441 028816884f70
child 454 edb4ad356c56
equal deleted inserted replaced
452:b93f4d2aeee1 453:36e5752fa191
    29   case SEQ(r1, r2) => 
    29   case SEQ(r1, r2) => 
    30     if (nullable(r1)) ALT(SEQ(der(c, r1), r2), der(c, r2))
    30     if (nullable(r1)) ALT(SEQ(der(c, r1), r2), der(c, r2))
    31     else SEQ(der(c, r1), r2)
    31     else SEQ(der(c, r1), r2)
    32   case STAR(r1) => SEQ(der(c, r1), STAR(r1))
    32   case STAR(r1) => SEQ(der(c, r1), STAR(r1))
    33   case NTIMES(r, i) => 
    33   case NTIMES(r, i) => 
    34     if (i == 0) ZERO else SEQ(der(c, r), NTIMES(r, i - 1))
    34     if (i == 0) ZERO else der(c, SEQ(r, NTIMES(r, i - 1)))
    35 }
    35 }
    36 
    36 
    37 def simp(r: Rexp) : Rexp = r match {
    37 def simp(r: Rexp) : Rexp = r match {
    38   case ALT(r1, r2) => (simp(r1), simp(r2)) match {
    38   case ALT(r1, r2) => (simp(r1), simp(r2)) match {
    39     case (ZERO, r2s) => r2s
    39     case (ZERO, r2s) => r2s