Spiral.scala
changeset 7 1572760ff866
parent 6 26b40a985622
child 8 e67c0ea1ca73
equal deleted inserted replaced
6:26b40a985622 7:1572760ff866
    35         //val Some(d) = alphabet.find(f)
    35         //val Some(d) = alphabet.find(f)
    36         d match {
    36         d match {
    37           case '\n' => elem("\\n")
    37           case '\n' => elem("\\n")
    38           case '\t' => elem("\\t")
    38           case '\t' => elem("\\t")
    39           case ' ' => elem("space")
    39           case ' ' => elem("space")
    40           case d => elem(d.toString)
    40           case d => if(bs.isEmpty)  elem(d.toString) else elem(d.toString++" ") beside elem(bs.toString)
    41         }   
    41         }   
    42       }
    42       }
    43       case AONE(bs) => {
    43       case AONE(bs) => {
    44         elem("ONE")
    44         if(bs.isEmpty)  elem("ONE") else elem("ONE ") beside elem(bs.toString)
    45       }
    45       }
    46       case AZERO => {
    46       case AZERO => {
    47         elem("ZERO")
    47         elem("ZERO") 
    48       }
    48       }
    49       case ASEQ(bs, r1, r2) => {
    49       case ASEQ(bs, r1, r2) => {
    50         binary_print("SEQ", r1, r2)
    50         annotated_binary_print("SEQ", r1, r2, bs)
    51       }
    51       }
    52       case AALTS(bs, rs) => {
    52       case AALTS(bs, rs) => {
    53         //elem("Awaiting completion")
    53         //elem("Awaiting completion")
    54         list_print("ALT", rs)
    54         annotated_list_print("ALT", rs, bs)  
    55       }
    55       }
    56       case ASTAR(bs, r) => {
    56       case ASTAR(bs, r) => {
    57         list_print("STA", List(r))
    57         annotated_list_print("STA", List(r), bs)
    58       }
    58       }
    59     } 
    59     } 
    60   }
    60   }
    61   def aregx_tree(r: ARexp): Element = {
    61   def aregx_tree(r: ARexp): Element = {
    62     r match {
    62     r match {
   109           (head left_align (port beside pref) ) left_align tail_print(rs1)
   109           (head left_align (port beside pref) ) left_align tail_print(rs1)
   110         }
   110         }
   111       }
   111       }
   112     }
   112     }
   113   }
   113   }
       
   114     def annotated_list_print(name: String, rs: List[ARexp], bs: List[Bit]): Element = {
       
   115     rs match {
       
   116       case r::Nil => {
       
   117         val pref = annotated_tree(r)
       
   118         val head = if(bs.isEmpty) elem(name) else elem(name ++ " ") beside elem(bs.toString)
       
   119         (head left_align (port up_align pref) ) 
       
   120       }
       
   121       case r2::r1::Nil => {
       
   122         annotated_binary_print(name, r2, r1, bs)
       
   123       }
       
   124       case r::rs1 => {
       
   125         val pref = annotated_tree(r)
       
   126         val head = if (bs.isEmpty) elem(name) else elem(name ++ " ") beside elem(bs.toString)
       
   127         if (pref.height > 1){
       
   128           val link = elem('|', 1, pref.height - 1)
       
   129           (head left_align ((port above link) beside pref)) left_align annotated_tail_print(rs1)    
       
   130         }
       
   131         else{
       
   132           (head left_align (port beside pref) ) left_align annotated_tail_print(rs1)
       
   133         }
       
   134       }
       
   135     }
       
   136   }
       
   137 
       
   138   def annotated_tail_print(rs: List[ARexp]): Element = {
       
   139     rs match {
       
   140       case r2::r1::Nil => {
       
   141         val pref = annotated_tree(r2)
       
   142         val suff = annotated_tree(r1)
       
   143         if (pref.height > 1){
       
   144           val link = elem('|', 1, pref.height - 1)
       
   145           ((port above link) beside pref) left_align (port up_align suff)
       
   146         }
       
   147         else{
       
   148           (port beside pref) left_align (port up_align suff)
       
   149         } 
       
   150       }
       
   151       case r2::rs1 => {
       
   152         val pref = annotated_tree(r2)
       
   153         
       
   154         if (pref.height > 1){
       
   155           val link = elem('|', 1, pref.height - 1)
       
   156           ((port above link) beside pref) left_align annotated_tail_print(rs1)//(port up_align tail_print(rs1) )
       
   157         }
       
   158         else{
       
   159           (port beside pref) left_align annotated_tail_print(rs1)//(port up_align tail_print(rs1))
       
   160         } 
       
   161         //pref left_align tail_print(rs1)
       
   162       }
       
   163     }
       
   164   }
       
   165 
   114   def tail_print(rs: List[ARexp]): Element = {
   166   def tail_print(rs: List[ARexp]): Element = {
   115     rs match {
   167     rs match {
   116       case r2::r1::Nil => {
   168       case r2::r1::Nil => {
   117         val pref = aregx_tree(r2)
   169         val pref = aregx_tree(r2)
   118         val suff = aregx_tree(r1)
   170         val suff = aregx_tree(r1)
   140   }
   192   }
   141 
   193 
   142   def binary_print(name: String, r1: ARexp, r2: ARexp): Element = {
   194   def binary_print(name: String, r1: ARexp, r2: ARexp): Element = {
   143     val pref = aregx_tree(r1)
   195     val pref = aregx_tree(r1)
   144     val suff = aregx_tree(r2)
   196     val suff = aregx_tree(r2)
   145     val head = elem(name)
   197     val head = elem(name) 
   146     if (pref.height > 1){
   198     if (pref.height > 1){
   147       val link = elem('|', 1, pref.height - 1)
   199       val link = elem('|', 1, pref.height - 1)
   148       (head left_align ((port above link) beside pref) ) left_align (port up_align suff)
   200       (head left_align ((port above link) beside pref) ) left_align (port up_align suff)
   149     }
   201     }
   150     else{
   202     else{
   151       (head left_align (port beside pref) ) left_align (port up_align suff)
   203       (head left_align (port beside pref) ) left_align (port up_align suff)
   152     }
   204     }
   153   }
   205   }
       
   206   def annotated_binary_print(name: String, r1: ARexp, r2: ARexp, bs: List[Bit]): Element = {
       
   207     val pref = annotated_tree(r1)
       
   208     val suff = annotated_tree(r2)
       
   209     val head = if (bs.isEmpty) elem(name) else elem(name ++ " ") beside elem(bs.toString)
       
   210     if (pref.height > 1){
       
   211       val link = elem('|', 1, pref.height - 1)
       
   212       (head left_align ((port above link) beside pref) ) left_align (port up_align suff)
       
   213     }
       
   214     else{
       
   215       (head left_align (port beside pref) ) left_align (port up_align suff)
       
   216     }
       
   217   }
       
   218 
   154   val arr_of_size = ListBuffer.empty[Int]
   219   val arr_of_size = ListBuffer.empty[Int]
   155 
   220 
   156   def pC(r: Rexp): Set[Rexp] = {//PD's companion
   221   def pC(r: Rexp): Set[Rexp] = {//PD's companion
   157     r match {
   222     r match {
   158       case SEQ(r1, r2) => pC(r2)
   223       case SEQ(r1, r2) => pC(r2)
   333         println(size(berase(simp_res)))
   398         println(size(berase(simp_res)))
   334         println(bregx_tree(simp_res))
   399         println(bregx_tree(simp_res))
   335         println(s)
   400         println(s)
   336         println(i)
   401         println(i)
   337         println(r)
   402         println(r)
   338         println()
       
   339         println(anatomy.map(size).sum)
   403         println(anatomy.map(size).sum)
   340         println(pd.map(size).sum)
   404         println(pd.map(size).sum)
   341       }  
   405       }  
   342       old = simp_res
   406       old = simp_res
   343       syncold = syncsimp_res
   407       syncold = syncsimp_res
   387             println("original regex")
   451             println("original regex")
   388             println(r)
   452             println(r)
   389             println("regex after ders simp")
   453             println("regex after ders simp")
   390             println(nangao)
   454             println(nangao)
   391             println("regex after ders")
   455             println("regex after ders")
   392             println(bders(ss.toList, r))
   456             println(annotated_tree(bders(ss.toList, r)))
   393             println("regex after ders and then a single simp")
   457             println("regex after ders and then a single simp")
   394             println(easy)
   458             println(annotated_tree(easy))
   395           }
   459           }
   396         }
   460         }
   397     }
   461     }
       
   462   }
       
   463   def radical_correctness(){
       
   464     enum(3, "abc").map(tests_blexer_simp(strs(3, "abc"))).toSet
       
   465     random_pool(1, 5).map(tests_blexer_simp(strs(5, "abc"))).toSet
   398   }
   466   }
   399   def main(args: Array[String]) {
   467   def main(args: Array[String]) {
   400     //check_all()   
   468     //check_all()   
   401     //enum(3, "abc").map(tests_blexer_simp(strs(3, "abc"))).toSet
   469     //radical_correctness()
   402     //
   470     correctness_proof_convenient_path()
   403     random_pool(1, 5).map(tests_blexer_simp(strs(5, "abc"))).toSet
       
   404     //correctness_proof_convenient_path()
       
   405   } 
   471   } 
   406 }
   472 }
   407 
   473