diff -r e9d14d58be3c -r daf561a83ba6 main_templates3/re.scala --- a/main_templates3/re.scala Thu Jan 13 12:55:03 2022 +0000 +++ b/main_templates3/re.scala Mon Apr 11 23:55:27 2022 +0100 @@ -12,28 +12,12 @@ case class SEQ(r1: Rexp, r2: Rexp) extends Rexp // sequence case class STAR(r: Rexp) extends Rexp // star -import scala.language.implicitConversions -import scala.language.reflectiveCalls - -def charlist2rexp(s: List[Char]): Rexp = s match { - case Nil => ONE - case c::Nil => CHAR(c) - case c::s => SEQ(CHAR(c), charlist2rexp(s)) -} -implicit def string2rexp(s: String): Rexp = charlist2rexp(s.toList) - - -// "a|b" -ALT(CHAR('a'), CHAR('b')) - -val reg : Rexp = "a" | "b" // CHAR('a') - -// some convenience for typing regular expressions - //the usual binary choice can be defined in terms of ALTs def ALT(r1: Rexp, r2: Rexp) = ALTs(List(r1, r2)) +// some convenience for typing regular expressions + import scala.language.implicitConversions import scala.language.reflectiveCalls @@ -44,9 +28,6 @@ } implicit def string2rexp(s: String): Rexp = charlist2rexp(s.toList) - - - implicit def RexpOps (r: Rexp) = new { def | (s: Rexp) = ALT(r, s) def % = STAR(r) @@ -61,6 +42,11 @@ def ~ (r: String) = SEQ(s, r) } + +// ALT(CHAR('a'), CHAR('b')) +// val reg : Rexp = "a" | "b" + + // (1) Complete the function nullable according to // the definition given in the coursework; this // function checks whether a regular expression