updated
authorChristian Urban <christian.urban@kcl.ac.uk>
Tue, 30 Nov 2021 10:16:47 +0000
changeset 852 8706b846a3e0
parent 851 48539905c447
child 853 568671822d52
updated
cws/cw03.pdf
cws/cw04.pdf
cws/cw04.tex
cwtests/cw03/primes.while
cwtests/cw04/fib.while
progs/lexer/lex.sc
progs/parser-combinators/comb1.sc
slides/slides04.pdf
slides/slides07.pdf
slides/slides07.tex
Binary file cws/cw03.pdf has changed
Binary file cws/cw04.pdf has changed
--- a/cws/cw04.tex	Mon Nov 22 11:35:38 2021 +0000
+++ b/cws/cw04.tex	Tue Nov 30 10:16:47 2021 +0000
@@ -64,8 +64,9 @@
 \texttt{java -jar jasmin-2.4/jasmin.jar loops.j}
 \end{center}
 
-\noindent in order to translate it into Java Byte Code. The
-resulting class file can be run with
+\noindent in order to translate it into Java Byte Code. If needed, you
+need to give the path to the Jasmin jar-file.  The resulting class
+file can be run with
 
 \begin{center}
 \texttt{java loops}
@@ -147,7 +148,7 @@
 a file that can be run, not as PDF-text.
 
 \begin{figure}[t]
-\lstinputlisting[language=while]{../progs/while-tests/fib.while}
+\lstinputlisting[language=while]{../cwtests/cw04/fib.while}
 \caption{The Fibonacci program in the WHILE language.\label{fibs}}
 \end{figure}
 
--- a/cwtests/cw03/primes.while	Mon Nov 22 11:35:38 2021 +0000
+++ b/cwtests/cw03/primes.while	Tue Nov 30 10:16:47 2021 +0000
@@ -9,6 +9,6 @@
     if ((n / f) * f == n) then  { tmp := 1 } else { skip };
     f := f + 1
   };
-  if (tmp == 0) then { write(n) } else { skip };
+  if (tmp == 0) then { write(n); write("\n") } else { skip };
   n  := n + 1
 }
\ No newline at end of file
--- a/cwtests/cw04/fib.while	Mon Nov 22 11:35:38 2021 +0000
+++ b/cwtests/cw04/fib.while	Tue Nov 30 10:16:47 2021 +0000
@@ -3,10 +3,10 @@
 minus1 := 0;
 minus2 := 1;
 while n > 0 do {
-temp := minus2;
-minus2 := minus1 + minus2;
-minus1 := temp;
-n := n - 1
+  temp := minus2;
+  minus2 := minus1 + minus2;
+  minus1 := temp;
+  n := n - 1
 };
 write "Result";
 write minus2
--- a/progs/lexer/lex.sc	Mon Nov 22 11:35:38 2021 +0000
+++ b/progs/lexer/lex.sc	Tue Nov 30 10:16:47 2021 +0000
@@ -138,6 +138,9 @@
 def lexing(r: Rexp, s: String) = 
   env(lex(r, s.toList))
 
+println(lex(("ab" | "a") ~ (ONE | "b"), "ab".toList))
+
+println(lex(STAR("aa" | "a"), "aaa".toList))
 
 // The Lexing Rules for the WHILE Language
 
