progs/scala/re-annotated.sc
changeset 361 8bb064045b4e
parent 360 e752d84225ec
--- a/progs/scala/re-annotated.sc	Mon Feb 22 03:22:26 2021 +0000
+++ b/progs/scala/re-annotated.sc	Thu Feb 25 22:46:58 2021 +0000
@@ -50,6 +50,41 @@
 case class Right(v: Val) extends Val
 case class Stars(vs: List[Val]) extends Val
 case class Recd(x: String, v: Val) extends Val
+
+abstract class BTree
+case object LZ extends BTree
+case class L(bs: Bits) extends BTree
+case class LALTS(bs: Bits, bts: List[BTree]) extends BTree 
+case class LSEQ(bs: Bits, bt1: BTree, bt2: BTree) extends BTree 
+case class LSTAR(bs: Bits, bt: BTree) extends BTree
+
+def ext(r: ARexp): BTree = r match {
+  case AZERO => LZ
+  case AONE(bs) => L(bs)
+  case ACHAR(bs, _) => L(bs)
+  case AALTS(bs, rs) => LALTS(bs, rs.map(ext))
+  case ASEQ(bs, r1, r2) => LSEQ(bs, ext(r1), ext(r2))
+  case ASTAR(bs, r) => LSTAR(bs, ext(r))
+}
+
+// annotated regular expressions
+abstract class BRexp 
+case object BZERO extends BRexp
+case object BONE extends BRexp
+case class BCHAR(c: Char) extends BRexp
+case class BALTS(rs: List[BRexp]) extends BRexp 
+case class BSEQ(r1: BRexp, r2: BRexp) extends BRexp 
+case class BSTAR(r: BRexp) extends BRexp 
+
+def ex(r: ARexp): BRexp = r match {
+  case AZERO => BZERO
+  case AONE(_) => BONE
+  case ACHAR(_, c) => BCHAR(c)
+  case AALTS(_, rs) => BALTS(rs.map(ex))
+  case ASEQ(_, r1, r2) => BSEQ(ex(r1), ex(r2))
+  case ASTAR(_, r) => BSTAR(ex(r))
+}
+
    
 // some convenience for typing in regular expressions
 def charlist2rexp(s: List[Char]): Rexp = s match {
@@ -234,7 +269,6 @@
 
 // example by Tudor
 //val reg = (STAR("a") ~ ("b" | "c")).%
-
 //println(blexing(reg, "aab"))