446 } |
446 } |
447 } |
447 } |
448 //case ASTAR(bs, r) => ASTAR(bs, bsimp(r)) |
448 //case ASTAR(bs, r) => ASTAR(bs, bsimp(r)) |
449 case r => r |
449 case r => r |
450 } |
450 } |
451 def find_pos(v: Val, rs: List[Rexp]): Int = (rs, v) match{ |
451 def find_pos(v: Val, rs: List[Rexp]): Int = (v, rs) match{ |
452 case (Right(v), r::Nil) => 1 |
452 case (Right(v), r::Nil) => 1 |
453 case (Left(v), r::rs) => 0 |
453 case (Left(v), r::rs) => 0 |
454 case (Right(v), r::rs) => find_pos(v, rs) + 1 |
454 case (Right(v), r::rs) => find_pos(v, rs) + 1 |
455 case (v, _) => 0 |
455 case (v, _) => 0 |
456 } |
456 } |
457 def remove(v: Val, rs: List[Rexp]) : Val = (rs,v) match {//remove the outmost layer of ALTS's Left and Right |
457 def remove(v: Val, rs: List[Rexp]) : Val = (v,rs) match {//remove the outmost layer of ALTS's Left and Right |
458 case (Right(v), r::Nil) => v |
458 case (Right(v), r::Nil) => v |
459 case (Left(v), r::rs) => v |
459 case (Left(v), r::rs) => v |
460 case (Right(v), r::rs) => remove(v, rs) |
460 case (Right(v), r::rs) => remove(v, rs) |
461 } |
461 } |
462 def simple_end(v: Value): Boolean = v match { |
462 def simple_end(v: Val): Boolean = v match { |
463 case Left(v) => return false |
463 case Left(v) => return false |
464 case Right(v) => return simple_end(v) |
464 case Right(v) => return simple_end(v) |
465 case v => return true |
465 case v => return true |
466 } |
466 } |
467 def isend(v: Val, rs: List[Rexp], position: Int): Boolean = { |
467 def isend(v: Val, rs: List[ARexp], position: Int): Boolean = { |
468 val rsbh = rs.slice(position, rs.length) |
468 val rsbh = rs.slice(position, rs.length) |
469 val out_end = if(flats(rsbh) == Nil) true else false |
469 val out_end = if(flats(rsbh) == Nil) true else false |
470 val inner_end = simple_end(v) |
470 val inner_end = simple_end(v) |
471 inner_end && out_end |
471 inner_end && out_end |
472 } |
472 } |
473 def get_coat(v: Val, rs: List[Rexp], vs: Val): Val = (rs, v) match{//the dual operation of remove(so-called by myself) |
473 def get_coat(v: Val, rs: List[Rexp], vs: Val): Val = (v, rs) match{//the dual operation of remove(so-called by myself) |
474 case (Right(v), r::Nil) => Right(vs) |
474 case (Right(v), r::Nil) => Right(vs) |
475 case (Left(v), r::rs) => Left(vs) |
475 case (Left(v), r::rs) => Left(vs) |
476 case (Right(v), r::rs) => Right(get_coat(v, rs, vs)) |
476 case (Right(v), r::rs) => Right(get_coat(v, rs, vs)) |
477 } |
477 } |
478 def coat(v: Val, i: Int) : Val = i match { |
478 def coat(v: Val, i: Int) : Val = i match { |
479 case 0 => v |
479 case 0 => v |
480 case i => coat(Right(v), i - 1) |
480 case i => coat(Right(v), i - 1) |
481 } |
481 } |
|
482 /* |
482 def bsimp2(r: ARexp, v: Val): (ARexp, Val => Val) = (r,v) match{ |
483 def bsimp2(r: ARexp, v: Val): (ARexp, Val => Val) = (r,v) match{ |
483 case (ASEQ(bs1, r1, r2), v) => (bsimp2(r1), bsimp2(r2)) match { |
484 case (ASEQ(bs1, r1, r2), v) => (bsimp2(r1), bsimp2(r2)) match { |
484 case ((AZERO, _), (_, _) )=> (AZERO, undefined) |
485 case ((AZERO, _), (_, _) )=> (AZERO, undefined) |
485 case ((_, _), (AZERO, _)) => (AZERO, undefined) |
486 case ((_, _), (AZERO, _)) => (AZERO, undefined) |
486 case ((AONE(bs2), f1) , (r2s, f2)) => (fuse(bs1 ++ bs2, r2s), lambda v => v match { case Sequ(_, v) => f2(v) } ) |
487 case ((AONE(bs2), f1) , (r2s, f2)) => (fuse(bs1 ++ bs2, r2s), lambda v => v match { case Sequ(_, v) => f2(v) } ) |
508 case rs => AALTS(bs1, rs) |
509 case rs => AALTS(bs1, rs) |
509 } |
510 } |
510 } |
511 } |
511 //case ASTAR(bs, r) => ASTAR(bs, bsimp(r)) |
512 //case ASTAR(bs, r) => ASTAR(bs, bsimp(r)) |
512 case r => r |
513 case r => r |
513 } |
514 }*/ |
514 def super_bsimp(r: ARexp): ARexp = r match { |
515 def super_bsimp(r: ARexp): ARexp = r match { |
515 case ASEQ(bs1, r1, r2) => (super_bsimp(r1), super_bsimp(r2)) match { |
516 case ASEQ(bs1, r1, r2) => (super_bsimp(r1), super_bsimp(r2)) match { |
516 case (AZERO, _) => AZERO |
517 case (AZERO, _) => AZERO |
517 case (_, AZERO) => AZERO |
518 case (_, AZERO) => AZERO |
518 case (AONE(bs2), r2s) => fuse(bs1 ++ bs2, r2s)//万一是(r1, alts(rs))这种形式呢 |
519 case (AONE(bs2), r2s) => fuse(bs1 ++ bs2, r2s)//万一是(r1, alts(rs))这种形式呢 |