equal
deleted
inserted
replaced
46 |
46 |
47 |
47 |
48 // derivative of a regular expression w.r.t. a character |
48 // derivative of a regular expression w.r.t. a character |
49 def der (c: Char, r: Rexp) : Rexp = r match { |
49 def der (c: Char, r: Rexp) : Rexp = r match { |
50 case NULL => NULL |
50 case NULL => NULL |
51 case EMPTY => NULL |
51 case EMPTY => NULL case CHAR(d) => if (c == d) EMPTY else NULL |
52 case CHAR(d) => if (c == d) EMPTY else NULL |
|
53 case ALT(r1, r2) => ALT(der(c, r1), der(c, r2)) |
52 case ALT(r1, r2) => ALT(der(c, r1), der(c, r2)) |
54 case SEQ(r1, r2) => |
53 case SEQ(r1, r2) => |
55 if (nullable(r1)) ALT(SEQ(der(c, r1), r2), der(c, r2)) |
54 if (nullable(r1)) ALT(SEQ(der(c, r1), r2), der(c, r2)) |
56 else SEQ(der(c, r1), r2) |
55 else SEQ(der(c, r1), r2) |
57 case STAR(r) => SEQ(der(c, r), STAR(r)) |
56 case STAR(r) => SEQ(der(c, r), STAR(r)) |