progs/app51.scala
changeset 261 24531cfaa36a
parent 93 4794759139ea
child 399 5c1fbb39c93e
--- a/progs/app51.scala	Sat Sep 27 00:37:02 2014 +0100
+++ b/progs/app51.scala	Sun Sep 28 18:07:58 2014 +0100
@@ -1,8 +1,8 @@
-abstract class Rexp
+def OPT(r: Rexp) = ALT(r, EMPTY)
 
-case object NULL extends Rexp
-case object EMPTY extends Rexp
-case class CHAR(c: Char) extends Rexp
-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
+def NTIMES(r: Rexp, n: Int) : Rexp = n match {
+  case 0 => EMPTY
+  case 1 => r
+  case n => SEQ(r, NTIMES(r, n - 1))
+}
+