progs/matcher/re3.sc
changeset 1003 bae8c3eb51c7
parent 999 e719e420cbc7
--- a/progs/matcher/re3.sc	Tue Oct 07 16:20:30 2025 +0100
+++ b/progs/matcher/re3.sc	Wed Oct 08 10:42:10 2025 +0100
@@ -2,7 +2,7 @@
 // of derivatives
 //
 // this keeps the regular expressions (often) small, which
-// is good for the run-time
+// is good for speed
 // 
 // call the test cases with X = {1,2,3,4}
 //
@@ -25,7 +25,6 @@
 import Rexp._
 
 
-
 // the nullable function: tests whether the regular 
 // expression can recognise the empty string
 def nullable (r: Rexp) : Boolean = r match {
@@ -153,6 +152,7 @@
 
 
 
+
 // PS:
 //
 // If you want to dig deeper into the topic, you can have 
@@ -201,44 +201,3 @@
 @arg(doc = "Tests that show not all is hunky-dory, but a solution leads too far afield.")
 @main
 def fail() = { test3(); test4(); test5() } 
-
-
-// simplification
-def simp2(r: Rexp) : Rexp = r match {
-  case ALT(r1, r2) => (simp2(r1), simp2(r2)) match {
-    case (ZERO, r2s) => r2s
-    case (r1s, ZERO) => r1s
-    //case (r1s, r2s) => if (r1s == r2s) r1s else ALT (r1s, r2s)
-    case (r1s, r2s) => ALT(r1s, r2s)
-  }
-  case SEQ(r1, r2) =>  (simp2(r1), simp2(r2)) match {
-    case (ZERO, _) => ZERO
-    case (_, ZERO) => ZERO
-    //case (ONE, r2s) => r2s
-    //case (r1s, ONE) => r1s
-    case (r1s, r2s) => SEQ(r1s, r2s)
-  }
-  case r => r
-}
-
-// some convenience for typing in regular expressions
-import scala.language.implicitConversions
-
-def charlist2rexp(s : List[Char]): Rexp = s match {
-  case Nil => ONE
-  case c::Nil => CHAR(c)
-  case c::s => SEQ(CHAR(c), charlist2rexp(s))
-}
-
-given Conversion[String, Rexp] = (s => charlist2rexp(s.toList))
-
-val HELLO : Rexp = "hello"
-
-extension (r: Rexp) {
-  def | (s: Rexp) = ALT(r, s)
-  def % = STAR(r)
-  def ~ (s: Rexp) = SEQ(r, s)
-}
-
-val re = (ONE | "a" | "ab") ~ ("c" | "bc") ~ ("d" | "e")
-simp2(der('d', der('c', der('b', der('a', re)))))
\ No newline at end of file