updated
authorChristian Urban <christian.urban@kcl.ac.uk>
Mon, 29 Aug 2022 01:16:32 +0200
changeset 873 a25da86f7c8c
parent 872 5f5e165c9a57
child 874 ffe02fd574a5
updated
cws/cw01.pdf
cws/cw02.pdf
cws/cw03.pdf
cws/cw04.pdf
cws/cw05.pdf
cws/cw05.tex
handouts/amm-ho.pdf
handouts/graphs.pdf
handouts/ho01.pdf
handouts/ho02.pdf
handouts/ho02.tex
handouts/ho03.pdf
handouts/ho04.pdf
handouts/ho05.pdf
handouts/ho06.pdf
handouts/ho07.pdf
handouts/ho08.pdf
handouts/ho09.pdf
handouts/ho10.pdf
handouts/notation.pdf
hws/hw01.pdf
hws/hw02.pdf
hws/hw03.pdf
hws/hw04.pdf
hws/hw05.pdf
hws/hw06.pdf
hws/hw07.pdf
hws/hw08.pdf
hws/hw09.pdf
hws/proof.pdf
langs.sty
progs/display/MinimalApplication.scala
progs/display/build.sc
progs/display/display.scala
progs/pprint/tree.sc
slides/slides01.pdf
slides/slides02.pdf
slides/slides03.pdf
slides/slides04.pdf
slides/slides05.pdf
slides/slides06.pdf
slides/slides07.pdf
slides/slides08.pdf
slides/slides09.pdf
slides/slides10.pdf
slides/slides11.pdf
slides/slides12.pdf
solution/cw5/fun_parser.sc
Binary file cws/cw01.pdf has changed
Binary file cws/cw02.pdf has changed
Binary file cws/cw03.pdf has changed
Binary file cws/cw04.pdf has changed
Binary file cws/cw05.pdf has changed
--- 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}
 
Binary file handouts/amm-ho.pdf has changed
Binary file handouts/graphs.pdf has changed
Binary file handouts/ho01.pdf has changed
Binary file handouts/ho02.pdf has changed
--- 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
Binary file handouts/ho03.pdf has changed
Binary file handouts/ho04.pdf has changed
Binary file handouts/ho05.pdf has changed
Binary file handouts/ho06.pdf has changed
Binary file handouts/ho07.pdf has changed
Binary file handouts/ho08.pdf has changed
Binary file handouts/ho09.pdf has changed
Binary file handouts/ho10.pdf has changed
Binary file handouts/notation.pdf has changed
Binary file hws/hw01.pdf has changed
Binary file hws/hw02.pdf has changed
Binary file hws/hw03.pdf has changed
Binary file hws/hw04.pdf has changed
Binary file hws/hw05.pdf has changed
Binary file hws/hw06.pdf has changed
Binary file hws/hw07.pdf has changed
Binary file hws/hw08.pdf has changed
Binary file hws/hw09.pdf has changed
Binary file hws/proof.pdf has changed
--- 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,%
--- 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("&#10084;&#65039;")
-  val unicorn = raw("&#129412;")
-
-  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()
-}
--- 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")
--- 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))
           )
--- 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("&middot")), 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)
+}  
Binary file slides/slides01.pdf has changed
Binary file slides/slides02.pdf has changed
Binary file slides/slides03.pdf has changed
Binary file slides/slides04.pdf has changed
Binary file slides/slides05.pdf has changed
Binary file slides/slides06.pdf has changed
Binary file slides/slides07.pdf has changed
Binary file slides/slides08.pdf has changed
Binary file slides/slides09.pdf has changed
Binary file slides/slides10.pdf has changed
Binary file slides/slides11.pdf has changed
Binary file slides/slides12.pdf has changed
--- 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 } ||