# HG changeset patch # User Christian Urban # Date 1763422107 0 # Node ID ee39fd6df150695608904814274c376747520520 # Parent b963117014ffa70c882b488c582c652def4e4897 updated diff -r b963117014ff -r ee39fd6df150 handouts/amm-faq.pdf Binary file handouts/amm-faq.pdf has changed diff -r b963117014ff -r ee39fd6df150 handouts/amm-faq.tex --- a/handouts/amm-faq.tex Fri Nov 14 12:38:59 2025 +0000 +++ b/handouts/amm-faq.tex Mon Nov 17 23:28:27 2025 +0000 @@ -137,6 +137,20 @@ \texttt{infix def \$ (r: Rexp) = RECD(s, r)} %$ \end{center} +\subsection*{Outdated Syntax in CW4} + +The templates for this task contain the lines + +\begin{lstlisting}[numbers=none,language=Scala] +def i(args: Any*): String = " " ++ sc.s(args:_*) ++ "\n" +def l(args: Any*): String = sc.s(args:_*) ++ ":\n" +\end{lstlisting} + +\noindent +which produce a warning about ``The syntax `x: \_*` is no longer +supported for vararg splices''. This warning can be avoided by writing +\texttt{args*} instead of \texttt{args:\_*}. + \end{document} %%% Local Variables: diff -r b963117014ff -r ee39fd6df150 progs/parser-combinators/comb1.sc --- a/progs/parser-combinators/comb1.sc Fri Nov 14 12:38:59 2025 +0000 +++ b/progs/parser-combinators/comb1.sc Mon Nov 17 23:28:27 2025 +0000 @@ -97,7 +97,7 @@ // (needs "new" because MapParser is not a case class) val NumParserInt = MapParser(NumParser, (s: String) => s.toInt) -NumParserInt.parse("123abc") +NumParserInt.parse("a123abc") // the following string interpolation allows us to write // StrParser(_some_string_) more conveniently as @@ -139,6 +139,17 @@ // A parser for palindromes (just returns them as string) // since the parser is recursive it needs to be lazy +val foo = foo + foo + +lazy val Foo : Parser[String, String] = p"a" || p"b" || p"" + + +lazy val Pal : Parser[String, String] = { + (p"a" ~ Pal ~ p"a") || + (p"b" ~ Pal ~ p"b") || + p"a" || p"b" || p"" +} + lazy val Pal : Parser[String, String] = { (p"a" ~ Pal ~ p"a").map{ case ((x, y), z) => s"$x$y$z" } || (p"b" ~ Pal ~ p"b").map{ case ((x, y), z) => s"$x$y$z" } || @@ -146,7 +157,7 @@ } // examples -Pal.parse("abaaba") +Pal.parse_all("abaaba") Pal.parse("abacaaba") println("Palindrome: " + Pal.parse_all("abaaaba")) @@ -178,8 +189,8 @@ (p"(" ~ E ~ p")").map{ case ((_, y), _) => y } || NumParserInt } println(E.parse_all("2*2*2")) +println(E.parse_all("5+3+4")) 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)))"))