# HG changeset patch # User Chengsong # Date 1552484034 0 # Node ID 99f4459d9bb6ad2bde30403437f7a95c1965d598 # Parent 902326e1615a44a86954d8480a01a81f37550e9b i diff -r 902326e1615a -r 99f4459d9bb6 Brexp.scala --- a/Brexp.scala Wed Mar 13 13:14:38 2019 +0000 +++ b/Brexp.scala Wed Mar 13 13:33:54 2019 +0000 @@ -29,6 +29,18 @@ case BSEQ(r1, r2) => brnullable(r1) && brnullable(r2) case BSTAR(_) => true } + //this function tells bspill when converting a brexp into a list of rexps + //the conversion : (a+b)*c -> {a*c, b*c} can only happen when a+b is generated from scratch (e.g. when deriving a seq) + //or is from the original regex but have been "touched" (i.e. have been derived) + //Why make this distinction? Look at the following example: + //r = (c+cb)+c(a+b) + // r\c = (1+b)+(a+b) + //after simplification + // (r\c)simp= 1+b+a + //we lost the structure that tells us 1+b should be grouped together and a grouped as itself + //however in our brexp simplification, + //(r\c)br_simp = 1+b+(a+b) + //we do not allow the bracket to be opened as it is from the original expression and have not been touched def brder(c: Char, r: BRexp) : BRexp = r match { case BZERO => BZERO case BONE => BZERO @@ -127,12 +139,23 @@ List(ALTS(rs.map(berase))) } - def bspill(r: BRexp): List[Rexp] = {//need to take SEQ(SEQ...) and many other structs into consideration - r match {//TODO: break chain rs according to bs + //this function converts a brexp into a list of rexps + //the conversion mainly about this: (a+b)*c -> {a*c, b*c} if a+b is generated from scratch (e.g. when deriving a seq) + //or is from the original regex but have been "touched" (i.e. have been derived) + //Why make this distinction? Look at the following example: + //r = (c+cb)+c(a+b) + // r\c = (1+b)+(a+b) + //after simplification + // (r\c)simp= 1+b+a + //we lost the structure that tells us 1+b should be grouped together and a grouped as itself + //however in our brexp simplification, + //(r\c)br_simp = 1+b+(a+b) + //we do not allow the bracket to be opened as it is from the original expression and have not been touched + def bspill(r: BRexp): List[Rexp] = { + r match { case BALTS(bs, rs) => { break_chain(bs, rs) } - //rs.flatMap(r1 => bspill(r1) ).toSet how to write if r's bit says no, do not split it with the adjacent regex? case BSEQ(r2, r3) => bspill(r2).map( a => if(a == ONE) berase(r3) else SEQ(a, berase(r3)) ) case BZERO => List() case r => List(berase(r)) diff -r 902326e1615a -r 99f4459d9bb6 Spiral.scala --- a/Spiral.scala Wed Mar 13 13:14:38 2019 +0000 +++ b/Spiral.scala Wed Mar 13 13:33:54 2019 +0000 @@ -303,16 +303,6 @@ val anatomy = bspill(simp_res) //track if the number of regular expressions exceeds those in the PD set(remember PD means the pders over A*) if(f(anatomy, pd) == false){ - /*println("regular expression") - println(regx_tree(r)) - println("string at " + i) - println(s) - println("partial derivatives") - (pd.foreach(a => println(regx_tree(a)))) - println("simp result") - println(bregx_tree(simp_res)) - println("bspill result") - (anatomy.foreach(a => println(regx_tree(a))))*/ println(size(berase(syncsimp_res))) println(size(berase(simp_res))) println(anatomy.map(size).sum)