--- a/lex_blex_Frankensteined.scala Sat Mar 23 11:53:09 2019 +0000
+++ b/lex_blex_Frankensteined.scala Wed Apr 10 16:34:34 2019 +0100
@@ -92,7 +92,7 @@
def decode_aux(r: Rexp, bs: Bits) : (Val, Bits) = (r, bs) match {
case (ONE, bs) => (Empty, bs)
case (CHAR(f), C(c)::bs) => (Chr(c), bs)
- case (ALTS(r::Nil), bs) => decode_aux(r, bs)//this case seems tailor made for those who want to simplify the regex before der or simp
+ //case (ALTS(r::Nil), bs) => decode_aux(r, bs)//this case seems only used when we simp a regex before derivatives and it contains things like alt("a")
case (ALTS(rs), bs) => bs match {
case Z::bs1 => {
val (v, bs2) = decode_aux(rs.head, bs1)
@@ -126,7 +126,25 @@
case _ => throw new Exception("Not decodable")
}
+ def code(v: Val): Bits = v match {
+ case Empty => Nil
+ case Left(v) => Z :: code(v)
+ case Right(v) => S :: code(v)
+ case Sequ(v1, v2) => code(v1) ::: code(v2)
+ case Stars(Nil) => Z::Nil
+ case Stars(v::vs) => S::code(v) ::: code(Stars(vs))
+ }
+
+ def retrieve(r: ARexp, v: Val): Bits = (r,v) match {
+ case (AONE(bs), Empty) => bs
+ case (ACHAR(bs, c), Chr(d)) => bs
+ case (AALTS(bs, as), Left(v)) => bs ++ retrieve(as.head,v)
+ case (AALTS(bs, as), Right(v)) => bs ++ retrieve(AALTS(Nil,as.tail),v)
+ case (ASEQ(bs, a1, a2), Sequ(v1, v2)) => bs ++ retrieve(a1, v1) ++ retrieve(a2, v2)
+ case (ASTAR(bs, a), Stars(Nil)) => bs ++ List(Z)
+ case (ASTAR(bs, a), Stars(v::vs)) => bs ++ List(S) ++ retrieve(a, v) ++ retrieve(ASTAR(Nil, a), Stars(vs))
+ }
//erase function: extracts the regx from Aregex
def erase(r:ARexp): Rexp = r match{
case AZERO => ZERO
@@ -397,8 +415,8 @@
case ASEQ(bs1, r1, r2) => (super_bsimp(r1), super_bsimp(r2)) match {
case (AZERO, _) => AZERO
case (_, AZERO) => AZERO
- case (AONE(bs2), r2s) => fuse(bs1 ++ bs2, r2s)
- case (AALTS(bs2, rs), r2) => AALTS(bs1 ++ bs2, rs.map(r => r match {case AONE(bs3) => fuse(bs3, r2) case r => ASEQ(Nil, r, r2)}) )
+ case (AONE(bs2), r2s) => fuse(bs1 ++ bs2, r2s)//万一是(r1, alts(rs))这种形式呢
+ case (AALTS(bs2, rs), r2) => AALTS(bs1 ++ bs2, rs.map(r => r match {case AONE(bs3) => fuse(bs3, r2) case r => ASEQ(Nil, r, r2)} ) )
case (r1s, r2s) => ASEQ(bs1, r1s, r2s)
}
case AALTS(bs1, rs) => {