112 case ASEQ(_, r1, r2) => s"(${astring(r1)} ~ ${astring(r2)})" |
112 case ASEQ(_, r1, r2) => s"(${astring(r1)} ~ ${astring(r2)})" |
113 case ASTAR(_, r) => s"{${astring(r)}}*" |
113 case ASTAR(_, r) => s"{${astring(r)}}*" |
114 } |
114 } |
115 |
115 |
116 |
116 |
117 //-------------------------------------------------------------------------------------------------------- |
117 //-------------------------------------------------------------- |
118 // START OF NON-BITCODE PART |
118 // START OF NON-BITCODE PART |
119 // |
119 // |
120 |
120 |
121 // nullable function: tests whether the regular |
121 // nullable function: tests whether the regular |
122 // expression can recognise the empty string |
122 // expression can recognise the empty string |
262 } |
262 } |
263 } |
263 } |
264 |
264 |
265 def lexing_simp(r: Rexp, s: String) : Val = lex_simp(r, s.toList) |
265 def lexing_simp(r: Rexp, s: String) : Val = lex_simp(r, s.toList) |
266 |
266 |
267 println(lexing_simp(("a" | "ab") ~ ("b" | ""), "ab")) |
267 //println(lexing_simp(("a" | "ab") ~ ("b" | ""), "ab")) |
268 |
268 |
269 |
269 |
270 def tokenise_simp(r: Rexp, s: String) = env(lexing_simp(r, s)).map(esc2) |
270 def tokenise_simp(r: Rexp, s: String) = |
271 |
271 env(lexing_simp(r, s)).map(esc2) |
272 //-------------------------------------------------------------------------------------------------------- |
272 |
|
273 //-------------------------------------------------------------------- |
|
274 // Partial Derivatives |
|
275 |
|
276 |
|
277 def pder(c: Char, r: Rexp): Set[Rexp] = r match { |
|
278 case ZERO => Set() |
|
279 case ONE => Set() |
|
280 case PRED(f, _) => if (f(c)) Set(ONE) else Set() |
|
281 case ALTS(rs) => rs.toSet.flatMap(pder(c, _)) |
|
282 case SEQ(r1, r2) => |
|
283 (for (pr1 <- pder(c, r1)) yield SEQ(pr1, r2)) ++ |
|
284 (if (nullable(r1)) pder(c, r2) else Set()) |
|
285 case STAR(r1) => |
|
286 for (pr1 <- pder(c, r1)) yield SEQ(pr1, STAR(r1)) |
|
287 case RECD(_, r1) => pder(c, r1) |
|
288 } |
|
289 |
|
290 def pders(cs: List[Char], r: Rexp): Set[Rexp] = cs match { |
|
291 case Nil => Set(r) |
|
292 case c::cs => pder(c, r).flatMap(pders(cs, _)) |
|
293 } |
|
294 |
|
295 def pders_simp(cs: List[Char], r: Rexp): Set[Rexp] = cs match { |
|
296 case Nil => Set(r) |
|
297 case c::cs => pder(c, r).flatMap(pders_simp(cs, _)).map(simp(_)._1) |
|
298 } |
|
299 |
|
300 def psize(rs: Set[Rexp]) = |
|
301 rs.map(size).sum |
|
302 |
|
303 //-------------------------------------------------------------------- |
273 // BITCODED PART |
304 // BITCODED PART |
274 |
305 |
275 |
306 |
276 def fuse(bs: Bits, r: ARexp) : ARexp = r match { |
307 def fuse(bs: Bits, r: ARexp) : ARexp = r match { |
277 case AZERO => AZERO |
308 case AZERO => AZERO |
593 |
624 |
594 println("Original " + size(WHILE_REGS)) |
625 println("Original " + size(WHILE_REGS)) |
595 println("Size Bit " + asize(bders_simp((fib_prog * 1).toList, internalise(WHILE_REGS)))) |
626 println("Size Bit " + asize(bders_simp((fib_prog * 1).toList, internalise(WHILE_REGS)))) |
596 println("Size Bitf " + asize(bders_simp_full((fib_prog * 1).toList, internalise(WHILE_REGS)))) |
627 println("Size Bitf " + asize(bders_simp_full((fib_prog * 1).toList, internalise(WHILE_REGS)))) |
597 println("Size Old " + size(ders_simp((fib_prog * 1).toList, WHILE_REGS))) |
628 println("Size Old " + size(ders_simp((fib_prog * 1).toList, WHILE_REGS))) |
598 |
629 println("Size Pder " + psize(pders_simp((fib_prog * 1).toList, WHILE_REGS))) |
599 |
630 |
600 System.exit(0) |
631 System.exit(0) |
601 |
632 |
602 println("Internal sizes test OK or strange") |
633 println("Internal sizes test OK or strange") |
603 |
634 |