--- a/progs/app05.scala Mon Oct 17 13:18:34 2016 +0100
+++ b/progs/app05.scala Tue Oct 18 10:43:26 2016 +0100
@@ -3,8 +3,8 @@
val (r1s, f1s) = simp(r1)
val (r2s, f2s) = simp(r2)
(r1s, r2s) match {
- case (NULL, _) => (r2s, F_RIGHT(f2s))
- case (_, NULL) => (r1s, F_LEFT(f1s))
+ case (ZERO, _) => (r2s, F_RIGHT(f2s))
+ case (_, ZERO) => (r1s, F_LEFT(f1s))
case _ =>
if (r1s == r2s) (r1s, F_LEFT(f1s))
else (ALT (r1s, r2s), F_ALT(f1s, f2s))
--- a/progs/app06.scala Mon Oct 17 13:18:34 2016 +0100
+++ b/progs/app06.scala Tue Oct 18 10:43:26 2016 +0100
@@ -3,10 +3,10 @@
val (r1s, f1s) = simp(r1)
val (r2s, f2s) = simp(r2)
(r1s, r2s) match {
- case (NULL, _) => (NULL, F_ERROR)
- case (_, NULL) => (NULL, F_ERROR)
- case (EMPTY, _) => (r2s, F_SEQ_Void1(f1s, f2s))
- case (_, EMPTY) => (r1s, F_SEQ_Void2(f1s, f2s))
+ case (ZERO, _) => (ZERO, F_ERROR)
+ case (_, ZERO) => (ZERO, F_ERROR)
+ case (ONE, _) => (r2s, F_SEQ_Void1(f1s, f2s))
+ case (_, ONE) => (r1s, F_SEQ_Void2(f1s, f2s))
case _ => (SEQ(r1s,r2s), F_SEQ(f1s, f2s))
}
}
--- a/progs/re1.scala Mon Oct 17 13:18:34 2016 +0100
+++ b/progs/re1.scala Tue Oct 18 10:43:26 2016 +0100
@@ -5,6 +5,12 @@
case class ALT(r1: Rexp, r2: Rexp) extends Rexp
case class SEQ(r1: Rexp, r2: Rexp) extends Rexp
case class STAR(r: Rexp) extends Rexp
+case class RANGE(cs: List[Char]) extends Rexp
+case class PLUS(r: Rexp) extends Rexp
+case class OPT(r: Rexp) extends Rexp
+case class NTIMES(r: Rexp, n : Int) extends Rexp
+case class NMTIMES(r: Rexp, n : Int, m : Int) extends Rexp
+
// nullable function: tests whether the regular
// expression can recognise the empty string
@@ -15,6 +21,7 @@
case ALT(r1, r2) => nullable(r1) || nullable(r2)
case SEQ(r1, r2) => nullable(r1) && nullable(r2)
case STAR(_) => true
+
}
// derivative of a regular expression w.r.t. a character
--- a/progs/re2.scala Mon Oct 17 13:18:34 2016 +0100
+++ b/progs/re2.scala Tue Oct 18 10:43:26 2016 +0100
@@ -29,7 +29,7 @@
else SEQ(der(c, r1), r2)
case STAR(r1) => SEQ(der(c, r1), STAR(r1))
case NTIMES(r1, i) =>
- if (i == 0) ZERO else SEQ(der(c, r1), NTIMES(r1, i - 1))
+ if (i == 0) ZERO else der(c, SEQ(r1, NTIMES(r1, i - 1)))
}
def ders (s: List[Char], r: Rexp) : Rexp = s match {
--- a/progs/re3.scala Mon Oct 17 13:18:34 2016 +0100
+++ b/progs/re3.scala Tue Oct 18 10:43:26 2016 +0100
@@ -31,7 +31,7 @@
else SEQ(der(c, r1), r2)
case STAR(r1) => SEQ(der(c, r1), STAR(r1))
case NTIMES(r, i) =>
- if (i == 0) ZERO else SEQ(der(c, r), NTIMES(r, i - 1))
+ if (i == 0) ZERO else der(c, SEQ(r, NTIMES(r, i - 1)))
}
def simp(r: Rexp) : Rexp = r match {
Binary file slides/slides03.pdf has changed
Binary file slides/slides04.pdf has changed
Binary file slides/slides05.pdf has changed