progs/re1.scala
changeset 471 9476086849ad
parent 469 1f4e81950ab4
child 477 b78664a24f5d
--- a/progs/re1.scala	Mon Nov 14 15:50:42 2016 +0000
+++ b/progs/re1.scala	Sat Jan 07 14:52:26 2017 +0000
@@ -1,13 +1,13 @@
 
 abstract class Rexp
-case object ZERO extends Rexp
-case object ONE 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 
+case object ZERO extends Rexp                    // matches nothing
+case object ONE extends Rexp                     // matches the empty string
+case class CHAR(c: Char) extends Rexp            // matches a character c
+case class ALT(r1: Rexp, r2: Rexp) extends Rexp  // alternative
+case class SEQ(r1: Rexp, r2: Rexp) extends Rexp  // sequence
+case class STAR(r: Rexp) extends Rexp            // star
 
-// nullable function: tests whether the regular 
+// nullable function: tests whether a regular 
 // expression can recognise the empty string
 def nullable (r: Rexp) : Boolean = r match {
   case ZERO => false
@@ -46,10 +46,10 @@
 der('b', r)
 der('c', r)
 
-//optional: one or zero times
+//optional (one or zero times)
 def OPT(r: Rexp) = ALT(r, ONE)
 
-//n-times
+//n-times (explicitly expanded)
 def NTIMES(r: Rexp, n: Int) : Rexp = n match {
   case 0 => ONE
   case 1 => r