progs/matcher/re1.sc
changeset 826 b0352633bf48
parent 825 dca072e2bb7d
child 871 94b84d880c2b
equal deleted inserted replaced
825:dca072e2bb7d 826:b0352633bf48
     5 //   amm re1.sc testX
     5 //   amm re1.sc testX
     6 //
     6 //
     7 // or 
     7 // or 
     8 //
     8 //
     9 //   amm re1.sc all
     9 //   amm re1.sc all
       
    10 //
       
    11 
    10  
    12  
    11 // regular expressions
    13 // regular expressions
    12 abstract class Rexp
    14 abstract class Rexp
    13 case object ZERO extends Rexp                    // matches nothing
    15 case object ZERO extends Rexp                    // matches nothing
    14 case object ONE extends Rexp                     // matches an empty string
    16 case object ONE extends Rexp                     // matches an empty string
    94   (end - start) / (i * 1.0e9)
    96   (end - start) / (i * 1.0e9)
    95 }
    97 }
    96 
    98 
    97 
    99 
    98 // test: (a?{n}) (a{n})
   100 // test: (a?{n}) (a{n})
    99 @doc("Test (a?{n}) (a{n})")
   101 @arg(doc = "Test (a?{n}) (a{n})")
   100 @main
   102 @main
   101 def test1() = {
   103 def test1() = {
   102   println("Test (a?{n}) (a{n})")
   104   println("Test (a?{n}) (a{n})")
   103 
   105 
   104   for (i <- 0 to 20 by 2) {
   106   for (i <- 0 to 20 by 2) {
   105     println(f"$i: ${time_needed(2, matcher(EVIL1(i), "a" * i))}%.5f")
   107     println(f"$i: ${time_needed(2, matcher(EVIL1(i), "a" * i))}%.5f")
   106   }
   108   }
   107 }
   109 }
   108 
   110 
   109 // test: (a*)* b
   111 // test: (a*)* b
   110 @doc("Test (a*)* b")
   112 @arg(doc = "Test (a*)* b")
   111 @main
   113 @main
   112 def test2() = {
   114 def test2() = {
   113   println("Test (a*)* b")
   115   println("Test (a*)* b")
   114 
   116 
   115   for (i <- 0 to 20 by 2) {
   117   for (i <- 0 to 20 by 2) {
   156 size(ders("abababababab".toList, BIG))  // 536
   158 size(ders("abababababab".toList, BIG))  // 536
   157 
   159 
   158 
   160 
   159 size(ders(("ab" * 200).toList, BIG))    // 366808
   161 size(ders(("ab" * 200).toList, BIG))    // 366808
   160 
   162 
   161 @doc("Test (a + b)* o (a o b) o (a + b)*")
   163 @arg(doc = "Test (a + b)* o (a o b) o (a + b)*")
   162 @main
   164 @main
   163 def test3() = {
   165 def test3() = {
   164   println("Test (a + b)* o (a o b) o (a + b)*")
   166   println("Test (a + b)* o (a o b) o (a + b)*")
   165 
   167 
   166   for (i <- 0 to 200 by 10) {
   168   for (i <- 0 to 200 by 10) {
   169 }
   171 }
   170 
   172 
   171 
   173 
   172 
   174 
   173 
   175 
   174 @doc("All tests.")
   176 @arg(doc = "All tests.")
   175 @main
   177 @main
   176 def all() = { test1(); test2() ; test3() } 
   178 def all() = { test1(); test2() ; test3() } 
       
   179 
       
   180 
       
   181 
       
   182 // runs with amm2 and amm3