--- a/progs/comb1.scala Wed Oct 24 13:07:13 2018 +0100
+++ b/progs/comb1.scala Wed Oct 24 16:03:07 2018 +0100
@@ -79,6 +79,8 @@
(("a" ~ Pal ~ "a") ==> { case ((x, y), z) => x + y + z } ||
("b" ~ Pal ~ "b") ==> { case ((x, y), z) => x + y + z } || "a" || "b" || "")
+Pal.parse_all("abaaaba")
+
println("Palindrome: " + Pal.parse_all("abaaaba"))
// well-nested parenthesis parser
@@ -91,6 +93,7 @@
P.parse_all("()")
// arithmetic expressions
+
lazy val E: Parser[String, Int] =
(T ~ "+" ~ E) ==> { case ((x, y), z) => x + z } ||
(T ~ "-" ~ E) ==> { case ((x, y), z) => x - z } || T
@@ -99,12 +102,15 @@
lazy val F: Parser[String, Int] =
("(" ~ E ~ ")") ==> { case ((x, y), z) => y } || NumParser
+
println(E.parse("4*2+3"))
-println(E.parse_all("4*2+3"))
+println(E.parse_all("4/2+3"))
println(E.parse("1 + 2 * 3"))
println(E.parse_all("(1+2)+3"))
println(E.parse_all("1+2+3"))
+
+
// no left-recursion allowed, otherwise will loop
lazy val EL: Parser[String, Int] =
((EL ~ "+" ~ EL) ==> { case ((x, y), z) => x + z} ||