lex_blex_Frankensteined.scala
changeset 12 768b833d6230
parent 11 9c1ca6d6e190
child 14 610f14009c0b
--- a/lex_blex_Frankensteined.scala	Wed Apr 10 16:34:34 2019 +0100
+++ b/lex_blex_Frankensteined.scala	Wed Apr 10 17:06:24 2019 +0100
@@ -7,7 +7,7 @@
 abstract class Bit
 case object Z extends Bit
 case object S extends Bit
-case class C(c: Char) extends Bit
+//case class C(c: Char) extends Bit
 
 
 abstract class Rexp 
@@ -91,8 +91,8 @@
 
   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 only used when we simp a regex before derivatives and it contains things like alt("a")
+    case (CHAR(f), bs) => (Chr(f), bs)
+    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)
@@ -128,6 +128,7 @@
 
   def code(v: Val): Bits = v match {
     case Empty => Nil
+    case Chr(a) => Nil
     case Left(v) => Z :: code(v)
     case Right(v) => S :: code(v)
     case Sequ(v1, v2) => code(v1) ::: code(v2)
@@ -141,6 +142,7 @@
     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 (AALTS(bs, a::Nil), v) => bs ++ retrieve(a, 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))
@@ -355,7 +357,7 @@
   def bder(c: Char, r: ARexp) : ARexp = r match {
     case AZERO => AZERO
     case AONE(_) => AZERO
-    case ACHAR(bs, f) => if (c == f) AONE(bs:::List(C(c))) else AZERO
+    case ACHAR(bs, f) => if (c == f) AONE(bs) else AZERO
     case AALTS(bs, rs) => AALTS(bs, rs.map(bder(c, _)))
     case ASEQ(bs, r1, r2) => 
       if (bnullable(r1)) AALT(bs, ASEQ(Nil, bder(c, r1), r2), fuse(mkepsBC(r1), bder(c, r2)))