updated
authorChristian Urban <christian.urban@kcl.ac.uk>
Wed, 21 Dec 2022 14:33:05 +0000
changeset 905 15973df32613
parent 904 d97283992d4f
child 906 2bf1516d730f
updated
cws/cw04.pdf
cws/cw04.tex
cws/cw05.pdf
cws/cw05.tex
handouts/ho01.pdf
handouts/ho01.tex
progs/fun/fun_llvm.sc
solutions/cw3/collatz.while
solutions/cw3/factors.while
solutions/cw3/lexer.sc
solutions/cw3/parser.sc
solutions/cw4/compiler.sc
Binary file cws/cw04.pdf has changed
--- a/cws/cw04.tex	Fri Dec 09 13:18:10 2022 +0000
+++ b/cws/cw04.tex	Wed Dec 21 14:33:05 2022 +0000
@@ -91,7 +91,7 @@
 \noindent and
 
 \begin{center}
-  \small\url{http://www.csc.villanova.edu/~tway/courses/csc4181/s2021/labs/lab4/JVM.pdf}
+  \small\url{http://www.csc.villanova.edu/~tway/courses/csc4181/s2022/labs/finalproject/JVM.pdf}
 \end{center}
 
 \subsection*{Krakatau Assembler}
@@ -204,7 +204,7 @@
 i := 2;
 while (i <= 4) do {
     write i;
-    i := i + 1;
+    i := i + 1
 }
 \end{lstlisting}
 \end{minipage}
Binary file cws/cw05.pdf has changed
--- a/cws/cw05.tex	Fri Dec 09 13:18:10 2022 +0000
+++ b/cws/cw05.tex	Wed Dec 21 14:33:05 2022 +0000
@@ -65,11 +65,11 @@
 on my end. You will be marked according to the input files
 
 \begin{itemize}
-\item\href{https://talisker.nms.kcl.ac.uk/cgi-bin/repos.cgi/afl-material/raw-file/tip/cwtests/cw05/sqr.fun}{sqr.fun}  
-\item\href{https://talisker.nms.kcl.ac.uk/cgi-bin/repos.cgi/afl-material/raw-file/tip/cwtests/cw05/fact.fun}{fact.fun}
-\item\href{https://talisker.nms.kcl.ac.uk/cgi-bin/repos.cgi/afl-material/raw-file/tip/cwtests/cw05/mand.fun}{mand.fun}
-\item\href{https://talisker.nms.kcl.ac.uk/cgi-bin/repos.cgi/afl-material/raw-file/tip/cwtests/cw05/mand2.fun}{mand2.fun}
-\item\href{https://talisker.nms.kcl.ac.uk/cgi-bin/repos.cgi/afl-material/raw-file/tip/cwtests/cw05/hanoi.fun}{hanoi.fun}    
+\item\href{https://nms.kcl.ac.uk/christian.urban/cfl/progs/sqr.fun}{sqr.fun}  
+\item\href{https://nms.kcl.ac.uk/christian.urban/cfl/progs/fact.fun}{fact.fun}
+\item\href{https://nms.kcl.ac.uk/christian.urban/cfl/progs/mand.fun}{mand.fun}
+\item\href{https://nms.kcl.ac.uk/christian.urban/cfl/progs/mand2.fun}{mand2.fun}
+\item\href{https://nms.kcl.ac.uk/christian.urban/cfl/progs/hanoi.fun}{hanoi.fun}    
 \end{itemize}  
 
 \noindent
Binary file handouts/ho01.pdf has changed
--- a/handouts/ho01.tex	Fri Dec 09 13:18:10 2022 +0000
+++ b/handouts/ho01.tex	Wed Dec 21 14:33:05 2022 +0000
@@ -46,8 +46,6 @@
 
 \section*{Handout 1}
 
-$\neq$
-
 The purpose of a compiler is to transform a program a human can read and
 write into code machines can run as fast as possible. Developing a
 compiler is an old craft going back to 1952 with the first compiler
--- a/progs/fun/fun_llvm.sc	Fri Dec 09 13:18:10 2022 +0000
+++ b/progs/fun/fun_llvm.sc	Wed Dec 21 14:33:05 2022 +0000
@@ -113,6 +113,14 @@
 def CPSi(e: Exp) = CPS(e)(KReturn)
 
 //some testcases:
+// (1 + 2) * 3
+println(CPSi(Aop("*", Aop("+", Num(1), Num(2)), Num(3))).toString)
+
+// 3 * (1 + 2)
+println(CPSi(Aop("*", Num(3), Aop("+", Num(1), Num(2)))).toString)
+
+//some testcases:
+
 // numbers and vars   
 println(CPSi(Num(1)).toString)
 println(CPSi(Var("z")).toString)
--- a/solutions/cw3/collatz.while	Fri Dec 09 13:18:10 2022 +0000
+++ b/solutions/cw3/collatz.while	Wed Dec 21 14:33:05 2022 +0000
@@ -3,6 +3,6 @@
 while n > 1 do {
   if n % 2 == 0 
   then n := n/2 
-  else n := 3*n+1;
+  else n := 3*n+1
 };
-write "Yes\n";
+write "Yes\n"
--- a/solutions/cw3/factors.while	Fri Dec 09 13:18:10 2022 +0000
+++ b/solutions/cw3/factors.while	Wed Dec 21 14:33:05 2022 +0000
@@ -5,10 +5,7 @@
 read n;
 write "The factors of n are:\n";
 f := 2;
-while n != 1 do {
-    while (n / f) * f == n do {
-        write f; write "\n";
-        n := n / f
-    };
-    f := f + 1
-}
\ No newline at end of file
+while (f < n / 2 + 1) do {
+  if ((n / f) * f == n) then  { write(f); write "\n" } else { skip };
+  f := f + 1
+}
--- a/solutions/cw3/lexer.sc	Fri Dec 09 13:18:10 2022 +0000
+++ b/solutions/cw3/lexer.sc	Wed Dec 21 14:33:05 2022 +0000
@@ -262,5 +262,6 @@
     f := f + 1
 }
 """
-println(tokenise(fact))
 
+//println(tokenise(fact))
+
--- a/solutions/cw3/parser.sc	Fri Dec 09 13:18:10 2022 +0000
+++ b/solutions/cw3/parser.sc	Wed Dec 21 14:33:05 2022 +0000
@@ -159,14 +159,14 @@
 
 // Testing with programs 2 & 3
 
-println("Fibonacci")
-println(Stmts.parse_all(tokenise(os.read(os.pwd / "fib.while"))))
+//println("Fibonacci")
+//println(Stmts.parse_all(tokenise(os.read(os.pwd / "fib.while"))))
 
-println("Loops")
-println(Stmts.parse_all(tokenise(os.read(os.pwd / "loops.while"))))
+//println("Loops")
+//println(Stmts.parse_all(tokenise(os.read(os.pwd / "loops.while"))))
 
-println("Collatz")
-println(Stmts.parse_all(tokenise(os.read(os.pwd / "collatz2.while"))))
+//println("Collatz")
+//println(Stmts.parse_all(tokenise(os.read(os.pwd / "collatz2.while"))))
 
 
 // Interpreter
@@ -226,15 +226,16 @@
 
 def eval(bl: Block) : Env = eval_bl(bl, Map())
 
-println("Primes eval")
-println(tokenise(os.read(os.pwd / "primes.while")))
-println(eval(Stmts.parse_all(tokenise(os.read(os.pwd / "primes.while"))).head))
-
-println("Factors eval")
-println(eval(Stmts.parse_all(tokenise(os.read(os.pwd / "factors.while"))).head))
-
-println("Collatz2 eval")
-println(eval(Stmts.parse_all(tokenise(os.read(os.pwd / "collatz2.while"))).head))
+@main
+def main(file: String) = {
+  val contents = os.read(os.pwd / file)
+  println(s"Lex $file: ")
+  println(tokenise(contents))
+  println(s"Parse $file: ")
+  println(Stmts.parse_all(tokenise(contents)).head)
+  println(s"Eval $file: ")
+  println(eval(Stmts.parse_all(tokenise(contents)).head))
+}
 
 /*
 println("Loops eval")
--- a/solutions/cw4/compiler.sc	Fri Dec 09 13:18:10 2022 +0000
+++ b/solutions/cw4/compiler.sc	Wed Dec 21 14:33:05 2022 +0000
@@ -248,7 +248,7 @@
 write "Result";
 write minus2"""
 
-//compile_all(Stmts.parse_all(tokenise(fibonacciProgram)).head, "fib")
+compile_all(Stmts.parse_all(tokenise(fibonacciProgram)).head, "fib")
 
 val factorialProgram = """write "Factorial";
 read n;