progs/matcher/re4.sc
changeset 826 b0352633bf48
parent 742 b5b5583a3a08
child 871 94b84d880c2b
equal deleted inserted replaced
825:dca072e2bb7d 826:b0352633bf48
     1 // (ASIDE!) A version which attempts to move whole strings, 
     1 // (ASIDE!) A version which attempts to move entire strings, 
     2 // not just characters, under derivatives whenever possible
     2 // not just characters, under derivatives whenever possible
     3 //    
     3 //    
     4 // call the test cases with X = {1,2}
     4 // call the test cases with X = {1,2}
     5 //
     5 //
     6 //   amm re4.sc testX
     6 //   amm re4.sc testX
   104   val end = System.nanoTime()
   104   val end = System.nanoTime()
   105   (end - start) / (i * 1.0e9)
   105   (end - start) / (i * 1.0e9)
   106 }
   106 }
   107 
   107 
   108 
   108 
   109 // test: (a?{n}) (a{n})
   109 @arg(doc = "Test (a?{n}) (a{n})")
   110 @doc("Test (a?{n}) (a{n})")
       
   111 @main
   110 @main
   112 def test1() = {
   111 def test1() = {
   113   for (i <- 0 to 11000 by 1000) {
   112   for (i <- 0 to 11000 by 1000) {
   114     println(f"$i: ${time_needed(2, matcher(EVIL1(i), "a" * i))}%.5f")
   113     println(f"$i: ${time_needed(2, matcher(EVIL1(i), "a" * i))}%.5f")
   115   }
   114   }
   116 }
   115 }
   117 
   116 
   118 // test: (a*)* b
   117 @arg(doc = "Test (a*)* b")
   119 @doc("Test (a*)* b")
       
   120 @main
   118 @main
   121 def test2() = {
   119 def test2() = {
   122   for (i <- 0 to 7000000 by 500000) {
   120   for (i <- 0 to 7000000 by 500000) {
   123     println(f"$i: ${time_needed(2, matcher(EVIL2, "a" * i))}%.5f")
   121     println(f"$i: ${time_needed(2, matcher(EVIL2, "a" * i))}%.5f")
   124   }
   122   }
   125 } 
   123 } 
   126 
   124 
   127 @doc("All tests.")
   125 @arg(doc = "All tests.")
   128 @main
   126 @main
   129 def all() = { test1(); test2() } 
   127 def all() = { test1(); test2() } 
   130 
   128 
   131 
   129 
   132 
   130 
   161 val EVIL3 = STAR(ALT(CHAR('a'), SEQ(CHAR('a'), CHAR('a'))))
   159 val EVIL3 = STAR(ALT(CHAR('a'), SEQ(CHAR('a'), CHAR('a'))))
   162 
   160 
   163 // test: ("" | "a" | "aa")*
   161 // test: ("" | "a" | "aa")*
   164 val EVIL4 = STAR(ALT(ONE, ALT(CHAR('a'), SEQ(CHAR('a'), CHAR('a')))))
   162 val EVIL4 = STAR(ALT(ONE, ALT(CHAR('a'), SEQ(CHAR('a'), CHAR('a')))))
   165 
   163 
       
   164 
       
   165 
       
   166 
       
   167 // runs with amm2 and amm3