--- a/progs/parser-combinators/comb1.sc Tue Nov 15 11:34:33 2022 +0000
+++ b/progs/parser-combinators/comb1.sc Thu Nov 24 19:05:34 2022 +0000
@@ -141,7 +141,7 @@
println(P.parse_all("()"))
// A parser for arithmetic expressions (Terms and Factors)
-{
+
lazy val E: Parser[String, Int] = {
(T ~ p"+" ~ E).map{ case ((x, _), z) => x + z } ||
(T ~ p"-" ~ E).map{ case ((x, _), z) => x - z } || T }
@@ -149,7 +149,7 @@
(F ~ p"*" ~ T).map{ case ((x, _), z) => x * z } || F }
lazy val F: Parser[String, Int] = {
(p"(" ~ E ~ p")").map{ case ((_, y), _) => y } || NumParserInt }
-}
+
println(E.parse_all("1+3+4"))
println(E.parse("1+3+4"))
println(E.parse_all("4*2+3"))