# HG changeset patch # User Christian Urban # Date 1351719987 0 # Node ID 485f38b530abcb27155e324d47ce61cf665edc71 # Parent 0cb2464e5d0e4444ccc0dd361ac4102e41675915 updated diff -r 0cb2464e5d0e -r 485f38b530ab parser.scala --- a/parser.scala Wed Oct 31 08:56:08 2012 +0000 +++ b/parser.scala Wed Oct 31 21:46:27 2012 +0000 @@ -139,7 +139,8 @@ // grammar for arithmetic expressions val grammar = - List ("E" -> List(T_NUM), + List ("F" -> List(T_NUM), + "E" -> List(T_NUM), "E" -> List(NT("E"), T_OP("+"), NT("E")), "E" -> List(NT("E"), T_OP("-"), NT("E")), "E" -> List(NT("E"), T_OP("*"), NT("E")), @@ -165,7 +166,7 @@ } def parse(g: Grammar, ts: List[Token]) : Boolean = { - //println(ts) + println(ts) if (ts == List(NT("E"))) true else { val tss = for ((lhs, rhs) <- g) yield replace(ts, rhs, List(NT(lhs))) @@ -180,7 +181,7 @@ -parser(grammar, lexing_rules, "2 + 3 * 4 + 1") +parser(grammar, lexing_rules, "2 + 3 * 4 + 1") parser(grammar, lexing_rules, "(2 + 3) * (4 + 1)") parser(grammar, lexing_rules, "(2 + 3) * 4 (4 + 1)") diff -r 0cb2464e5d0e -r 485f38b530ab re1.scala --- a/re1.scala Wed Oct 31 08:56:08 2012 +0000 +++ b/re1.scala Wed Oct 31 21:46:27 2012 +0000 @@ -1,7 +1,5 @@ -abstract class Rexp { - def simp : Rexp = this -} +abstract class Rexp case object NULL extends Rexp case object EMPTY extends Rexp @@ -45,7 +43,7 @@ // derivative w.r.t. a string (iterates der) def ders (s: List[Char], r: Rexp) : Rexp = s match { case Nil => r - case c::s => ders(s, der(c, r).simp) + case c::s => ders(s, der(c, r)) } // main matcher function @@ -71,7 +69,7 @@ (end - start)/(i * 1.0e9) } -for (i <- 1 to 22) { +for (i <- 1 to 29) { println(i + ": " + "%.5f".format(time_needed(1, matcher(RTEST(i), "a" * i)))) }