updated
authorChristian Urban <urbanc@in.tum.de>
Tue, 05 Dec 2017 13:49:47 +0000
changeset 542 37a3db7cd655
parent 541 885cf83ebce3
child 543 16adebf18ef9
updated
pics/bridge-limits.png
pics/code.jpg
pics/ken-thompson.jpg
pics/marspath1.png
pics/marspath3.png
pics/marsrover.png
pics/p1.pdf
pics/p2.jpg
pics/p3.jpg
pics/p4.jpg
pics/state.png
pics/state2.png
pics/state3.jpg
pics/state4.jpg
pics/state5.png
pics/state6.png
pics/towerbridge.jpg
progs/token.scala
slides/slides10.pdf
Binary file pics/bridge-limits.png has changed
Binary file pics/code.jpg has changed
Binary file pics/ken-thompson.jpg has changed
Binary file pics/marspath1.png has changed
Binary file pics/marspath3.png has changed
Binary file pics/marsrover.png has changed
Binary file pics/p1.pdf has changed
Binary file pics/p2.jpg has changed
Binary file pics/p3.jpg has changed
Binary file pics/p4.jpg has changed
Binary file pics/state.png has changed
Binary file pics/state2.png has changed
Binary file pics/state3.jpg has changed
Binary file pics/state4.jpg has changed
Binary file pics/state5.png has changed
Binary file pics/state6.png has changed
Binary file pics/towerbridge.jpg has changed
--- a/progs/token.scala	Sun Jan 01 01:55:12 2017 +0000
+++ b/progs/token.scala	Tue Dec 05 13:49:47 2017 +0000
@@ -8,7 +8,7 @@
 case class ALT(r1: Rexp, r2: Rexp) extends Rexp 
 case class SEQ(r1: Rexp, r2: Rexp) extends Rexp 
 case class STAR(r: Rexp) extends Rexp 
-case class RECD(x: String, r: Rexp) extends Rexp
+case class RECD[A](f: String => A, r: Rexp) extends Rexp
 
 abstract class Val
 case object Empty extends Val
@@ -17,7 +17,7 @@
 case class Left(v: Val) extends Val
 case class Right(v: Val) extends Val
 case class Stars(vs: List[Val]) extends Val
-case class Rec(x: String, v: Val) extends Val
+case class Rec[A](f: String => A, v: Val) extends Val
    
 // some convenience for typing in regular expressions
 def charlist2rexp(s : List[Char]): Rexp = s match {
@@ -79,20 +79,20 @@
   case Chr(c) => c.toString
   case Left(v) => flatten(v)
   case Right(v) => flatten(v)
-  case Sequ(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)
 }
 
 // extracts an environment from a value
-def env(v: Val) : List[(String, String)] = v match {
+def env[A](v: Val) : List[A] = v match {
   case Empty => Nil
   case Chr(c) => Nil
   case Left(v) => env(v)
   case Right(v) => env(v)
   case Sequ(v1, v2) => env(v1) ::: env(v2)
   case Stars(vs) => vs.flatMap(env)
-  case Rec(x, v) => (x, flatten(v))::env(v)
+  case Rec(f, v) => ((f:String => A)(flatten(v)))::env(v)
 }
 
 // injection part
@@ -211,7 +211,7 @@
 val STRING: Rexp = "\"" ~ SYM.% ~ "\""
 
 
-val WHILE_REGS = (("k" $ KEYWORD) | 
+val WHILE_REGS = (((s) => Token $ KEYWORD) | 
                   ("i" $ ID) | 
                   ("o" $ OP) | 
                   ("n" $ NUM) | 
@@ -221,6 +221,20 @@
                   ("b" $ (BEGIN | END)) | 
                   ("w" $ WHITESPACE)).%
 
+
+
+
+// extracts an environment from a value
+def env(v: Val) : List[Token] = v match {
+  case Empty => Nil
+  case Chr(c) => Nil
+  case Left(v) => env(v)
+  case Right(v) => env(v)
+  case Sequ(v1, v2) => env(v1) ::: env(v2)
+  case Stars(vs) => vs.flatMap(env)
+  case Rec(f, v) => (f(flatten(v)))::env(v)
+}
+
 //   Testing
 //============
 
@@ -282,4 +296,8 @@
   time(lexing_simp(WHILE_REGS, prog2 * i))
 }
 
+abstract class Token
+case class KeyToken(s: String) extends Token
+case class IdToken(s: String) extends Token
 
+list[(STRING, STRING)]=> List(TOKEN)
Binary file slides/slides10.pdf has changed