110 println(i + " " + "%.5f".format(time_needed(2, matcher(EVIL2, "a" * i)))) |
110 println(i + " " + "%.5f".format(time_needed(2, matcher(EVIL2, "a" * i)))) |
111 } |
111 } |
112 |
112 |
113 |
113 |
114 |
114 |
|
115 // size of a regular expressions - for testing purposes |
|
116 def size(r: Rexp) : Int = r match { |
|
117 case ZERO => 1 |
|
118 case ONE => 1 |
|
119 case CHAR(_) => 1 |
|
120 case ALT(r1, r2) => 1 + size(r1) + size(r2) |
|
121 case SEQ(r1, r2) => 1 + size(r1) + size(r2) |
|
122 case STAR(r) => 1 + size(r) |
|
123 case NTIMES(r, _) => 1 + size(r) |
|
124 } |
|
125 |
|
126 |
|
127 // string of a regular expressions - for testing purposes |
|
128 def string(r: Rexp) : String = r match { |
|
129 case ZERO => "0" |
|
130 case ONE => "1" |
|
131 case CHAR(c) => c.toString |
|
132 case ALT(r1, r2) => s"(${string(r1)} + ${string(r2)})" |
|
133 case SEQ(CHAR(c), CHAR(d)) => s"${c}${d}" |
|
134 case SEQ(r1, r2) => s"(${string(r1)} ~ ${string(r2)})" |
|
135 case STAR(r) => s"(${string(r)})*" |
|
136 case NTIMES(r, n) => s"(${string(r)}){${n}}" |
|
137 } |
|
138 |
|
139 |
|
140 // test: ("a" | "aa")* |
|
141 val EVIL3 = STAR(ALT(CHAR('a'), SEQ(CHAR('a'), CHAR('a')))) |
|
142 |
|
143 //test: ("" | "a" | "aa")* |
|
144 val EVIL3 = STAR(ALT(ONE, ALT(CHAR('a'), SEQ(CHAR('a'), CHAR('a'))))) |
|
145 |
|
146 val t1 = ders2("a".toList, EVIL3) |
|
147 val t1s = simp(t1) |
|
148 val t2 = ders2("aa".toList, t1s) |
|
149 val t2s = simp(t2) |
|
150 val t3 = ders2("aaa".toList, t2s) |
|
151 val t3s = simp(t3) |
|
152 val t4 = ders2("aaaa".toList, t3s) |
|
153 val t4s = simp(t4) |
|
154 println(string(t1) + " " + size(t1)) |
|
155 println("s " + string(t1s) + " " + size(t1s)) |
|
156 println(string(t2) + " " + size(t2)) |
|
157 println("s " + string(t2s) + " " + size(t2s)) |
|
158 println(string(t3) + " " + size(t3)) |
|
159 println("s " + string(t3s) + " " + size(t3s)) |
|
160 println(string(t4) + " " + size(t4)) |
|
161 println("s " + string(t4s) + " " + size(t4s)) |