updated
authorChristian Urban <christian dot urban at kcl dot ac dot uk>
Thu, 13 Oct 2016 13:13:27 +0100
changeset 450 d91a1748a9be
parent 449 be599d76f592
child 451 4a5876f321ae
updated
progs/token.scala
slides/slides04.pdf
--- a/progs/token.scala	Thu Oct 13 12:57:07 2016 +0100
+++ b/progs/token.scala	Thu Oct 13 13:13:27 2016 +0100
@@ -1,6 +1,5 @@
 import scala.language.implicitConversions    
 import scala.language.reflectiveCalls
-import scala.annotation.tailrec   
 
 abstract class Rexp 
 case object ZERO extends Rexp
@@ -120,13 +119,17 @@
 
 // main lexing function (produces a value)
 def lex(r: Rexp, s: List[Char]) : Val = s match {
-  case Nil => if (nullable(r)) mkeps(r) else throw new Exception("Not matched")
+  case Nil => if (nullable(r)) mkeps(r) 
+              else throw new Exception("Not matched")
   case c::cs => inj(r, c, lex(der(c, r), cs))
 }
 
 def lexing(r: Rexp, s: String) : Val = lex(r, s.toList)
 
-lexing(("ab" | "ab") ~ ("b" | ONE), "ab")
+
+lexing(("ab" | "a") ~ ("b" | ONE), "ab")
+
+
 
 // some "rectification" functions for simplification
 def F_ID(v: Val): Val = v
@@ -194,6 +197,7 @@
 // Lexing Rules for a Small While Language
 
 def PLUS(r: Rexp) = r ~ r.%
+
 val SYM = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z"
 val DIGIT = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
 val ID = SYM ~ (SYM | DIGIT).% 
@@ -270,8 +274,10 @@
 
 println("Tokens")
 println(env(lexing_simp(WHILE_REGS, prog2)))
+println(env(lexing_simp(WHILE_REGS, prog2)).filterNot{_._1 == "w"}.mkString("\n"))
 
-for (i <- 1 to 80) {
+// some more timing tests
+for (i <- 1 to 101 by 10) {
   print(i.toString + ":  ")
   time(lexing_simp(WHILE_REGS, prog2 * i))
 }
Binary file slides/slides04.pdf has changed