updated
authorChristian Urban <christian.urban@kcl.ac.uk>
Sat, 21 Oct 2023 09:09:09 +0100
changeset 943 5365ef60707e
parent 942 c82a45f48bfc
child 944 f5d2453c5640
updated
cws/cw01.pdf
cws/cw02.pdf
cws/cw02.tex
cws/cw03.pdf
cws/cw03.tex
cws/cw04.pdf
cws/cw04.tex
cws/cw05.pdf
cws/cw05.tex
handouts/ho07.pdf
handouts/ho07.tex
handouts/ho08.pdf
hws/Der.pdf
hws/Der.tex
hws/hw01.pdf
hws/hw02.pdf
hws/hw03.pdf
hws/hw03.tex
hws/hw04.pdf
hws/hw04.tex
hws/hw05.pdf
hws/hw06.pdf
hws/hw07.pdf
hws/hw08.pdf
hws/hw09.pdf
hws/upload
progs/lexer/lexer.sc
progs/while-arrays/compile_arrays.sc
progs/while-arrays/compile_arrays2.sc
progs/while-arrays/compile_bfc.sc
progs/while/compile.sc
slides/build.sc
slides/slides01.pdf
slides/slides02.pdf
slides/slides03.pdf
slides/slides04.pdf
slides/slides04.tex
slides/slides05.pdf
slides/slides06.pdf
slides/slides07.pdf
slides/slides08.pdf
slides/slides09.pdf
slides/slides10.pdf
solutions/cw5/out.png
Binary file cws/cw01.pdf has changed
Binary file cws/cw02.pdf has changed
--- a/cws/cw02.tex	Fri Oct 13 23:49:34 2023 +0100
+++ b/cws/cw02.tex	Sat Oct 21 09:09:09 2023 +0100
@@ -13,11 +13,12 @@
 WHILE language. You can do the implementation in any programming
 language you like, but you need to submit the source code with which
 you answered the questions, otherwise a mark of 0\% will be
-awarded. You need to submit your written
-answers as pdf---see attached questionaire.  Code send as code. If you use
-Scala in your code, a good place to start is the file \texttt{lexer.sc}
-and \texttt{token.sc}
-that are uploaded to Github.
+awarded. You need to submit your written answers as pdf---see attached
+questionaire.  Code send as code. If you use Scala in your code, a
+good place to start is the file \texttt{lexer.sc} and
+\texttt{token.sc} uploaded to KEATS. The template file on Github is
+called \texttt{cw02.sc}. Your code needs to be uploaded to Github by
+the deadline.
 
 \subsection*{Disclaimer\alert}
 
Binary file cws/cw03.pdf has changed
--- a/cws/cw03.tex	Fri Oct 13 23:49:34 2023 +0100
+++ b/cws/cw03.tex	Sat Oct 21 09:09:09 2023 +0100
@@ -15,8 +15,7 @@
 language you like, but you need to submit the source code with which
 you answered the questions, otherwise a mark of 0\% will be
 awarded. You should use the lexer from the previous coursework for the
-parser.  Please package everything(!) in a zip-file that creates a
-directory with the name \texttt{YournameYourFamilyname} on my end.
+parser.  Please submit your code to Github by the deadline.
 
 \subsection*{Disclaimer\alert}
 
@@ -162,6 +161,40 @@
 \caption{Collatz series program.\label{collatz}}
 \end{figure}
 
+\clearpage
+\newpage
+\section*{Answers}
+
+\noindent
+\textbf{Question 1 (Grammar):}\\
+
+\mbox{}\\[9cm]
+
+\noindent
+\textbf{Question 2 (Prase Tree):}\\
+
+\mbox{}\\[8cm]
+
+
+\noindent
+\textbf{Question 3 (Timings):}\\
+
+\begin{center}
+  \def\arraystretch{1.5}
+  \begin{tabular}{l|l}
+    n & secs\\
+    \hline
+    100 & \\
+    500 & \\
+    700 & \\
+    1000 & \\
+    \\
+    \\
+    \\
+    \\
+   \end{tabular} 
+\end{center}  
+
 \end{document}
 
 %%% Local Variables: 
Binary file cws/cw04.pdf has changed
--- a/cws/cw04.tex	Fri Oct 13 23:49:34 2023 +0100
+++ b/cws/cw04.tex	Sat Oct 21 09:09:09 2023 +0100
@@ -237,8 +237,8 @@
 
 \subsection*{Question 4}
 
-Extend the lexer and parser to add a \texttt{break} keyword.  Modify
-the compiler such that when a \texttt{break}-statement is encountered
+Extend the lexer and parser to add a \textcolor{codepurple}{\pcode{break}} keyword.  Modify
+the compiler (including lexer and parser) such that when a \textcolor{codepurple}{\texttt{break}}-statement is encountered
 the code should jump out of the ``enclosing'' for-loop, or in case it
 is not inside a for-loop to the end of the program. For example the
 program
@@ -246,11 +246,13 @@
 \begin{center}
 \begin{minipage}{12cm}
 \begin{lstlisting}[language=While, numbers=none]
+// should print 0 .. 10    
 for i := 0 upto 10 do {
   write i;
   write "\n"
 };
 
