equal
deleted
inserted
replaced
|
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")) |