--- a/lex_blex_Frankensteined.scala Thu Apr 16 09:14:15 2020 +0100
+++ b/lex_blex_Frankensteined.scala Thu May 07 11:36:15 2020 +0100
@@ -641,7 +641,7 @@
//given the number of right outside it
def coat(v: Val, i: Int) : Val = i match {
case 0 => v
- case i => coat(Right(v), i - 1)
+ case i => if(i > 0) coat(Right(v), i - 1) else {println(v,i); throw new Exception("coat minus")}
}
def decoat(v:Val, i: Int) : Val = i match {
case 0 => v
@@ -752,7 +752,151 @@
case (r, v) => (v => v)
}
//This version takes a regex and a value, return a simplified regex and its corresponding simplified value
- def bsimp2(r: ARexp, v: Val): (ARexp, Val) = (r,v) match{
+ //def flats2(r: Arexp, v: val): (ARexp, Val) = (r, v) match{
+ // case (AALTS(bs, rs), Right(v0)) => rs match {
+ // case Nil => (AALTS(bs, Nil), v)
+ // case AZERO::rs0 => flats2(AALTS(bs, rs0), v0)
+ // case
+ // case (AALTS(bs, rs), Left(v0)) =>
+ //}
+ //liangren qixinxieli zuo yixie shiqing
+ //shi xinzhaobuxuan de moqi
+ //ni yao fanzhangben
+ //na wo jiu zhineng peini fanzhangben
+ //ni xianshuo wo weini zuole haoduohaoduo
+ //na wo jiu haohao gen ni fenxifenxi
+ //ni daodi zuole shenme
+ //ni meizuo shenme
+ //zhishi yinwei ni lei
+ //suoyi ni juede ni zuole haoduo
+ //zuofanyeshi
+ //shi weile ni shiwu cai zuo name jingxi
+ //shiwo de hua meitian sancan huadeshijian
+ //buchaoguo liangxiaoshi
+ //ni zuode henduoshihou doushi weile ziji
+ //ni zuoshiqing de shihou ye zongshi bawo jiaolai bangmang
+ //ni de xiaolv hai hendi
+ //zonghe kanlai
+ //ni buhuizhaoguziji meiyoudandang nenglibuzu haizisi
+ //suoyi wo zui taoyan gennishuozhexie
+ //shuoli bianbuguolai
+ //jiu ba ren xiaoshihoude shiqing nachulaishuo, lai exin ren
+ //nibangwo daoyibeishui, wo buleyujieshou, wo bushuoxiexie
+ //nandao woshuo sheiyaonidaole, zoukai? buyaoni geiwo dao? wo ziji dao?
+ //nishuo qiantou doushi ni zaizuo
+ //zheliwoyao buchong
+ //quancheng ni yigerenzuo yidunfan de cishu
+ //dagai you duoshaoci?
+ //kending you jici, dan bushi duoshu
+ //duoshu shi wo huilai yihou
+ //ni rangwo lai chaocai huozhe lai jieguan zuowan shengyude gongzuo
+ //ni zuo de zhexieshihou
+ //yiban jiushi lianggecai
+ //huozhe yicai yitang
+ //wo hui renwei
+ //zhe shi ni shenti keyi shiying de gongzuoliang
+ //moren ni ziji hui zhaoguhao ziji
+ //ruguo ni leile, yehui lai zhaowo bangmang
+ //suoyi wo moren ni zai zhe qijian shi meiyou
+ //guolao, ruguo you, wo renwei
+ //1 ni meiyou zhaoguhao niziji
+ //2 nimeiyou jishi xiangwo xunqiu bangzhu
+ //3 ni jibensangshi laodongnengli le,
+ //yihou huolu doushi wo lai bao le jiu wanle
+ //niziji meinengli jiu buyao dui zuoshi de ren
+ //tiaosanjiansi
+ //ni shibushi taomi xigecai jiu hui lei
+ //na shuoming
+ //yaome ni tili taicha--jibensangshi laodongli
+ //yaome ni fangfabuheshi(xiaolvdi, zishiyouwenti daozhi shentilaosun)--ni yinggai tiaozheng ziji zuoshide fangfa, women yiqilai zhaozhao yuanyin
+ //cuowu de silushi: nikanwo dou zhemelei le,
+ //shuoming wo zuole henduo, ni bu tiliangwo
+ //ni zuo zhexie doushi yinggaide
+ //yinwei wo shi nimama erqie wo leile
+ def pos_i(rs: List[ARexp], v: Val): Int = (rs, v) match {
+ case (r::Nil, v1) => 0
+ case ( r::rs1, Right(v) ) => pos_i(rs1, v) + 1
+ case ( r::rs1, Left(v) ) => 0
+ }
+ def pos_v(rs: List[ARexp], v: Val): Val = (rs, v) match {
+ case (r::Nil, v1) => v1
+ case (r::rs1, Right(v) ) => pos_v(rs1, v)
+ case (r::rs1, Left(v) ) => v
+ }
+ def unify(rs: List[ARexp], v: Val): Val = {
+ Position( pos_i(rs, v), pos_v(rs, v) )
+ }
+ def deunify(rs_length: Int, v: Val): Val = v match{
+ case Position(i, v0) => {
+ if(i <0) {println(rs_length, v); throw new Exception("deunify minus")}
+ else if(rs_length == 1) {println(v); v}
+ else if(rs_length - 1 == i) coat(v0, i)
+ else coat(Left(v0), i)
+ }
+ case _ => throw new Exception("deunify error")
+ }
+ def flats2(front: List[ARexp], i: Int, rs: List[ARexp], v: Val): (List[ARexp], Val) = v match {
+ case Position(j, v0) => {
+ if (i < 0) (front ::: flats(rs), Position(j, v0) )
+ else if(i == 0){
+ rs match {
+ case AALTS(bs, rs1) :: rs2 => ( (front ::: rs1.map(fuse(bs, _))):::flats(rs2), Position(j + rs1.length - 1, pos_v(rs1, v0)))
+ case r::rs2 => (front ::: List(r) ::: flats(rs2), Position(j, v0))
+ case _ => throw new Exception("flats2 i = 0")
+ }
+ }
+ else{
+ rs match {
+ case AZERO::rs1 => flats2(front, i - 1, rs1, Position(j - 1, v0))
+ case AALTS(bs, rs1) ::rs2 => flats2(front:::rs1.map(fuse(bs, _)), i - 1, rs2, Position(j + rs1.length - 1, v0))
+ case r::rs1 => flats2(front:::List(r), i - 1, rs1, Position(j, v0))
+ case _ => throw new Exception("flats2 i>0")
+ }
+ }
+ }
+ case _ => throw new Exception("flats2 error")
+ }
+ def distinctBy2[B, C](v: Val, xs: List[B], f: B => C, acc: List[C] = Nil, res: List[B] = Nil): (List[B], Val) = xs match {
+ case Nil => (res, v)
+ case (x::xs) => {
+ val re = f(x)
+ if (acc.contains(re)) v match {
+ case Position(i, v0) => distinctBy2(Position(i - 1, v0), xs, f, acc, res)
+ case _ => throw new Exception("dB2")
+ }
+ else distinctBy2(v, xs, f, re::acc, x::res)
+ }
+ }
+ def bsimp2(r: ARexp, v: Val): (ARexp, Val) = (r,v) match{
+ case (ASEQ(bs1, r1, r2), Sequ(v1, v2)) => (bsimp2(r1, v1), bsimp2(r2, v2)) match {
+ case ((AZERO, _), (_, _) )=> (AZERO, undefined)
+ case ((_, _), (AZERO, _)) => (AZERO, undefined)
+ case ((AONE(bs2), v1s) , (r2s, v2s)) => (fuse(bs1 ++ bs2, r2s), v2s )//v2 tells how to retrieve bits in r2s, which is enough as the bits of the first part of the sequence has already been integrated to the top level of the second regx.
+ case ((r1s, v1s), (r2s, v2s)) => (ASEQ(bs1, r1s, r2s), Sequ(v1s, v2s))
+ }
+ case (AALTS(bs1, rs), v) => {
+ val vlist = unify(rs, v)
+ vlist match {
+ case Position(i, v0) => {
+ val v_simp = bsimp2(rs(i), v0)._2
+ val rs_simp = rs.map(bsimp)
+ val flat_res = flats2( Nil, i, rs_simp, Position(i, v_simp) )
+ val dist_res = distinctBy2(flat_res._2, flat_res._1, erase)
+ val rs_new = dist_res._1
+ val v_new = deunify(rs_new.length, dist_res._2)
+ rs_new match {
+ case Nil => (AZERO, undefined)
+ case s :: Nil => (fuse(bs1, s), v_new)
+ case rs => (AALTS(bs1, rs), v_new)
+ }
+ }
+ case _ => throw new Exception("Funny vlist bsimp2")
+ }
+ }
+ //case ASTAR(bs, r) => ASTAR(bs, bsimp(r))
+ case (r, v) => (r, v)
+ }
+ /*def bsimp2(r: ARexp, v: Val): (ARexp, Val) = (r,v) match{
case (ASEQ(bs1, r1, r2), Sequ(v1, v2)) => (bsimp2(r1, v1), bsimp2(r2, v2)) match {
case ((AZERO, _), (_, _) )=> (AZERO, undefined)
case ((_, _), (AZERO, _)) => (AZERO, undefined)
@@ -794,7 +938,7 @@
}
//case ASTAR(bs, r) => ASTAR(bs, bsimp(r))
case (r, v) => (r, v)
- }
+ }*/
//the below are all residuals from the bsimp2 function
//val vs_for_coating = if(isend(vs._2, rs_simp, init_ind)||flat_res.length == 1) vs_kernel else Left(vs_kernel)
//val vf = coat(vs_for_coating, new_ind)
@@ -857,7 +1001,8 @@
//case ASTAR(bs, r) => ASTAR(bs, bsimp(r))
case r => r
}
-
+//nice website http://www.nhc.gov.cn/xcs/kpzs/202002/d228d85eaa19412eaaa4eee740f03101.shtml
+//orientalism
def simp_weakened(r: Rexp): Rexp = r match {
case SEQ(r1, r2) => (simp_weakened(r1), r2) match {
@@ -1219,6 +1364,7 @@
case class Right(v: Val) extends Val
case class Stars(vs: List[Val]) extends Val
case class Rec(x: String, v: Val) extends Val
+case class Position(i: Int, v: Val) extends Val
case object undefined extends Val
//case class Pos(i: Int, v: Val) extends Val
case object Prd extends Val