diff -r be599d76f592 -r d91a1748a9be progs/token.scala --- 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)) }