author | Christian Urban <urbanc@in.tum.de> |
Wed, 10 Oct 2012 00:55:37 +0100 | |
changeset 24 | 275af0faf90c |
parent 7 | 73cf4406b773 |
child 66 | 9215b9fb8852 |
permissions | -rw-r--r-- |
7 | 1 |
def matches(r: Rexp, s: String) : Boolean = |
2 |
nullable(derivs(r, s.toList)) |
|
3 |
||
4 |
||
5 |
/* Examples */ |
|
6 |
||
7 |
println(matches(SEQ(SEQ(CHAR('c'), CHAR('a')), CHAR('b')),"cab")) |
|
8 |
println(matches(STAR(CHAR('a')),"aaa")) |
|
9 |
||
10 |
/* Convenience using implicits */ |
|
11 |
implicit def string2rexp(s : String) : Rexp = { |
|
12 |
s.foldRight (EMPTY: Rexp) ( (c, r) => SEQ(CHAR(c), r) ) |
|
13 |
} |
|
14 |
||
15 |
println(matches("cab" ,"cab")) |
|
16 |
println(matches(STAR("a"),"aaa")) |
|
17 |
println(matches(STAR("a"),"aaab")) |