--- a/progs/comb1.scala Thu Oct 24 14:39:29 2019 +0100
+++ b/progs/comb1.scala Fri Oct 25 14:55:31 2019 +0100
@@ -5,7 +5,7 @@
* constraint IsSeq, which means that the input type 'I' needs
* to be a sequence. */
- type IsSeq[A] = A => Seq[_]
+type IsSeq[A] = A => Seq[_]
abstract class Parser[I : IsSeq, T] {
def parse(ts: I): Set[(T, I)]
@@ -84,6 +84,7 @@
("b" ~ Pal ~ "b") ==> { case ((x, y), z) => x + y + z } || "a" || "b" || "")
Pal.parse_all("abaaaba")
+Pal.parse_all("abacba")
Pal.parse("abaaaba")
println("Palindrome: " + Pal.parse_all("abaaaba"))
@@ -97,6 +98,13 @@
P.parse_all(")(")
P.parse_all("()")
+lazy val PC : Parser[String, Int] =
+ ("(" ~ PC ~ ")" ~ PC ==> { case (((_, x), _), y) => x + y + 2 } ||
+ "" ==> { (s) => 0 })
+
+PC.parse_all("(((()()))())")
+P.parse_all("(((()()))()))")
+
// Arithmetic Expressions (Terms and Factors)
lazy val E: Parser[String, Int] =