equal
deleted
inserted
replaced
5 case class CHAR(c: Char) extends Rexp |
5 case class CHAR(c: Char) extends Rexp |
6 case class ALT(r1: Rexp, r2: Rexp) extends Rexp |
6 case class ALT(r1: Rexp, r2: Rexp) extends Rexp |
7 case class SEQ(r1: Rexp, r2: Rexp) extends Rexp |
7 case class SEQ(r1: Rexp, r2: Rexp) extends Rexp |
8 case class STAR(r: Rexp) extends Rexp |
8 case class STAR(r: Rexp) extends Rexp |
9 case class NTIMES(r: Rexp, n: Int) extends Rexp |
9 case class NTIMES(r: Rexp, n: Int) extends Rexp |
|
10 |
10 |
11 |
11 // nullable function: tests whether the regular |
12 // nullable function: tests whether the regular |
12 // expression can recognise the empty string |
13 // expression can recognise the empty string |
13 def nullable (r: Rexp) : Boolean = r match { |
14 def nullable (r: Rexp) : Boolean = r match { |
14 case ZERO => false |
15 case ZERO => false |
45 case (_, ZERO) => ZERO |
46 case (_, ZERO) => ZERO |
46 case (ONE, r2s) => r2s |
47 case (ONE, r2s) => r2s |
47 case (r1s, ONE) => r1s |
48 case (r1s, ONE) => r1s |
48 case (r1s, r2s) => SEQ(r1s, r2s) |
49 case (r1s, r2s) => SEQ(r1s, r2s) |
49 } |
50 } |
50 case NTIMES(r1, n) => NTIMES(simp(r1), n) |
|
51 case r => r |
51 case r => r |
52 } |
52 } |
53 |
53 |
54 |
54 |
55 // derivative w.r.t. a string (iterates der) |
55 // derivative w.r.t. a string (iterates der) |