171 } |
171 } |
172 |
172 |
173 // some examples for Thompson's |
173 // some examples for Thompson's |
174 val A = thompson(CHAR('a')) |
174 val A = thompson(CHAR('a')) |
175 |
175 |
176 println(A.accepts("a")) |
176 println(A.accepts("a")) // true |
177 println(A.accepts("c")) |
177 println(A.accepts("c")) // false |
178 println(A.accepts("aa")) |
178 println(A.accepts("aa")) // false |
179 |
179 |
180 val B = thompson(ALT("ab","ac")) |
180 val B = thompson(ALT("ab","ac")) |
181 |
181 |
182 println(B.accepts("ab")) |
182 println(B.accepts("ab")) // true |
183 println(B.accepts("ac")) |
183 println(B.accepts("ac")) // true |
184 println(B.accepts("bb")) |
184 println(B.accepts("bb")) // false |
185 println(B.accepts("aa")) |
185 println(B.accepts("aa")) // false |
186 |
186 |
187 val C = thompson(STAR("ab")) |
187 val C = thompson(STAR("ab")) |
188 |
188 |
189 println(C.accepts("")) |
189 println(C.accepts("")) // true |
190 println(C.accepts("a")) |
190 println(C.accepts("a")) // false |
191 println(C.accepts("ababab")) |
191 println(C.accepts("ababab")) // true |
192 println(C.accepts("ab")) |
192 println(C.accepts("ab")) // true |
193 println(C.accepts("ac")) |
193 println(C.accepts("ac")) // false |
194 println(C.accepts("bb")) |
194 println(C.accepts("bb")) // false |
195 println(C.accepts("aa")) |
195 println(C.accepts("aa")) // false |
196 |
196 |
197 // regular expression matcher using Thompson's |
197 // regular expression matcher using Thompson's |
198 def matcher(r: Rexp, s: String) : Boolean = thompson(r).accepts(s) |
198 def matcher(r: Rexp, s: String) : Boolean = thompson(r).accepts(s) |
199 |
199 |
200 |
200 |