progs/comb1.scala
changeset 599 33c4b580092b
parent 598 e3ad67cd5123
child 624 8d0af38389bc
--- a/progs/comb1.scala	Tue Nov 06 08:18:53 2018 +0000
+++ b/progs/comb1.scala	Mon Nov 12 11:33:51 2018 +0000
@@ -99,7 +99,15 @@
 lazy val F: Parser[String, Int] = 
   ("(" ~ E ~ ")") ==> { case ((x, y), z) => y } | NumParserInt
 
+lazy val E: Parser[String, String] = 
+  (T ~ "+" ~ E) ==> { case ((x, y), z) => "(" + x + ")+(" + z + ")"} | T 
+lazy val T: Parser[String, String] = 
+  (F ~ "*" ~ T) ==> { case ((x, y), z) => "(" + x + ")*("+ z + ")"} | F
+lazy val F: Parser[String, String] = 
+  ("(" ~ E ~ ")") ==> { case ((x, y), z) => y } | NumParser
 
+println(E.parse_all("1+3+4"))
+println(E.parse("1+3+4"))
 println(E.parse_all("4*2+3"))
 println(E.parse_all("4*(2+3)"))
 println(E.parse_all("(4)*((2+3))"))
@@ -126,12 +134,12 @@
 lazy val S : Parser[String, String] =
   ("1" ~ S ~ S) ==> { case ((x, y), z) => x + y + z } | ""
 
-S.parse("1" * 15)
+S.parse("1" * 17)
 
 lazy val U : Parser[String, String] =
   ("1" ~ U) ==> { case (x, y) => x + y  } | ""
 
-U.parse("1" * 15)
+U.parse("1" * 25)
 
 U.parse("11")
 U.parse("11111")