progs/token.scala
changeset 520 2849c305b12d
parent 450 d91a1748a9be
child 521 95af9beb4b7f
--- a/progs/token.scala	Sun Oct 15 20:47:14 2017 +0100
+++ b/progs/token.scala	Tue Oct 17 13:49:45 2017 +0100
@@ -13,7 +13,7 @@
 abstract class Val
 case object Empty extends Val
 case class Chr(c: Char) extends Val
-case class Seq(v1: Val, v2: Val) extends Val
+case class Sequ(v1: Val, v2: Val) extends Val
 case class Left(v: Val) extends Val
 case class Right(v: Val) extends Val
 case class Stars(vs: List[Val]) extends Val
@@ -79,7 +79,7 @@
   case Chr(c) => c.toString
   case Left(v) => flatten(v)
   case Right(v) => flatten(v)
-  case Seq(v1, v2) => flatten(v1) + flatten(v2)
+  case Sequ(v1, v2) => flatten(v1) + flatten(v2)
   case Stars(vs) => vs.map(flatten).mkString
   case Rec(_, v) => flatten(v)
 }
@@ -90,7 +90,7 @@
   case Chr(c) => Nil
   case Left(v) => env(v)
   case Right(v) => env(v)
-  case Seq(v1, v2) => env(v1) ::: env(v2)
+  case Sequ(v1, v2) => env(v1) ::: env(v2)
   case Stars(vs) => vs.flatMap(env)
   case Rec(x, v) => (x, flatten(v))::env(v)
 }
@@ -100,17 +100,17 @@
   case ONE => Empty
   case ALT(r1, r2) => 
     if (nullable(r1)) Left(mkeps(r1)) else Right(mkeps(r2))
-  case SEQ(r1, r2) => Seq(mkeps(r1), mkeps(r2))
+  case SEQ(r1, r2) => Sequ(mkeps(r1), mkeps(r2))
   case STAR(r) => Stars(Nil)
   case RECD(x, r) => Rec(x, mkeps(r))
 }
 
 
 def inj(r: Rexp, c: Char, v: Val) : Val = (r, v) match {
-  case (STAR(r), Seq(v1, Stars(vs))) => Stars(inj(r, c, v1)::vs)
-  case (SEQ(r1, r2), Seq(v1, v2)) => Seq(inj(r1, c, v1), v2)
-  case (SEQ(r1, r2), Left(Seq(v1, v2))) => Seq(inj(r1, c, v1), v2)
-  case (SEQ(r1, r2), Right(v2)) => Seq(mkeps(r1), inj(r2, c, v2))
+  case (STAR(r), Sequ(v1, Stars(vs))) => Stars(inj(r, c, v1)::vs)
+  case (SEQ(r1, r2), Sequ(v1, v2)) => Sequ(inj(r1, c, v1), v2)
+  case (SEQ(r1, r2), Left(Sequ(v1, v2))) => Sequ(inj(r1, c, v1), v2)
+  case (SEQ(r1, r2), Right(v2)) => Sequ(mkeps(r1), inj(r2, c, v2))
   case (ALT(r1, r2), Left(v1)) => Left(inj(r1, c, v1))
   case (ALT(r1, r2), Right(v2)) => Right(inj(r2, c, v2))
   case (CHAR(d), Empty) => Chr(c) 
@@ -140,12 +140,12 @@
   case Left(v) => Left(f1(v))
 }
 def F_SEQ(f1: Val => Val, f2: Val => Val) = (v:Val) => v match {
-  case Seq(v1, v2) => Seq(f1(v1), f2(v2))
+  case Sequ(v1, v2) => Sequ(f1(v1), f2(v2))
 }
 def F_SEQ_Empty1(f1: Val => Val, f2: Val => Val) = 
-  (v:Val) => Seq(f1(Empty), f2(v))
+  (v:Val) => Sequ(f1(Empty), f2(v))
 def F_SEQ_Empty2(f1: Val => Val, f2: Val => Val) = 
-  (v:Val) => Seq(f1(v), f2(Empty))
+  (v:Val) => Sequ(f1(v), f2(Empty))
 def F_RECD(f: Val => Val) = (v:Val) => v match {
   case Rec(x, v) => Rec(x, f(v))
 }