48 case class Sequ(v1: Val, v2: Val) extends Val |
48 case class Sequ(v1: Val, v2: Val) extends Val |
49 case class Left(v: Val) extends Val |
49 case class Left(v: Val) extends Val |
50 case class Right(v: Val) extends Val |
50 case class Right(v: Val) extends Val |
51 case class Stars(vs: List[Val]) extends Val |
51 case class Stars(vs: List[Val]) extends Val |
52 case class Recd(x: String, v: Val) extends Val |
52 case class Recd(x: String, v: Val) extends Val |
|
53 |
|
54 abstract class BTree |
|
55 case object LZ extends BTree |
|
56 case class L(bs: Bits) extends BTree |
|
57 case class LALTS(bs: Bits, bts: List[BTree]) extends BTree |
|
58 case class LSEQ(bs: Bits, bt1: BTree, bt2: BTree) extends BTree |
|
59 case class LSTAR(bs: Bits, bt: BTree) extends BTree |
|
60 |
|
61 def ext(r: ARexp): BTree = r match { |
|
62 case AZERO => LZ |
|
63 case AONE(bs) => L(bs) |
|
64 case ACHAR(bs, _) => L(bs) |
|
65 case AALTS(bs, rs) => LALTS(bs, rs.map(ext)) |
|
66 case ASEQ(bs, r1, r2) => LSEQ(bs, ext(r1), ext(r2)) |
|
67 case ASTAR(bs, r) => LSTAR(bs, ext(r)) |
|
68 } |
|
69 |
|
70 // annotated regular expressions |
|
71 abstract class BRexp |
|
72 case object BZERO extends BRexp |
|
73 case object BONE extends BRexp |
|
74 case class BCHAR(c: Char) extends BRexp |
|
75 case class BALTS(rs: List[BRexp]) extends BRexp |
|
76 case class BSEQ(r1: BRexp, r2: BRexp) extends BRexp |
|
77 case class BSTAR(r: BRexp) extends BRexp |
|
78 |
|
79 def ex(r: ARexp): BRexp = r match { |
|
80 case AZERO => BZERO |
|
81 case AONE(_) => BONE |
|
82 case ACHAR(_, c) => BCHAR(c) |
|
83 case AALTS(_, rs) => BALTS(rs.map(ex)) |
|
84 case ASEQ(_, r1, r2) => BSEQ(ex(r1), ex(r2)) |
|
85 case ASTAR(_, r) => BSTAR(ex(r)) |
|
86 } |
|
87 |
53 |
88 |
54 // some convenience for typing in regular expressions |
89 // some convenience for typing in regular expressions |
55 def charlist2rexp(s: List[Char]): Rexp = s match { |
90 def charlist2rexp(s: List[Char]): Rexp = s match { |
56 case Nil => ONE |
91 case Nil => ONE |
57 case c::Nil => CHAR(c) |
92 case c::Nil => CHAR(c) |