progs/matcher/re1.sc
changeset 919 53f08d873e09
parent 913 eef6a56c185a
child 928 2f3c077359c4
--- a/progs/matcher/re1.sc	Fri Sep 15 10:49:33 2023 +0100
+++ b/progs/matcher/re1.sc	Sun Sep 17 19:12:57 2023 +0100
@@ -1,6 +1,6 @@
 // A simple matcher for basic regular expressions
 //
-// Call the test cases with X = {1,2,3}
+// Call the testcases with X = {1,2,3}
 //
 //   amm re1.sc testX
 //
@@ -19,9 +19,9 @@
 case class SEQ(r1: Rexp, r2: Rexp) extends Rexp  // sequence
 case class STAR(r: Rexp) extends Rexp            // star
 
+
 // nullable function: tests whether a regular 
-// expression can recognise the empty string
-  
+// expression can recognise the empty string  
 def nullable(r: Rexp) : Boolean = r match {
   case ZERO => false
   case ONE => true
@@ -54,13 +54,12 @@
   nullable(ders(s.toList, r))
 
 
+// some examples from the homework
 
 val r = SEQ(CHAR('b'), CHAR('c'))
 matcher(r, "ac")
 
-// some examples from the homework
-
-val r = STAR(ALT(SEQ(CHAR('a'), CHAR('b')), CHAR('b')))
+val r1 = STAR(ALT(SEQ(CHAR('a'), CHAR('b')), CHAR('b')))
 der('a', r)
 der('b', r)
 der('c', r)
@@ -71,6 +70,9 @@
 der('z', der('y', der('x', r2)))
 
 
+// Test Cases
+//============
+
 // the optional regular expression (one or zero times)
 def OPT(r: Rexp) = ALT(r, ONE)   // r + 1
 
@@ -81,10 +83,6 @@
   case n => SEQ(r, NTIMES(r, n - 1))
 }
 
-
-// Test Cases
-//============
-
 // the evil regular expression  (a?){n} a{n}
 def EVIL1(n: Int) = 
   SEQ(NTIMES(OPT(CHAR('a')), n), NTIMES(CHAR('a'), n))