updated
authorChristian Urban <urbanc@in.tum.de>
Wed, 31 Oct 2012 21:46:27 +0000
changeset 54 485f38b530ab
parent 53 0cb2464e5d0e
child 55 cceed8d66b28
updated
parser.scala
re1.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)")
 
--- 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))))
 }