+// should print 0 .. 4  
 for i := 0 upto 10 do {
   if i > 4 then break else skip;
   write i;
Binary file cws/cw05.pdf has changed
--- a/cws/cw05.tex	Fri Oct 13 23:49:34 2023 +0100
+++ b/cws/cw05.tex	Sat Oct 21 09:09:09 2023 +0100
@@ -165,7 +165,7 @@
 \end{figure}
 
 \begin{figure}[t]
-\includegraphics[scale=0.35]{../solution/cw5/out.png}
+\includegraphics[scale=0.35]{../solutions/cw5/out.png}
 \caption{Ascii output of the Mandelbrot program.\label{mand2}}
 \end{figure}
 
Binary file handouts/ho07.pdf has changed
--- a/handouts/ho07.tex	Fri Oct 13 23:49:34 2023 +0100
+++ b/handouts/ho07.tex	Sat Oct 21 09:09:09 2023 +0100
@@ -91,7 +91,7 @@
 \noindent The first instruction loads the constant $1$ onto the stack,
 the next one loads $2$, the third instruction adds both numbers together
 replacing the top two elements of the stack with the result $3$. For
-simplicity, we will consider throughout only arithmetic involving
+simplicity, we will consider only arithmetic operations involving
 integer numbers. This means our main JVM instructions for arithmetic
 will be \instr{iadd}, \instr{isub}, \instr{imul}, \instr{idiv} and so on.
 The \code{i} stands for integer instructions in the JVM (alternatives
@@ -341,7 +341,7 @@
 unconditional, meaning we always have to jump to the end of
 $cs_2$. The corresponding instruction of the JVM is
 \instr{goto}. In case $b$ turns out to be false we need the
-control-flow
+control-flow to be:
 
 \begin{center}
 \begin{tikzpicture}[node distance=2mm and 4mm,line cap=round,
@@ -476,7 +476,7 @@
 if-statement:
 
 \begin{lstlisting}[mathescape,numbers=none,language=While]
-if 1 = 1 then x := 2 else y := 3
+if 1 == 1 then x := 2 else y := 3
 \end{lstlisting}
 
 \noindent 
@@ -503,7 +503,7 @@
 \end{tikzpicture}
 
 \noindent The first three lines correspond to the the boolean
-expression $1 = 1$. The jump for when this boolean expression
+expression \texttt{1 == 1}. The jump for when this boolean expression
 is false is in Line~3. Lines 4-6 corresponds to the if-branch;
 the else-branch is in Lines 8 and 9. 
 
@@ -642,23 +642,24 @@
 void). Since the method has only one argument, we only need a single
 local variable (Line~2) and a stack with two cells will be sufficient
 (Line 3). Line 4 instructs the JVM to get the value of the member
-\pcode{out} from the class \pcode{java/lang/System}. It expects the value
-to be of type \pcode{java/io/PrintStream}. A reference to this value
-will be placed on the stack.\footnote{Note the syntax \texttt{L
-\ldots{};} for the \texttt{PrintStream} type is not an typo. Somehow the
-designers of Jasmin decided that this syntax is pleasing to the eye. So
-if you wanted to have strings in your Jasmin code, you would need to
-write \texttt{Ljava/lang/String;}\;. If you want arrays of one
-dimension, then use \texttt{[\ldots}; two dimensions, use
-\texttt{[[\ldots} and so on. Looks all very ugly to my eyes.} Line~5
-copies the integer we want to print out onto the stack. In the line
-after that we call the method \pcode{println} (from the class
-\pcode{java/io/PrintStream}). We want to print out an integer and do not
-expect anything back (that is why the type annotation is \pcode{(I)V}).
-The \pcode{return}-instruction in the next line changes the control-flow
-back to the place from where \pcode{write} was called. This method needs
-to be part of a header that is included in any code we generate. The
-helper-method \pcode{write} can be invoked with the two instructions
+\pcode{out} from the class \pcode{java/lang/System}. It expects the
+value to be of type \pcode{java/io/PrintStream}. A reference to this
+value will be placed on the stack.\footnote{Note the syntax
+  \texttt{Ljava\ldots{};} for the \texttt{PrintStream} type is not an
+  typo. Somehow the designers of Jasmin decided that this syntax is
+  pleasing to the eye. So if you wanted to have strings in your Jasmin
+  code, you would need to write \texttt{Ljava/lang/String;}\;. If you
+  want arrays of one dimension, then use \texttt{[\ldots}; two
+  dimensions, use \texttt{[[\ldots} and so on. Looks all very ugly to
+  my eyes.} Line~5 copies the integer we want to print out onto the
+stack. In the line after that we call the method \pcode{println} (from
+the class \pcode{java/io/PrintStream}). We want to print out an
+integer and do not expect anything back (that is why the type
+annotation is \pcode{(I)V}).  The \pcode{return}-instruction in the
+next line changes the control-flow back to the place from where
+\pcode{write} was called. This method needs to be part of a header
+that is included in any code we generate. The helper-method
+\pcode{write} can be invoked with the two instructions
 
 \begin{lstlisting}[mathescape,language=JVMIS]
 iload $E(x)$ 
@@ -745,11 +746,11 @@
 section let us have a look at how we can support the following three
 constructions
 
-\begin{lstlisting}[mathescape,language=While]
-new(arr[15000])
-x := 3 + arr[3 + y]
-arr[42 * n] := ...
-\end{lstlisting}
+\begin{itemize}
+\item \lstinline|new(arr[15000])|
+\item \lstinline|x := 3 + arr[3 + y]|
+\item \lstinline|arr[42 * n] := ...|
+\end{itemize}  
 
 \noindent
 The first construct is for creating new arrays. In this instance the
Binary file handouts/ho08.pdf has changed
Binary file hws/Der.pdf has changed
--- a/hws/Der.tex	Fri Oct 13 23:49:34 2023 +0100
+++ b/hws/Der.tex	Sat Oct 21 09:09:09 2023 +0100
@@ -25,7 +25,7 @@
 \noindent
 where $\Sigma^*$ is in our case the set of all strings (what follows
 also holds for any kind of ``domain'', like the set of all integers or
-set of all binary trees, etc). Let us assume $P(s)$ is a property that
+the set of all binary trees, etc). Let us assume $P(s)$ is a property that
 is about strings, for example $P(s)$ could be ``the string $s$ has
 an even length'', or ``the string $s$ starts with the letter
 \texttt{a}''. Every such property carves out a subset of strings from
@@ -42,8 +42,8 @@
 would be outside the grey area where $\neg P(s)$ holds. Notice that
 sometimes the property $P(s)$ holds for every string in
 $\Sigma^*$. Then the grey area would fill out the whole rectangle and
-the set where $\neg P(s)$ holds is empty. Similarly, the property $P(s)$
-holds for no string in which case the grey circle is empty.
+the set where $\neg P(s)$ holds is empty. Similarly, if the property $P(s)$
+holds for no string, then the grey circle is empty.
 
 Now, we are looking for the complement of the set defined in \eqref{set}.
 This complement set is often written as
@@ -55,7 +55,7 @@
 \noindent
 It is the area of $\Sigma^*$ which isn't grey, that is $\Sigma^*$
 minus $\{s \in \Sigma^*\;|\; P(s) \}$, \textbf{or} written differently
-it is the set $\{s \in \Sigma^*\;|\; \neg P(s) \}$. That means it the
+it is the set $\{s \in \Sigma^*\;|\; \neg P(s) \}$. That means it is the
 set of all the strings where $\neg P(s)$ holds. Consequently we have
 for any complement set the equation:
 
@@ -63,7 +63,7 @@
 \overline{\{s \in \Sigma^*\;|\; P(s) \}} = \{s \in \Sigma^*\;|\; \neg P(s) \}
 \end{equation}
 
-\section*{Semantic derivative}
+\section*{Semantic Derivative}
 
 Our semantic derivative $Der\;c\;A$ is nothing else than a property that defines
 a subset of strings (inside $\Sigma^*$). The corresponding
@@ -75,7 +75,7 @@
 
 \noindent
 That means $Der\;c\;A$ is some grey area inside $\Sigma^*$. Obviously
-which subset, or grey area, we are carving out from $\Sigma^*$ depends on what we
+which subset, or which grey area, we are carving out from $\Sigma^*$ depends on what we
 choose for $c$ and $A$.\bigskip
 
 
@@ -119,10 +119,10 @@
 \noindent
 This can be calculated by ``subtracting'' $\{[aa], [bb], [a]\}$ from
 $\Sigma^*$. I let you check whether I did this correctly.  According
-to the equation in \eqref{eq} this should be equal to
+to the equation in \eqref{eq} this should also be equal to
 
 \[
-\overline{Der\;a\;A} = \{s \in \Sigma^*\;|\;a::s\not\in A\}
+\overline{Der\;a\;A} = \{s \in \Sigma^*\;|\;\neg(a::s\in A)\}
 \]  
 
 \noindent Let us test in turn every string in $\Sigma^*$ and see
@@ -131,13 +131,14 @@
 \[\{[aaa], [abb], [aa], [bb], []\}\]
 
 \noindent
-This gives rise to the following table where in the first column are
+This gives rise to the following table where in the first column are all
 the strings of $\Sigma^*$ and in the second whether $a::s \in A$ holds. The third column
-is the negated version of the second.
+is the negated version of the second, namely $\neg(a::s\in A)$ which is the same as
+$a::s\not\in A$.
 
 \begin{center}
 \begin{tabular}{r|c|l}
-  s & is $a::s \in A$? & $\neg(a::s \in A) \Leftrightarrow  a::s \not\in A$\\
+  $s\in\Sigma^*$ & is $a::s \in A$? & $\neg(a::s \in A) \Leftrightarrow  a::s \not\in A$\\
   \hline
   $[]$    & no & yes\\
   $[a]$   & yes& no\\
@@ -158,7 +159,78 @@
 \end{center}
 
 \noindent
-Collecting all the yes in the third row gives you the set in \eqref{Der}. So it works out in this example.
+Collecting all the yes in the third column gives you the set in
+\eqref{Der}. So it works out in this example. The idea is that this always works out. ;o)
+\bigskip
+
+\noindent
+BTW, notice that all three properties are the same
+
+\[
+  \neg(a::s \in A) \quad\Leftrightarrow\quad  a::s \not\in A
+  \quad\Leftrightarrow\quad a::s \in \overline{A}
+\]  
+
+\noindent
+This means we have
+
+\begin{equation}\label{D}
+\overline{Der\;a\;A} = Der\;a\;\overline{A}
+\end{equation}
+
+\noindent
+I let you check whether this makes sense.
+
+\section*{Not-Regular Expression}
+
+With the equation in \eqref{D} we can also very quickly verify that the
+$der$-definition for the not-regular expression satisfies the property
+of derivatives, namely
+
+\begin{equation}\label{derprop}
+\forall c\,r.\;\;\;L(der\;c\;r) = Der\;c\;(L(r))
+\end{equation}
+
+\noindent
+holds. We defined the language of a not-regular expression as
+
+\[
+L(\sim r) \;\dn\; \Sigma^* - L(r)
+\]  
+
+\noindent
+Using the overline notation, maybe I should have defined this equivalently as
+
+\[
+L(\sim r) \;\dn\; \overline{L(r)}
+\] 
+
+\noindent
+meaning all the strings that $r$ \emph{cannot} match. We defined the derivative for
+the not-regular expression as
+
+\[
+der\;c\;(\sim r) \;\dn\; \sim(der\;c\;r)
+\]  
+
+\noindent
+The big question is now does this definition satisfy the property in
+\eqref{derprop}? Lets see: We would have to prove this by induction on regular
+expressions. When we are in the case for $\sim r$ the reasoning is as follows:
+
+\begin{center}
+  \def\arraystretch{1.5}
+\begin{tabular}{llll}
+  $L(der\;c\;(\sim r))$ & $\dn$ & $L(\sim (der\;c\;r))$ & by definition of $der$\\
+                        & $\dn$ & $\overline{L(der\;c\;r)}$ & by definition of $L$\\
+                        & $=$ & $\overline{Der\;c\;(L(r))}$ & by IH\\
+                        & $=$ & $Der\;c\;\overline{(L(r))}$ & by \eqref{D}\\
+                        & $\dn$ & $Der\;c\;(L(\sim r))$ & by definition of $L$\\
+\end{tabular}    
+\end{center}
+
+\noindent
+That means we have established the property of derivatives in the $\sim r$-case\dots{}yippee~;o)
 
 \end{document}
 
Binary file hws/hw01.pdf has changed
Binary file hws/hw02.pdf has changed
Binary file hws/hw03.pdf has changed
--- a/hws/hw03.tex	Fri Oct 13 23:49:34 2023 +0100
+++ b/hws/hw03.tex	Sat Oct 21 09:09:09 2023 +0100
@@ -97,7 +97,7 @@
 
         \[
           \hat{\rho}(qs, []) \dn qs \qquad
-          \hat{\rho}(qs, c::s) \dn \bigcup_{q\in qs} \{ q' \; | \; \rho(q, c, q')\}
+          \hat{\rho}(qs, c::s) \dn \bigcup_{q\in qs} \hat{\rho}(\{ q' \; | \; \rho(q, c, q')\}, s)
         \]
 
         This ``collects'' all the states reachable in a breadth-first
Binary file hws/hw04.pdf has changed
--- a/hws/hw04.tex	Fri Oct 13 23:49:34 2023 +0100
+++ b/hws/hw04.tex	Sat Oct 21 09:09:09 2023 +0100
@@ -22,13 +22,49 @@
 there are several values for how these regular expressions can
 recognise the strings (for 1) $ab$ and (for 2) $aaa$. Give in each case
 \emph{all} the values and indicate which one is the POSIX value.
+
+\solution{
+  1) There are only 2 values (writing $a$ for $Char(a)$ and so on)
+
+  \begin{center}
+  \begin{tabular}{l}
+    $Sequ(Left(Sequ(a,b)),Left(Empty))$\\
+    $Sequ(Right(a),Left(b))$\\ 
+  \end{tabular}    
+  \end{center}
   
+  The first is the POSIX value because of the preference for $Left$.
+
+  2) There are three ``main'' values, namely
+
+  \begin{center}
+  \begin{tabular}{l}
+    $Stars\,[Left(Sequ(a,a)),Right(a)]$\\
+    $Stars\,[Right(a), Left(Sequ(a,a))]$\\
+    $Stars\,[Right(a), Right(a), Right(a)]$\\
+  \end{tabular}    
+  \end{center}
+
+  Again the first one is the POSIX value, but if it just about all
+  possible values, then there are in fact infinitely many values because
+  the following 
+
+  \begin{center}
+  \begin{tabular}{l}
+    $Stars\,[Left(Sequ(a,a)),Empty,Right(a)]$\\
+    $Stars\,[Left(Sequ(a,a)),Empty,Empty,Right(a)]$\\
+    $Stars\,[Left(Sequ(a,a)),Empty,Right(a), Empty]$, \ldots\\
+  \end{tabular}    
+  \end{center}
+
+  are also values for this regex and the string $aaa$.
+}  
 
 \item If a regular expression $r$ does not contain any occurrence of $\ZERO$,  
   is it possible for $L(r)$ to be empty? Explain why, or give a proof.
 
   \solution{
-    The property to prove is
+    No. The property to prove by induction is
 
     \begin{center}
     $P(r)$: If $r$ does not contain $\ZERO$, then $L(r) \not= \emptyset$.  
@@ -76,6 +112,10 @@
   In case they can, can you give the corresponding token
   sequences.
 
+  \solution{
+  The first 2 are lexibile. The 3 one contains $/$ which is not an operator.
+  }  
+
 \item Assume $r$ is nullable. Show that
   \[ 1 + r + r\cdot r \;\equiv\; r\cdot r
   \]
@@ -128,8 +168,8 @@
   password should be at least 8 characters long and consist of upper-
   and lower-case letters and digits. It should contain at least a
   single lower-case letter, at least a single upper-case letter and at
-  least a single digit. If possible ise the intersection regular
-  expression from CW1, written $\_\&\_$, the bounded regular
+  least a single digit. If possible use the intersection regular
+  expression from CW1, written $\_\&\_$, and the bounded regular
   expressions; you can also assume a regular expression written
   \texttt{ALL} that can match any character.
 
@@ -144,6 +184,8 @@
                    & \;\&\; & $(ALL^*\cdot [0-9]\cdot ALL^*)$\\
   \end{tabular}
   \end{center}
+
+  $ALL$ could be represented as $\sim \ZERO$.
   }
   
 \item Assume the delimiters for comments are
@@ -161,7 +203,13 @@
       that can recognise any character, and a regular
       expression \texttt{NOT} that recognises the complement
       of a regular expression.)
