Question: Define the structure as a set of case class in scala. sealed trait Regex // Use constructors: Atom, Concatenation, OrOperator, AndOperator and KleeneStar // YOUR
Define the structure as a set of case class in scala.
sealed trait Regex // Use constructors: Atom, Concatenation, OrOperator, AndOperator and KleeneStar // YOUR CODE HERE ???
//BEGIN TEST val v1 = Atom("Hello") val v2 = Concatenation(v1, v1) val v3 = OrOperator(v1, v2) val v4 = KleeneStar(v3) val v5 = AndOperator(v1, v4) passed(10) //END TEST

B (7 points) Define the structure as a set of case class in scala. In ( ): sealed trait Regex // Use constructors: Atom, Concatenation, Oroperator, Andoperator and Kleenestar // YOUR CODE HERE ??? In [ ]: //BEGIN TEST val vl = Atom( "Hello") val v2 = Concatenation (vl, vl) val v3 = OrOperator(vi, v2) val v4 = KleeneStar (v3) val v5 = AndOperator(vi, v4) passed (10) //END TEST C (8 points) Write down the representation of the regular expression in Scala. Your cell must define a term that should be called finalAnswerc. ("hello"|("scala"; "best"))* In [ ]: val finalAnswerc = { // YOUR CODE HERE 222 In [ ]: //BEGIN TEST def munge(r: Regex): String = r match { case Atom(at) => "SA$"+st case Concatenation(rl, r2) => munge (11)+"$C$"+munge (12) case KleeneStar (I) => "$K$"+munge(r)+"$S$" case OrOperator(ri, 12) => munge(rl)+"_0_"+munge(r2) case AndOperator (ri,r2) => munge(rl)+"/\"+ munge (r2) } assert (munge(finalAnswerc) == "$K$$A$hello_0_$K$$A$scala$c$$A$best$S$$$$") passed (8) //END TEST B (7 points) Define the structure as a set of case class in scala. In ( ): sealed trait Regex // Use constructors: Atom, Concatenation, Oroperator, Andoperator and Kleenestar // YOUR CODE HERE ??? In [ ]: //BEGIN TEST val vl = Atom( "Hello") val v2 = Concatenation (vl, vl) val v3 = OrOperator(vi, v2) val v4 = KleeneStar (v3) val v5 = AndOperator(vi, v4) passed (10) //END TEST C (8 points) Write down the representation of the regular expression in Scala. Your cell must define a term that should be called finalAnswerc. ("hello"|("scala"; "best"))* In [ ]: val finalAnswerc = { // YOUR CODE HERE 222 In [ ]: //BEGIN TEST def munge(r: Regex): String = r match { case Atom(at) => "SA$"+st case Concatenation(rl, r2) => munge (11)+"$C$"+munge (12) case KleeneStar (I) => "$K$"+munge(r)+"$S$" case OrOperator(ri, 12) => munge(rl)+"_0_"+munge(r2) case AndOperator (ri,r2) => munge(rl)+"/\"+ munge (r2) } assert (munge(finalAnswerc) == "$K$$A$hello_0_$K$$A$scala$c$$A$best$S$$$$") passed (8) //END TEST
Step by Step Solution
There are 3 Steps involved in it
StepbyStep Solution Part B Define the Structure as a Set of Case Classes First we need to define a s... View full answer
Get step-by-step solutions from verified subject matter experts
