# HG changeset patch # User Christian Urban # Date 1661728592 -7200 # Node ID a25da86f7c8c367f5f2327b7fd0fbf5d8a970aa6 # Parent 5f5e165c9a5773a51ba3d10378d0746a4162f921 updated diff -r 5f5e165c9a57 -r a25da86f7c8c cws/cw01.pdf Binary file cws/cw01.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c cws/cw02.pdf Binary file cws/cw02.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c cws/cw03.pdf Binary file cws/cw03.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c cws/cw04.pdf Binary file cws/cw04.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c cws/cw05.pdf Binary file cws/cw05.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c cws/cw05.tex --- a/cws/cw05.tex Sat Apr 02 01:52:43 2022 +0100 +++ b/cws/cw05.tex Mon Aug 29 01:16:32 2022 +0200 @@ -3,8 +3,31 @@ \usepackage{../style} \usepackage{../graphicss} \usepackage{../langs} +\definecolor{navyblue}{rgb}{0.0, 0.0, 0.5} +\definecolor{pansypurple}{rgb}{0.47, 0.09, 0.29} \begin{document} +\color{pansypurple} + +\section*{RESIT / REPLACEMENT} + +{\bf +The resit / replacement task is essentially CW5 (listed below) with +the exception that the lexer and parser is already provided. The +parser will generate an AST (see file \texttt{fun\_llvm.sc}). Your task +is to generate an AST for the K-intermediate language and supply +sufficient type annotations such that you can generate valid code for +the LLVM-IR. The submission deadline is 9th August at 16:00. At the +deadline, please send me an email containing a zip-file with your +files. +Feel free to reuse the files I have uploaded on KEATS (especially +the files generating simple LLVM-IR code). Of help might also be the +videos of Week~10.\bigskip + +\noindent +Good Luck!} +\color{black} + \section*{Coursework 5} diff -r 5f5e165c9a57 -r a25da86f7c8c handouts/amm-ho.pdf Binary file handouts/amm-ho.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c handouts/graphs.pdf Binary file handouts/graphs.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c handouts/ho01.pdf Binary file handouts/ho01.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c handouts/ho02.pdf Binary file handouts/ho02.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c handouts/ho02.tex --- a/handouts/ho02.tex Sat Apr 02 01:52:43 2022 +0100 +++ b/handouts/ho02.tex Mon Aug 29 01:16:32 2022 +0200 @@ -28,7 +28,7 @@ matcher (the plots on the right below)---more efficient than the matchers from regular expression libraries in Ruby, Python, JavaScript and Java (the plots on the left).\footnote{Have a look at KEATS: students -last year contributed also date for the Swift and Dart languages.}\medskip +last year contributed also data for the Swift and Dart languages.}\medskip \noindent To start with let us look more closely at the experimental data: The diff -r 5f5e165c9a57 -r a25da86f7c8c handouts/ho03.pdf Binary file handouts/ho03.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c handouts/ho04.pdf Binary file handouts/ho04.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c handouts/ho05.pdf Binary file handouts/ho05.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c handouts/ho06.pdf Binary file handouts/ho06.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c handouts/ho07.pdf Binary file handouts/ho07.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c handouts/ho08.pdf Binary file handouts/ho08.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c handouts/ho09.pdf Binary file handouts/ho09.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c handouts/ho10.pdf Binary file handouts/ho10.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c handouts/notation.pdf Binary file handouts/notation.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c hws/hw01.pdf Binary file hws/hw01.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c hws/hw02.pdf Binary file hws/hw02.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c hws/hw03.pdf Binary file hws/hw03.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c hws/hw04.pdf Binary file hws/hw04.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c hws/hw05.pdf Binary file hws/hw05.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c hws/hw06.pdf Binary file hws/hw06.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c hws/hw07.pdf Binary file hws/hw07.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c hws/hw08.pdf Binary file hws/hw08.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c hws/hw09.pdf Binary file hws/hw09.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c hws/proof.pdf Binary file hws/proof.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c langs.sty --- a/langs.sty Sat Apr 02 01:52:43 2022 +0100 +++ b/langs.sty Mon Aug 29 01:16:32 2022 +0200 @@ -37,12 +37,12 @@ \lstdefinelanguage{Scala}{ morekeywords={abstract,then,case,catch,class,def,% - do,else,extends,false,final,finally,% - for,if,implicit,import,match,mixin,% + do,else,enum,extends,false,final,finally,% + for,given,if,implicit,import,lazy,match,mixin,% new,null,object,override,package,% private,protected,requires,return,sealed,% - super,this,throw,trait,true,try,% - type,val,var,while,with,yield,write,read,lazy},% + super,this,then,throw,trait,true,try,% + type,val,var,while,with,yield,write,read},% literate={==>}{{\mbox{\color{codepurple}{\textbf{\texttt{==>}}}}}}2,% otherkeywords={=>,<-,<\%,<:,>:,\#},% sensitive=true,% diff -r 5f5e165c9a57 -r a25da86f7c8c progs/display/MinimalApplication.scala --- a/progs/display/MinimalApplication.scala Sat Apr 02 01:52:43 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -package app - -import scalatags.Text.all._ -import scala.util.Random - - -object MinimalApplication extends cask.MainRoutes{ - - val bootstrap = "https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.css" - - var x = Random.between(0, 7) - var y = Random.between(0, 7) - var z = Random.between(0, 7) - - abstract class Answer - case object No extends Answer - case object Correct extends Answer - case class Wrong(n: Int) extends Answer - - var ans : Answer = No - var cnt = 1 - - val heart = raw("❤️") - val unicorn = raw("🦄") - - var nms = List("Christiane", "Sebastian") - - @cask.get("/") - def hello() = - doctype("html")( - html( - head(link(rel := "stylesheet", href := bootstrap)), - body( - div(cls := "container")( - //h1(s"Hello ${nms((cnt / 3) % 2)}!"), - h1(s"Hello Christiane"), - h1(s"$x + $y = ??"), - ans match { - case No => "" - case Correct => i(color.green)("Correct!") - case Wrong(n) => i(color.red)(s"$n is wrong!") - }, - form(action := "/", method := "post")( - frag( - for (i <- 0 to 12) yield button(`type` := "submit", name := "name", value := i.toString)(i.toString) - ) - ), - frag( - for (i <- 0 until cnt) yield - if ((i + 1) % 10 != 0) heart else unicorn - ) - ) - ) - ) - ) - - @cask.postForm("/") - def answer(name: String) = { - if (x + y == name.toInt) { - ans = Correct - x = Random.between(0, 7) - y = Random.between(0, 7) - z = Random.between(0, 7) - cnt = cnt + 1 - } - else - ans = Wrong(name.toInt) - hello() - } - - initialize() -} diff -r 5f5e165c9a57 -r a25da86f7c8c progs/display/build.sc --- a/progs/display/build.sc Sat Apr 02 01:52:43 2022 +0100 +++ b/progs/display/build.sc Mon Aug 29 01:16:32 2022 +0200 @@ -5,11 +5,11 @@ object app extends ScalaModule { - def scalaVersion = "2.13.3" + def scalaVersion = "2.13.6" def ivyDeps = Agg( - ivy"com.lihaoyi::cask:0.6.7", - ivy"com.lihaoyi::scalatags:0.9.1" + ivy"com.lihaoyi::cask:0.8.0", + ivy"com.lihaoyi::scalatags:0.9.4" ) override def sources = T.sources(baseDir / "display.scala") diff -r 5f5e165c9a57 -r a25da86f7c8c progs/display/display.scala --- a/progs/display/display.scala Sat Apr 02 01:52:43 2022 +0100 +++ b/progs/display/display.scala Mon Aug 29 01:16:32 2022 +0200 @@ -73,10 +73,6 @@ body( div(cls := "container")( h1(s"Hello"), - i(color.green)(s"$cnt"), - form(action := "/", method := "post")( - button(`type` := "submit", name := "name", value := 1)(s"1"), - ), ul(cls := "tree")(pp(evil2)), ul(cls := "tree")(ppa(aevil2)) ) diff -r 5f5e165c9a57 -r a25da86f7c8c progs/pprint/tree.sc --- a/progs/pprint/tree.sc Sat Apr 02 01:52:43 2022 +0100 +++ b/progs/pprint/tree.sc Mon Aug 29 01:16:32 2022 +0200 @@ -1,9 +1,4 @@ -// scalatags -import ammonite.ops._ -import $ivy.`com.lihaoyi::scalatags:0.8.2` -import scalatags.Text.all._ -import scalatags.Text._ // regular expressions including records abstract class Rexp @@ -62,6 +57,11 @@ } +// scalatags +import $ivy.`com.lihaoyi::scalatags:0.8.2` +import scalatags.Text.all._ +import scalatags.Text._ + def pp(r: Rexp) : TypedTag[String] = r match { case CHAR(c) => li(code(c.toString)) case ALT(r1, r2) => li(code("+"), ul(pp(r1), pp(r2))) @@ -104,6 +104,42 @@ @main def main(fname: String) = { - val content = index(List(r1)) - write.over(pwd / fname, content) + val content = index(List(r1, r2, evil2)) + os.write.over(os.pwd / fname, content) } + + + +// scalatags +import $ivy.`com.lihaoyi::scalatags:0.8.2` +import scalatags.Text.all._ +import scalatags.Text._ + +def pp(r: Rexp) : TypedTag[String] = r match { + case CHAR(c) => li(code(c.toString)) + case ALTs(rs) => li(code("+"), ul(rs.map(pp))) + case SEQs(rs) => li(code(raw("·")), ul(rs.map(pp))) + case STAR(r1) => li(code("*"), ul(pp(r1))) + case ZERO => li(code("0")) + case ONE => li(code("1")) + //case SPECIAL(s) => li(code(raw(s))) +} + +def mktree(r: Rexp) = + ul(cls := "tree")(pp(r)) + + +def index(rs: List[Rexp]) = + html( + head(link(rel := "stylesheet", href := "./style.css")), + body(rs.map(mktree)) + ) + + +@main +def main(fname: String) = { + val r = ("a" | "ab" | "a") ~ ("c" | "bc") + val strs = List("","a","ab","abc") + val content = index(strs.map(s => ders(s.toList, r))) + os.write.over(os.pwd / fname, content) +} diff -r 5f5e165c9a57 -r a25da86f7c8c slides/slides01.pdf Binary file slides/slides01.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c slides/slides02.pdf Binary file slides/slides02.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c slides/slides03.pdf Binary file slides/slides03.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c slides/slides04.pdf Binary file slides/slides04.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c slides/slides05.pdf Binary file slides/slides05.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c slides/slides06.pdf Binary file slides/slides06.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c slides/slides07.pdf Binary file slides/slides07.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c slides/slides08.pdf Binary file slides/slides08.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c slides/slides09.pdf Binary file slides/slides09.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c slides/slides10.pdf Binary file slides/slides10.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c slides/slides11.pdf Binary file slides/slides11.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c slides/slides12.pdf Binary file slides/slides12.pdf has changed diff -r 5f5e165c9a57 -r a25da86f7c8c solution/cw5/fun_parser.sc --- a/solution/cw5/fun_parser.sc Sat Apr 02 01:52:43 2022 +0100 +++ b/solution/cw5/fun_parser.sc Mon Aug 29 01:16:32 2022 +0200 @@ -155,8 +155,6 @@ (F ~ T_OP("/") ~ T) ==> { case x ~ _ ~ z => Aop("/", x, z): Exp } || (F ~ T_OP("%") ~ T) ==> { case x ~ _ ~ z => Aop("%", x, z): Exp } || F lazy val F: Parser[List[Token], Exp] = - (IdParser ~ T_LPAREN ~ T_RPAREN) ==> - { case x ~ _ ~ _ => Call(x, Nil): Exp } || (IdParser ~ T_LPAREN ~ T_RPAREN) ==> { case x ~ _ ~ _ => Call(x, Nil): Exp } || (IdParser ~ T_LPAREN ~ ListParser(Exp, T_COMMA) ~ T_RPAREN) ==> { case x ~ _ ~ z ~ _ => Call(x, z): Exp } || (T_LPAREN ~ Exp ~ T_RPAREN) ==> { case _ ~ y ~ _ => y: Exp } ||