-  
+
+      \solution{
+        \[/ * \sim (ALL^* * / ALL^*) * /\]
+
+      The idea to make sure in between $/ *$ and $* /$ ar no strings that contain $* /$.  
+      }
+      
 \item Simplify the regular expression
 
 \[
@@ -170,7 +218,12 @@
 \]
 
       Does simplification always preserve the meaning of a
-      regular expression? 
+      regular expression?
+
+      \solution{ Yes, simplification preserves the language. It
+        simplifies to just $\ONE$. It should be remembered that the
+        Brzozowski does not simplify under stars. This does not apply
+        in this example, though.  }
      
 \item The Sulzmann \& Lu algorithm contains the function
       $mkeps$ which answers how a regular expression can match
@@ -184,10 +237,28 @@
     (a + \ONE) \cdot (\ONE + \ONE)\\
     a^*
   \end{array}
-  \]
+\]
+
+\solution{
+  The values are
+  \begin{center}
+  \begin{tabular}{l}
+    $Right(Right(Empty))$\\
+    $Sequ(Right(\ONE),Left(\ONE))$\\
+    $Stars\,[]$
+  \end{tabular}  
+  \end{center}
+
+  The last one uses the rule that $mkeps$ for the star returns always $Star\,[]$.
+  }
 
 \item What is the purpose of the record regular expression in