--- a/progs/parser-combinators/comb1.sc	Mon Nov 22 11:35:38 2021 +0000
+++ b/progs/parser-combinators/comb1.sc	Tue Nov 30 10:16:47 2021 +0000
@@ -13,7 +13,7 @@
 type IsSeq[A] = A => Seq[_]
 
 abstract class Parser[I : IsSeq, T]{
-  def parse(in: I): Set[(T, I)]
+  def parse(in: I): Set[(T, I)]  
 
   def parse_all(in: I) : Set[T] =
     for ((hd, tl) <- parse(in); 
Binary file slides/slides04.pdf has changed
Binary file slides/slides07.pdf has changed
--- a/slides/slides07.tex	Mon Nov 22 11:35:38 2021 +0000
+++ b/slides/slides07.tex	Tue Nov 30 10:16:47 2021 +0000
@@ -37,6 +37,43 @@
       {\footnotesize\rowcolors{1}{capri!10}{white}
         \begin{tabular}{|p{4.8cm}|p{4.8cm}|}\hline
           1 Introduction, Languages          & 6 While-Language \\
+          2 Regular Expressions, Derivatives & 7 Compilation, JVM \\
+          3 Automata, Regular Languages      & \cellcolor{blue!50} 8 Compiling Functional Languages \\
+          4 Lexing, Tokenising               & 9 Optimisations \\
+          5 Grammars, Parsing                & 10 LLVM \\ \hline
+        \end{tabular}%
+      };
+    \end{tikzpicture}
+  \end{center}
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{frame}[t]
+\frametitle{%
+  \begin{tabular}{@ {}c@ {}}
+  \\[-3mm]
+  \LARGE Compilers and \\[-2mm] 
+  \LARGE Formal Languages\\[3mm] 
+  \end{tabular}}
+
+  \normalsize
+  \begin{center}
+  \begin{tabular}{ll}
+    Email:  & christian.urban at kcl.ac.uk\\
+    %Office Hours: & Thursdays 12 -- 14\\
+    %Location: & N7.07 (North Wing, Bush House)\\
+    Slides \& Progs: & KEATS (also homework is there)\\  
+  \end{tabular}
+  \end{center}
+
+  \begin{center}
+    \begin{tikzpicture}
+      \node[drop shadow,fill=white,inner sep=0pt] 
+      {\footnotesize\rowcolors{1}{capri!10}{white}
+        \begin{tabular}{|p{4.8cm}|p{4.8cm}|}\hline
+          1 Introduction, Languages          & 6 While-Language \\
           2 Regular Expressions, Derivatives & \cellcolor{blue!50} 7 Compilation, JVM \\
           3 Automata, Regular Languages      & 8 Compiling Functional Languages \\
           4 Lexing, Tokenising               & 9 Optimisations \\
@@ -1037,6 +1074,72 @@
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 
 
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{frame}[t, fragile]
+\frametitle{Function Definitions}
+
+\footnotesize
+\begin{lstlisting}[language=JVMIS, 
+                   xleftmargin=2mm, 
+                   numbers=none]
+.method public static write(I)V 
+   .limit locals 1
+   .limit stack 2
+   getstatic java/lang/System/out Ljava/io/PrintStream; 
+   iload 0 
+   invokevirtual java/io/PrintStream/println(I)V 
+   return 
+.end method
+\end{lstlisting}\bigskip
+
+\small We will need methods for definitions like\footnotesize\medskip
+
+\begin{lstlisting}[language=JVMIS, 
+                   xleftmargin=2mm, 
+                   numbers=none]
+def fname (x1, ... , xn) = ...                   
+                   
+.method public static fname (I...I)I
+  .limit locals ??
+  .limit stack ?? 
+  ??
+.end method
+\end{lstlisting}
+
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{frame}[c, fragile]
+\frametitle{Stack Estimation}
+\small
+\mbox{}\\[-15mm]
+
+\bl{\begin{center}
+\begin{tabular}{@{\hspace{-4mm}}l@{\hspace{2mm}}c@{\hspace{2mm}}l@{}}
+$\textit{estimate}(n)$ & $\dn$ & $1$\\
+$\textit{estimate}(x)$ & $\dn$ & $1$\\
+$\textit{estimate}(a_1\;aop\;a_2)$ & $\dn$ &
+$\textit{estimate}(a_1) + \textit{estimate}(a_2)$\\
+$\textit{estimate}(\pcode{if}\;b\;\pcode{then}\;e_1\;\pcode{else}\;e_2)$ & $\dn$ & 
+$\textit{estimate}(b) +$\\ 
+& & $\quad max(\textit{estimate}(e_1), \textit{estimate}(e_2))$\\
+$\textit{estimate}(\pcode{write}(e))$ & $\dn$ & 
+$\textit{estimate}(e) + 1$\\
+$\textit{estimate}(e_1 ; e_2)$ & $\dn$ & 
+$max(\textit{estimate}(e_1), \textit{estimate}(e_2))$\\
+$\textit{estimate}(f(e_1, ..., e_n))$ & $\dn$ & 
+$\sum_{i = 1..n}\;estimate(e_i)$\medskip\\
+$\textit{estimate}(a_1\;bop\;a_2)$ & $\dn$ &
+$\textit{estimate}(a_1) + \textit{estimate}(a_2)$\\
+\end{tabular}
+\end{center}}
+
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
+
+
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \mode<presentation>{
 \begin{frame}[c]