201 def re_closeo(l1: List[Rexp], l2: List[Rexp], re_init: Rexp): Rexp = l1 match { |
201 def re_closeo(l1: List[Rexp], l2: List[Rexp], re_init: Rexp): Rexp = l1 match { |
202 case Nil => re_init |
202 case Nil => re_init |
203 case c::cs => if(nullable(c)) re_closeo(cs, l2.tail, ALT(re_init, l2.head) ) |
203 case c::cs => if(nullable(c)) re_closeo(cs, l2.tail, ALT(re_init, l2.head) ) |
204 else re_closeo(cs, l2.tail, re_init) |
204 else re_closeo(cs, l2.tail, re_init) |
205 } |
205 } |
|
206 |
206 //HERE |
207 //HERE |
207 def closed_string_dero(r1: Rexp, r2: Rexp, s: List[Char]): Rexp = { |
208 def closed_string_dero(r1: Rexp, r2: Rexp, s: List[Char]): Rexp = { |
208 val l1 = der_seqo(r1, s, Nil) |
209 val l1 = der_seqo(r1, s, Nil) |
209 val l2 = der_seq_revo(r2, s, Nil) |
210 val l2 = der_seq_revo(r2, s, Nil) |
210 val Re = re_closeo((l1.reverse).tail, l2.tail, SEQ(l1.last, l2.head)) |
211 val Re = re_closeo((l1.reverse).tail, l2.tail, SEQ(l1.last, l2.head)) |
471 val rs_simp = rs.map(bsimp) |
472 val rs_simp = rs.map(bsimp) |
472 val flat_res = flats(rs_simp) |
473 val flat_res = flats(rs_simp) |
473 val dist_res = distinctBy(flat_res, erase) |
474 val dist_res = distinctBy(flat_res, erase) |
474 dist_res match { |
475 dist_res match { |
475 case Nil => AZERO |
476 case Nil => AZERO |
476 case s :: Nil => fuse(bs1, s) |
477 case r :: Nil => fuse(bs1, r) |
477 case rs => AALTS(bs1, rs) |
478 case rs => AALTS(bs1, rs) |
478 } |
479 } |
479 } |
480 } |
480 //case ASTAR(bs, r) => ASTAR(bs, bsimp(r)) |
481 //case ASTAR(bs, r) => ASTAR(bs, bsimp(r)) |
481 case r => r |
482 case r => r |
482 } |
483 } |
|
484 //only print at the top level |
|
485 |
483 def find_pos(v: Val, rs: List[ARexp]): Int = (v, rs) match{ |
486 def find_pos(v: Val, rs: List[ARexp]): Int = (v, rs) match{ |
484 case (v, r::Nil) => 0 |
487 case (v, r::Nil) => 0 |
485 case (Right(v), r::rs) => find_pos(v, rs) + 1 |
488 case (Right(v), r::rs) => find_pos(v, rs) + 1 |
486 case (Left(v), r::rs) => 0 |
489 case (Left(v), r::rs) => 0 |
487 //case (v, _) => 0 |
490 //case (v, _) => 0 |
526 case ((r1s, v1s), (r2s, v2s)) => (ASEQ(bs1, r1s, r2s), Sequ(v1s, v2s)) |
529 case ((r1s, v1s), (r2s, v2s)) => (ASEQ(bs1, r1s, r2s), Sequ(v1s, v2s)) |
527 } |
530 } |
528 case (AALTS(bs1, rs), v) => { |
531 case (AALTS(bs1, rs), v) => { |
529 //phase 1 transformation so that aalts(bs1, rs) => aalts(bs1, rsf) and v => vf |
532 //phase 1 transformation so that aalts(bs1, rs) => aalts(bs1, rsf) and v => vf |
530 val init_ind = find_pos(v, rs) |
533 val init_ind = find_pos(v, rs) |
531 //println(rs) |
|
532 //println(v) |
|
533 val vs = bsimp2(rs(init_ind), remove(v, rs))//remove all the outer layers of left and right in v to match the regx rs[i] |
534 val vs = bsimp2(rs(init_ind), remove(v, rs))//remove all the outer layers of left and right in v to match the regx rs[i] |
534 //println(vs) |
535 //println(vs) |
535 val rs_simp = rs.map(bsimp) |
536 val rs_simp = rs.map(bsimp) |
536 val vs_kernel = rs_simp(init_ind) match { |
537 val vs_kernel = rs_simp(init_ind) match { |
537 case AALTS(bs2, rs2) => remove(vs._2, rs2)//remove the secondary layer of left and right |
538 case AALTS(bs2, rs2) => remove(vs._2, rs2)//remove the secondary layer of left and right |
538 case r => vs._2 |
539 case r => vs._2 |
539 } |
540 } |
540 val flat_res = flats(rs_simp) |
541 val flat_res = flats(rs_simp) |
541 //println(rs_simp) |
|
542 //println(flat_res) |
|
543 //println(init_ind) |
|
544 val vs_for_coating = if(isend(vs._2, rs_simp, init_ind)||flat_res.length == 1) vs_kernel else Left(vs_kernel) |
542 val vs_for_coating = if(isend(vs._2, rs_simp, init_ind)||flat_res.length == 1) vs_kernel else Left(vs_kernel) |
545 //println(vs_for_coating) |
|
546 val r_s = rs_simp(init_ind)//or vs._1 |
543 val r_s = rs_simp(init_ind)//or vs._1 |
547 val shift = flats_vsimp(rs_simp, init_ind) + find_pos_aux(vs._2, rs_simp(init_ind)) |
544 val shift = flats_vsimp(rs_simp, init_ind) + find_pos_aux(vs._2, rs_simp(init_ind)) |
548 //println(shift) |
|
549 val new_ind = init_ind + shift |
545 val new_ind = init_ind + shift |
550 //println("new ind:") |
|
551 //println(new_ind) |
|
552 val vf = coat(vs_for_coating, new_ind) |
546 val vf = coat(vs_for_coating, new_ind) |
553 //println("vf:") |
|
554 //println(vf) |
|
555 //flats2 returns a list of regex and a single v |
547 //flats2 returns a list of regex and a single v |
556 //now |- vf: ALTS(bs1, flat_res) |
548 //now |- vf: ALTS(bs1, flat_res) |
557 |
|
558 //phase 2 transformation so that aalts(bs1, rsf) => aalts(bs, rsdb) and vf => vdb |
549 //phase 2 transformation so that aalts(bs1, rsf) => aalts(bs, rsdb) and vf => vdb |
559 val dist_res = distinctBy(flat_res, erase) |
550 val dist_res = distinctBy(flat_res, erase) |
560 val front_part = distinctBy(flat_res.slice(0, new_ind + 1), erase) |
551 val front_part = distinctBy(flat_res.slice(0, new_ind + 1), erase) |
561 //val size_reduction = new_ind + 1 - front_part.length |
552 //val size_reduction = new_ind + 1 - front_part.length |
562 //println(flat_res.length) |
|
563 //println(dist_res) |
|
564 //println(front_part) |
|
565 val vdb = if(dist_res.length == front_part.length )//that means the regex we are interested in is at the end of the list |
553 val vdb = if(dist_res.length == front_part.length )//that means the regex we are interested in is at the end of the list |
566 { |
554 { |
567 coat(vs_kernel, front_part.length - 1) |
555 coat(vs_kernel, front_part.length - 1) |
568 } |
556 } |
569 else{ |
557 else{ |