-      the Sulzmann \& Lu algorithm?
+  the Sulzmann \& Lu algorithm?
+
+  \solution{
+    It marks a part of a regular expression and can be used to extract the part of the
+    string that is matched by this marked part of the regular expression.
+  }
 
 \item Recall the functions \textit{nullable} and
       \textit{zeroable}.  Define recursive functions
@@ -252,7 +323,7 @@
           i(r^*)  &\dn \neg a(r)
         \end{align}
 
-        Here the interesting bit is that as soon $r$ can match at least a single string, then $r^*$
+        Here the interesting bit is that as soon $r$ can match at least a single non-empty string, then $r^*$
         will match infinitely many strings.
         }
 
@@ -264,6 +335,15 @@
   engines like the one in Rust generate DFAs. Explain what is the
   problem with these regex engines and also what is the problem with $a^{\{1000\}}$
   in these engines.
+
+  \solution{
+    Why they use NFAs? NFAs are of similar size as the regular expression (they do not explode
+    for the basic regular expressions. Python regex library supports constructions like
+    back-refernces which cannot be represented by DFAs (string matching with back-references
+    can be NP. What is the problem with $a^{\{1000\}}$. When generating DFAs (and NFAs) for the
+    bounded regular expressions, one has to make $n$ copies, which means their size can grow
+    drastically for large counters.
+  }
       
 %\item (Optional) The tokenizer in \texttt{regexp3.scala} takes as
 %argument a string and a list of rules. The result is a list of tokens. Improve this tokenizer so 
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
--- a/hws/upload	Fri Oct 13 23:49:34 2023 +0100
+++ b/hws/upload	Sat Oct 21 09:09:09 2023 +0100
@@ -9,7 +9,8 @@
 	hw06.pdf
 	hw07.pdf
 	hw08.pdf
-	hw09.pdf"} 
+	hw09.pdf
+        Der.pdf"} 
 
 for f in $fls; do
     echo -e "uploading $f"
--- a/progs/lexer/lexer.sc	Fri Oct 13 23:49:34 2023 +0100
+++ b/progs/lexer/lexer.sc	Sat Oct 21 09:09:09 2023 +0100
@@ -42,12 +42,6 @@
 implicit def string2rexp(s : String) : Rexp = 
   charlist2rexp(s.toList)
 
-extension (r: Rexp) {
-  def | (s: Rexp) = ALT(r, s)
-  def % = STAR(r)
-  def ~ (s: Rexp) = SEQ(r, s)
-}
-
 extension (s: String) {
   def | (r: Rexp) = ALT(s, r)
   def | (r: String) = ALT(s, r)
@@ -57,6 +51,17 @@
   def $ (r: Rexp) = RECD(s, r)
 }
 
+extension (r: Rexp) {
+  def | (s: Rexp) = ALT(r, s)
+  def % = STAR(r)
+  def ~ (s: Rexp) = SEQ(r, s)
+}
+
+
+
+val r : Rexp = ("a" | "b").% 
+println(r) 
+
 def nullable(r: Rexp) : Boolean = r match {
   case ZERO => false
   case ONE => true
@@ -79,6 +84,7 @@
   case RECD(_, r1) => der(c, r1)
 }
 
+println(der('a', ALT(STAR("a"), "b")))
 
 // extracts a string from a value
 def flatten(v: Val) : String = v match {
@@ -128,6 +134,8 @@
   case (RECD(x, r1), _) => Rec(x, inj(r1, c, v))
 }
 
+
+
 // some "rectification" functions for simplification
 def F_ID(v: Val): Val = v
 def F_RIGHT(f: Val => Val) = (v:Val) => Right(f(v))
--- a/progs/while-arrays/compile_arrays.sc	Fri Oct 13 23:49:34 2023 +0100
+++ b/progs/while-arrays/compile_arrays.sc	Sat Oct 21 09:09:09 2023 +0100
@@ -88,11 +88,12 @@
 // convenient string interpolations 
 // for generating instructions and labels
 
-implicit def sring_inters(sc: StringContext) = new {
+extension (sc: StringContext) {
     def i(args: Any*): String = "   " ++ sc.s(args:_*) ++ "\n"
     def l(args: Any*): String = sc.s(args:_*) ++ ":\n"
 }
 
+
 def compile_op(op: String) = op match {
   case "+" => i"iadd"
   case "-" => i"isub"
@@ -215,14 +216,8 @@
 
 // automating the above
 
-// pre-2.5.0 ammonite 
-// import ammonite.ops._
-
-// post 2.5.0 ammonite
 import os._
 
-
-
 def compile_to_file(bl: Block, class_name: String) : Unit = 
   write.over(pwd / s"$class_name.j", compile(bl, class_name))  
 
@@ -246,5 +241,4 @@
 
 
 
-// runs with amm2 and amm3
 
--- a/progs/while-arrays/compile_arrays2.sc	Fri Oct 13 23:49:34 2023 +0100
+++ b/progs/while-arrays/compile_arrays2.sc	Sat Oct 21 09:09:09 2023 +0100
@@ -1,5 +1,8 @@
 // A Small Compiler for the WHILE Language
 //
+// - there are some small peep-hole optimisations
+//   implemented
+//
 // - this compiler contains support for "static" integer 
 //   arrays (they are mutable but cannot be re-sized)
 //
@@ -88,11 +91,12 @@
 // convenient string interpolations 
 // for generating instructions and labels
 
-implicit def sring_inters(sc: StringContext) = new {
+extension (sc: StringContext) {
     def i(args: Any*): String = "   " ++ sc.s(args:_*) ++ "\n"
     def l(args: Any*): String = sc.s(args:_*) ++ ":\n"
 }
 
+
 def compile_num(i: Int) = 
   if (0 <= i && i <= 5) i"iconst_$i" else 
   if (-128 <= i && i <= 127) i"bipush $i" else i"ldc $i"
@@ -262,5 +266,3 @@
 
 
 
-
-// runs with amm2 and amm3
--- a/progs/while-arrays/compile_bfc.sc	Fri Oct 13 23:49:34 2023 +0100
+++ b/progs/while-arrays/compile_bfc.sc	Sat Oct 21 09:09:09 2023 +0100
@@ -92,33 +92,37 @@
 // Grammar Rules for WHILE with arrays
 //=====================================
 
+import $ivy.`com.lihaoyi::fastparse:3.0.2`
 import fastparse._
 import MultiLineWhitespace._
 
-def lowercase [_ : P] = P( CharIn("a-z") )
-def uppercase[_ : P]  = P( CharIn("A-Z") )
-def letter[_ : P]     = P( lowercase | uppercase )
-def digit [_ : P]     = P( CharIn("0-9") )
+def string[A: P]: P[String]   = P(CharIn("a-zA-Z0-9").rep(1).!)
 
-def Number[_ : P]: P[Int] =  P( digit.rep(1) ).!.map(_.toInt)
-def Ident[_ : P]: P[String] = P( letter ~ (letter | digit | "_").rep ).!
+/*
+def lowercase [$ : P] = P( CharIn("a-z") )
+def uppercase[$ : P]  = P( CharIn("A-Z") )
+def letter[$ : P]     = P( lowercase | uppercase )
+def digit [$ : P]     = P( CharIn("0-9") )
+
+def Number[$ : P]: P[Int] =  P( digit.rep(1) ).!.map(_.toInt)
+def Ident[$ : P]: P[String] = P( letter ~ (letter | digit | "_").rep ).!
 
 // arithmetic expressions
-def AExp[_ : P]: P[AExp] = 
+def AExp[$ : P]: P[AExp] = 
   P(  P(Te ~ "+" ~ AExp).map{ case (l, r) => Aop("+", l, r)} 
     | P(Te ~ "-" ~ AExp).map{ case (l, r) => Aop("-", l, r)}
     | Te )
-def Te[_ : P]: P[AExp] = 
+def Te[$ : P]: P[AExp] = 
   P(  P(Fa ~ "*" ~ Te).map{ case (l, r) => Aop("*", l, r)} 
     | Fa )   
-def Fa[_ : P]: P[AExp] = 
+def Fa[$ : P]: P[AExp] = 
   P( "(" ~ AExp ~ ")" 
      | P (Ident ~ "[" ~ AExp ~ "]").map{Ref.tupled}
      | P(Number).map{Num} 
      | P(Ident).map{Var} )
 
 // boolean expressions
-def BExp[_ : P]: P[BExp] = 
+def BExp[$ : P]: P[BExp] = 
   P(  P(AExp ~ "=" ~ AExp).map{ case (x, z) => Bop("=", x, z)} 
     | P(AExp ~ "!=" ~ AExp).map{ case (x, z) => Bop("!=", x, z)}  
     | P(AExp ~ "<" ~ AExp).map{ case (x, z) => Bop("<", x, z)}  
@@ -128,7 +132,7 @@
     | "(" ~ BExp ~ ")" )
 
 // statements and blocks
-def Stmt[_ : P]: P[Stmt] =
+def Stmt[$ : P]: P[Stmt] =
   P(  P("skip").map( _ => Skip) 
     | P(Ident ~ ":=" ~ AExp).map{Assign.tupled} 
     | P(Ident ~ "[" ~ AExp ~ "]" ~ ":=" ~ AExp).map{AssignA.tupled} 
@@ -137,11 +141,11 @@
     | P("new(" ~ Ident ~ "[" ~ Number ~ "])").map{ArrayDef.tupled} 
     | P("write(" ~ Ident ~ ")").map{Write} ) 
 
-def Stmts[_ : P]: P[Block] =
+def Stmts[$ : P]: P[Block] =
   P(  P(Stmt ~ ";" ~ Stmts).map{ case (x, z) => x :: z } 
     | P(Stmt).map{s => List(s)} ) 
 
-def Block[_ : P]: P[Block] =
+def Block[$ : P]: P[Block] =
   P(  "{" ~ Stmts ~ "}" 
     | P(Stmt).map(s => List(s)) )
 
@@ -320,6 +324,4 @@
 
 
 
-
-
-// runs with amm2 and amm3
+*/
--- a/progs/while/compile.sc	Fri Oct 13 23:49:34 2023 +0100
+++ b/progs/while/compile.sc	Sat Oct 21 09:09:09 2023 +0100
@@ -1,11 +1,14 @@
 // A Small Compiler for the WHILE Language
 // (it does not use a parser nor lexer)
 //
-// cal with 
+// call with 
 //
 //   amm compile.sc test
 //   amm compile.sc test2
-
+//
+// test2 includes a run of the JVM instructions. This
+// requires that jasmin.jar is present in the same 
+// directory.
 
 // the abstract syntax trees
 abstract class Stmt
@@ -33,7 +36,7 @@
 
 
 // compiler headers needed for the JVM
-// (contains methods for read and write)
+// (contains a method for write)
 val beginning = """
 .class public XXX.XXX
 .super java/lang/Object
@@ -75,10 +78,8 @@
 
 // convenient string interpolations 
 // for instructions and labels
-import scala.language.implicitConversions
-import scala.language.reflectiveCalls
 
-implicit def sring_inters(sc: StringContext) = new {
+extension (sc: StringContext) {
     def i(args: Any*): String = "   " ++ sc.s(args:_*) ++ "\n"
     def l(args: Any*): String = sc.s(args:_*) ++ ":\n"
 }
@@ -150,11 +151,6 @@
   case Write(x) => 
     (i"iload ${env(x)} \t\t; $x" ++ 
      i"invokestatic XXX/XXX/write(I)V", env)
-  //case Read(x) => {
-  //  val index = env.getOrElse(x, env.keys.size) 
-  //  (i"invokestatic XXX/XXX/read()I" ++ 
-  //   i"istore $index \t\t; $x", env + (x -> index))
-  //}
 }
 
 // compilation of a block (i.e. list of instructions)
@@ -200,8 +196,6 @@
 
 
 
-
-
 // compiling and running .j-files
 //
 // JVM files can be assembled with 
@@ -218,6 +212,7 @@
     os.write.over(os.pwd / s"$class_name.j", code)
     os.proc("java", "-jar", "jasmin.jar", s"$class_name.j").call()
     os.proc("java", s"$class_name/$class_name").call(stdout = os.Inherit, stdin = os.Inherit)
+    ()
 }
 
 
@@ -266,6 +261,3 @@
 
 
 
-
-
-// runs with amm2 and amm3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/slides/build.sc	Sat Oct 21 09:09:09 2023 +0100
@@ -0,0 +1,29 @@
+#!/usr/bin/env amm
+
+val files = Seq("slides01.tex",
+	        "slides02.tex",
+	        "slides03.tex",
+	        "slides04.tex",
+	        "slides05.tex",
+                "slides06.tex",
+	        "slides07.tex",
+	        "slides08.tex",
+	        "slides09.tex",
+	        "slides10.tex")
+
+val pdf_files = files.map(s => s.stripSuffix("tex") ++ "pdf")
+
+
+@main
+def make() = {
+  for (f <- files) {
+    println(s"Processing $f ...")
+    os.proc("xelatex", f).call(stdout = os.Inherit, stdin = os.Inherit)
+  }
+}
+
+@main
+def hg() = {
+  println(os.proc("hg", "commit", "-m texupdate", files ++ pdf_files).call())
+  println(os.proc("hg", "push").call())
+}
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
--- a/slides/slides04.tex	Fri Oct 13 23:49:34 2023 +0100
+++ b/slides/slides04.tex	Sat Oct 21 09:09:09 2023 +0100
@@ -64,6 +64,25 @@
 \end{frame}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{frame}[c]
+\frametitle{While Tokens}
+
+\begin{center}
+\begin{tabular}{rcl}
+\pcode{WHILE\_REGS} & $\dn$ & \raisebox{-1mm}{\large(}\pcode{("k" : KEYWORD)} +\\ 
+                  &       & \phantom{(}\pcode{("i" : ID)} +\\ 
+                  &       & \phantom{(}\pcode{("o" : OP)} + \\
+                  &       & \phantom{(}\pcode{("n" : NUM)} + \\
+                  &       & \phantom{(}\pcode{("s" : SEMI)} +\\ 
+                  &       & \phantom{(}\pcode{("p" : (LPAREN + RPAREN))} +\\ 
+                  &       & \phantom{(}\pcode{("b" : (BEGIN + END))} +\\ 
+                  &       & \phantom{(}\pcode{("w" : WHITESPACE)}\raisebox{-1mm}{\large)$^*$}
+\end{tabular}
+\end{center}
+
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %\begin{frame}[c]
@@ -1658,12 +1677,20 @@
 \end{frame}
 
 \begin{frame}[c]
+  \frametitle{Week 3 Feedback}
+  \begin{center}
+  \includegraphics[scale=0.30]{s0.png}
+  \end{center}
+\end{frame}
+
+
+\begin{frame}[c]
   \begin{center}
   \begin{tabular}{cc}  
-  \includegraphics[scale=0.27]{s1.png} &
-  \includegraphics[scale=0.27]{s2.png} \\
-  \includegraphics[scale=0.27]{s3.png} &
-  \includegraphics[scale=0.27]{s4.png} \\
+  \includegraphics[scale=0.20]{s1.png} &
+  \includegraphics[scale=0.20]{s2.png} \\
+  \includegraphics[scale=0.20]{s3.png} &
+  \includegraphics[scale=0.20]{s4.png} \\
   \end{tabular}                                      
   \end{center}
 \end{frame}
@@ -1671,10 +1698,10 @@
 \begin{frame}[c]
   \begin{center}
   \begin{tabular}{cc}  
-  \includegraphics[scale=0.27]{s5.png} &
-  \includegraphics[scale=0.27]{s6.png} \\
-  \includegraphics[scale=0.27]{s7.png} &
-  \includegraphics[scale=0.27]{s8.png} \\
+  \includegraphics[scale=0.20]{s5.png} &
+  \includegraphics[scale=0.20]{s6.png} \\
+  \includegraphics[scale=0.20]{s7.png} &
+  \includegraphics[scale=0.20]{s8.png} \\
   \end{tabular}                                      
   \end{center}
 \end{frame}
@@ -1682,8 +1709,8 @@
 \begin{frame}[c]
   \begin{center}
   \begin{tabular}{cc}  
-    \includegraphics[scale=0.3]{s9.png} &
-    \includegraphics[scale=0.3]{s10.png} 
+    \includegraphics[scale=0.20]{s9.png} &
+    \includegraphics[scale=0.20]{s10.png} 
   \end{tabular}                                      
   \end{center}
 \end{frame}
@@ -1693,95 +1720,66 @@
 \begin{frame}[c]
   \small
   \begin{itemize}
-  \item[$\bullet$] I'm impressed by the speed of the answers on KEATS,
-    even on weekends. It's amazing. Obviously, the lecturer cares about
-    the students.\pause
-
-  \item[$\bullet$] The handouts and materials on KEATS are very
-    helpful and your explanation is easy to understand especially
-    after both reading the handout and watch the lectures. The LGT is
-    also engaging and I will try my best to engage more. I am actually
-    already impressed by your teaching since 5CCS2PEP.\pause
-  
-  \item[$\bullet$] I believe the module is great, if possible, it
-    would be nice to have a small handout that recaps Scala syntax
-    from PEP last year.
-\end{itemize}
-\end{frame}
+  \item[$\bullet$] Great lecturer. Looking forward to the next lecture!
+    
+  \item[$\bullet$] Would it be possible for you to post the answer of
+    the homework to KEATS after sgts each week? It will be very
+    helpful for us to prepare for the exam. Thank you.
 
-\begin{frame}[c]
-  \small
-  \begin{itemize}
-  \item[$\bullet$] While I understand you want people to attend the
-    small groups, not providing the solutions to the homework
-    exercises disadvantages those with disabilities (e.g. processing
-    difficulties) as most students take notes of the solutions during
-    the SGTs, and those of us who are unable to do so cannot obtain
-    the full benefit of the sessions. Even if the exam is based on
-    those questions, it is closed-book anyway, so there is no harm in
-    providing the answers. At least allow the TAs to give the
-    solutions to those who attend the SGTs please?
+  \item[$\bullet$] A lot of the parts of the LGT are going through
+    what was covered in the videos. While this is helpful to refresh
+    students' minds, I think it would be better if the Pollev
+    questions were checked more regularly to focus on what students
+    want support with
+  \end{itemize}\bigskip
 
-  \item[$\bullet$] Really enjoy the content, but would appreciate
-    uploads of the tutorial answers as sometimes we do not have time
-    to go through all of them in the SGTs.  
-\end{itemize}
+  $\Rightarrow$ Reluctant, but I am prepared for selected questions to
+  make the answers public.
+
+  $\Rightarrow$ The content viewing numbers are a bit worrying. Therefore
+  the reflex on my side to lecture the content again.
 \end{frame}
 
 \begin{frame}[c]
   \small
-  \begin{itemize}  
-  \item[$\bullet$] CFL is a very interesting module and the LGTs are
-    helpful to consolidate information. The homeworks and courseworks
-    are useful for learning the content.  My only criticism is that it
-    feels like there is too much content crammed into each
-    week. Between the time taken each week by 2h LGT, 1h SGT, 3-4h of
-    videos, 1-2h homework and time for courseworks, I find it
-    difficult making time for all aspects of this module each week.
+  \begin{minipage}{1.3\textwidth}
+  \begin{itemize}
+  \item[$\bullet$]
+    Regarding module content, the content is not only interesting but relevant, up-to-date, and applicable to the real world. The practical, real-world application of the module is made abundantly clear through the coursework-focused delivery of the module. The content of the module progresses fast, but that is due to the nature of the content and the aims of the module. The learning aims and assessment are clearly explained.
 
+Regarding teaching, Dr. Urban is incredibly helpful both inside (and even outside) contact hours. I can tell the lecturer is very passionate about teaching the module. TAs are on hand to help with all aspects of the module, with the lecturer having taken care to have dedicated TAs for resolving technical issues. Discussions both on the forum and in lessons are encouraged, and the module is structured so that high engagement with the content and live lessons will make it easier for students to do the module (which is, of course, a good thing).
+
+Only 3 weeks in I would very highly recommend the module. It is a difficult subject, but a pleasure to study at the same time.
 \end{itemize}
+\end{minipage}
 \end{frame}
 
 \begin{frame}[c]
   \small
-  \begin{itemize}
-  \item[$\bullet$] i like this course  
-  \item[$\bullet$] I could learn the material better if the LGTs could
-    somehow be recorded because I've sometimes felt a need to go back
-    to them while revising stuff
-  \item[$\bullet$] I feel that, as with most modules, there is a lot
-    happening at once. Since we only went through the first coursework
-    it's too early to call, but the workload tends to pile up. I
-    understand it's in the nature of the module, and the work, though
-    difficult, is enjoyable, but there's gotta be a way to mitigate
-    this. Other than that, I am enjoying this module and you, Chris,
-    are a great lecturer!
+  \begin{minipage}{1.2\textwidth}
+  \begin{itemize}  
+  \item[$\bullet$] Professor Christian is incredibly patient. He always stays longer after live session lectures to answer additional questions, even though he doesn't need to. He made me feel that no questions are stupid. Thanks so much!
+    
+  \item[$\bullet$] I am enjoying your module at the moment, I think you clearly explain every point and answer all questions during the live tutorial.
+    
+  \item[$\bullet$] It would be helpful to be given the full set of coursework templates on GitHub so that there is less ambiguity regarding future courseworks.
+    
+\item[$\bullet$] Maybe some additional exercises in the LGT would be useful
+\item[$\bullet$] This module handout are the most useful thing I have ever seen in this uni.
+\item[$\bullet$] This module is structured very well and is very interesting. Thank you
 \end{itemize}
+$\Rightarrow$ In case of CW3 the starting files are comb1.sc and comb2.sc uploaded to KEATS.
+\end{minipage}
 \end{frame}
 
+
 \begin{frame}[c]
-  \small
-  \begin{itemize}  
-  \item[$\bullet$] Strongly advise you, the lecturer, to take into
-    account that your students have not been studying the subject for
-    as long as you have. Also, that some of us are still waiting to be
-    convinced of the interesting-ness and relevance of the subject,
-    which you often fail to mention in the sessions and in the
-    videos. I find myself lost trying to find a context for the things
-    we are learning.
-
-    \ldots
-
-    I thoroughly enjoy the SGTS where my concerns and questions are
-    welcomed. But I feel uncomfortable to ask you questions in your
-    LGTs because of the way I have heard you respond to other
-    students.
-
-\end{itemize}
+  \begin{center}
+    \includegraphics[scale=0.30]{~/Desktop/feynman-teaching.jpeg}
+  \end{center}
 \end{frame}
 
 \end{document}
-\end{document}
 
 
 %%% Local Variables:  
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 solutions/cw5/out.png has changed