equal
deleted
inserted
replaced
1 // A version with simplification of derivatives; |
1 // A version with simplification of derivatives; |
2 // this keeps the regular expressions small, which |
2 // this keeps the regular expressions small, which |
3 // is good for run-time |
3 // is good for the run-time |
4 |
4 |
5 |
5 |
6 abstract class Rexp |
6 abstract class Rexp |
7 case object ZERO extends Rexp |
7 case object ZERO extends Rexp |
8 case object ONE extends Rexp |
8 case object ONE extends Rexp |
63 case c::s => ders(s, simp(der(c, r))) |
63 case c::s => ders(s, simp(der(c, r))) |
64 } |
64 } |
65 |
65 |
66 |
66 |
67 // the main matcher function |
67 // the main matcher function |
68 def matcher(r: Rexp, s: String) : Boolean = nullable(ders(s.toList, r)) |
68 def matcher(r: Rexp, s: String) : Boolean = |
|
69 nullable(ders(s.toList, r)) |
69 |
70 |
70 |
71 |
71 // one or zero |
72 // one or zero |
72 def OPT(r: Rexp) = ALT(r, ONE) |
73 def OPT(r: Rexp) = ALT(r, ONE) |
73 |
74 |