442 } |
442 } |
443 //case ASTAR(bs1, r1) => ASTAR(bs1, bsimp(r1)) |
443 //case ASTAR(bs1, r1) => ASTAR(bs1, bsimp(r1)) |
444 case r => r |
444 case r => r |
445 } |
445 } |
446 |
446 |
447 |
|
448 |
|
449 |
|
450 def bders_simp (s: List[Char], r: ARexp) : ARexp = s match { |
447 def bders_simp (s: List[Char], r: ARexp) : ARexp = s match { |
451 case Nil => r |
448 case Nil => r |
452 case c::s => bders_simp(s, bsimp(bder(c, r))) |
449 case c::s => bders_simp(s, bsimp(bder(c, r))) |
453 } |
450 } |
454 |
451 |
461 |
458 |
462 def blexing_simp(r: Rexp, s: String) : Val = |
459 def blexing_simp(r: Rexp, s: String) : Val = |
463 decode(r, blex_simp(internalise(r), s.toList)) |
460 decode(r, blex_simp(internalise(r), s.toList)) |
464 |
461 |
465 |
462 |
466 def btokenise_simp(r: Rexp, s: String) = env(blexing_simp(r, s)).map(esc2) |
463 def btokenise_simp(r: Rexp, s: String) = |
|
464 env(blexing_simp(r, s)).map(esc2) |
467 |
465 |
468 |
466 |
469 |
467 |
470 // INCLUDING SIMPLIFICATION UNDER STARS |
468 // INCLUDING SIMPLIFICATION UNDER STARS |
471 |
469 |
500 def blexing_simp_full(r: Rexp, s: String) : Val = |
498 def blexing_simp_full(r: Rexp, s: String) : Val = |
501 decode(r, blex_simp_full(internalise(r), s.toList)) |
499 decode(r, blex_simp_full(internalise(r), s.toList)) |
502 |
500 |
503 |
501 |
504 def btokenise_simp_full(r: Rexp, s: String) = env(blexing_simp_full(r, s)).map(esc2) |
502 def btokenise_simp_full(r: Rexp, s: String) = env(blexing_simp_full(r, s)).map(esc2) |
|
503 |
|
504 // bders2 for strings in the ALTS case |
|
505 |
|
506 def bders2_simp(s: List[Char], a: ARexp) : ARexp = { |
|
507 //println(s"s = ${s.length} a = ${asize(a)}") |
|
508 //Console.readLine |
|
509 (s, a) match { |
|
510 case (Nil, r) => r |
|
511 case (s, AZERO) => AZERO |
|
512 case (s, AONE(_)) => AZERO |
|
513 case (s, APRED(bs, f, _)) => |
|
514 if (f(s.head) && s.tail == Nil) AONE(bs:::List(C(s.head))) else AZERO |
|
515 case (s, AALTS(bs, rs)) => bsimp(AALTS(bs, rs.map(bders2_simp(s, _)))) |
|
516 case (c::s, r) => bders2_simp(s, bsimp(bder(c, r))) |
|
517 }} |
|
518 |
|
519 |
|
520 |
|
521 def blexing2_simp(r: Rexp, s: String) : Val = { |
|
522 val bder = bders2_simp(s.toList, internalise(r)) |
|
523 if (bnullable(bder)) decode(r, bmkeps(bder)) else |
|
524 throw new Exception("Not matched") |
|
525 |
|
526 } |
|
527 |
|
528 def btokenise2_simp(r: Rexp, s: String) = |
|
529 env(blexing2_simp(r, s)).map(esc2) |
505 |
530 |
506 |
531 |
507 |
532 |
508 // Testing |
533 // Testing |
509 //============ |
534 //============ |
592 println(astring(bders_simp("aaaaaaaaaaaa".toList, internalise(re1)))) |
617 println(astring(bders_simp("aaaaaaaaaaaa".toList, internalise(re1)))) |
593 println(astring(bders_simp("aaaaaaaaaaaaaaaaaaaaaaaaa".toList, internalise(re1)))) |
618 println(astring(bders_simp("aaaaaaaaaaaaaaaaaaaaaaaaa".toList, internalise(re1)))) |
594 println(astring(bders_simp("aaaaaabaaaabbbbbaaaaaaaaaaaaaaa".toList, internalise(re1)))) |
619 println(astring(bders_simp("aaaaaabaaaabbbbbaaaaaaaaaaaaaaa".toList, internalise(re1)))) |
595 |
620 |
596 |
621 |
597 |
622 for (i <- 0 to 100 by 5) { |
598 |
623 //print("Old: " + time(tokenise_simp(re1, "a" * i))) |
|
624 print(" Bit: " + time(btokenise_simp(re1, "a" * i))) |
|
625 print(" Bit full simp: " + time(btokenise_simp_full(re1, "a" * i))) |
|
626 println(" Bit2: " + time(btokenise2_simp(re1, "a" * i))) |
|
627 } |
|
628 |
|
629 Console.readLine |
599 |
630 |
600 |
631 |
601 // Bigger Tests |
632 // Bigger Tests |
602 //============== |
633 //============== |
603 |
634 |
|
635 |
|
636 println("Big tests") |
604 |
637 |
605 val fib_prog = """ |
638 val fib_prog = """ |
606 write "Fib"; |
639 write "Fib"; |
607 read n; |
640 read n; |
608 minus1 := 0; |
641 minus1 := 0; |
625 |
658 |
626 for (i <- 1 to 20) { |
659 for (i <- 1 to 20) { |
627 print("Old: " + time(tokenise_simp(WHILE_REGS, fib_prog * i))) |
660 print("Old: " + time(tokenise_simp(WHILE_REGS, fib_prog * i))) |
628 print(" Bit: " + time(btokenise_simp(WHILE_REGS, fib_prog * i))) |
661 print(" Bit: " + time(btokenise_simp(WHILE_REGS, fib_prog * i))) |
629 println(" Bit full simp: " + time(btokenise_simp_full(WHILE_REGS, fib_prog * i))) |
662 println(" Bit full simp: " + time(btokenise_simp_full(WHILE_REGS, fib_prog * i))) |
|
663 //println(" Bit2: " + time(btokenise2_simp(WHILE_REGS, fib_prog * i))) |
630 } |
664 } |
631 |
665 |
632 |
666 |
633 println("Original " + size(WHILE_REGS)) |
667 println("Original " + size(WHILE_REGS)) |
634 println("Size Bit " + asize(bders_simp((fib_prog * 1).toList, internalise(WHILE_REGS)))) |
668 println("Size Bit " + asize(bders_simp((fib_prog * 1).toList, internalise(WHILE_REGS)))) |
635 println("Size Bitf " + asize(bders_simp_full((fib_prog * 1).toList, internalise(WHILE_REGS)))) |
669 println("Size Bitf " + asize(bders_simp_full((fib_prog * 1).toList, internalise(WHILE_REGS)))) |
|
670 println("Size Bit2 " + asize(bders2_simp((fib_prog * 1).toList, internalise(WHILE_REGS)))) |
636 println("Size Old " + size(ders_simp((fib_prog * 1).toList, WHILE_REGS))) |
671 println("Size Old " + size(ders_simp((fib_prog * 1).toList, WHILE_REGS))) |
637 println("Size Pder " + psize(pders_simp((fib_prog * 1).toList, WHILE_REGS))) |
672 println("Size Pder " + psize(pders_simp((fib_prog * 1).toList, WHILE_REGS))) |
638 |
673 |
639 System.exit(0) |
674 System.exit(0) |
640 |
675 |