updated
authorChristian Urban <christian.urban@kcl.ac.uk>
Fri, 31 Oct 2025 11:25:14 +0000
changeset 1019 f71399fe3fdc
parent 1018 fd6a64c53f0e
child 1020 36799f7b9702
updated
graphicss.sty
progs/lexer/lex.sc
slides/qr01.png
slides/slides05.pdf
slides/slides05.tex
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graphicss.sty	Fri Oct 31 11:25:14 2025 +0000
@@ -0,0 +1,51 @@
+\usepackage{tikz}
+\usepackage{pgf}
+\usetikzlibrary{positioning}
+\usetikzlibrary{calc}
+\usetikzlibrary{automata}
+\usetikzlibrary{arrows}
+\usetikzlibrary{backgrounds}
+\usetikzlibrary{fit}
+\usetikzlibrary{shadows}
+\usepackage{tikz-qtree}
+\usepackage{graphicx} 
+\usepackage{pgfplots}
+
+
+
+\pgfplotsset{compat=1.15}
+
+\newenvironment{bubble}[1][]{%
+\addtolength{\leftmargini}{4mm}%
+\begin{tikzpicture}[baseline=(current bounding box.north)]%
+\draw (0,0) node[drop shadow,inner sep=2mm,fill=cream,ultra thick,draw=red,rounded corners=2mm]% 
+\bgroup\begin{minipage}{#1}\raggedright{}}
+{\end{minipage}\egroup;%
+\end{tikzpicture}\bigskip}
+
+
+%%% for trees
+%% http://anorien.csc.warwick.ac.uk/mirrors/CTAN/graphics/pgf/contrib/forest/forest.pdf
+
+\newcommand\grid[1]{%
+\begin{tikzpicture}[baseline=(char.base)]
+  \path[use as bounding box]
+    (0,0) rectangle (1em,1em);
+  \draw[red!50, fill=red!20]
+    (0,0) rectangle (1em,1em);
+  \node[inner sep=1pt,anchor=base west]
+    (char) at (0em,\gridraiseamount) {#1};
+\end{tikzpicture}}
+\newcommand\gridraiseamount{0.12em}
+
+\makeatletter
+\newcommand\Grid[1]{%
+  \@tfor\z:=#1\do{\grid{\z}}}
+\makeatother	
+
+\newcommand\Vspace[1][.3em]{%
+  \mbox{\kern.06em\vrule height.3ex}%
+  \vbox{\hrule width#1}%
+  \hbox{\vrule height.3ex}}
+
+\def\VS{\Vspace[0.6em]}
\ No newline at end of file
--- a/progs/lexer/lex.sc	Fri Oct 24 11:26:43 2025 +0100
+++ b/progs/lexer/lex.sc	Fri Oct 31 11:25:14 2025 +0000
@@ -99,7 +99,7 @@
   case Right(v) => env(v)
   case Sequ(v1, v2) => env(v1) ::: env(v2)
   case Stars(vs) => vs.flatMap(env)
-  case Rec[A](x, v) => (x, flatten(v))::env(v)  
+  case Rec(x: A, v) => (x, flatten(v))::env(v)  
 }
 
 
@@ -177,20 +177,20 @@
 
 
 extension (t: TAGS) {
-  def $ (r: Rexp) = RECD[TAGS](t, r)
+  def & (r: Rexp) = RECD[TAGS](t, r)
 }
 
 def lexing(r: Rexp, s: String) = 
   env[TAGS](lex(r, s.toList))
 
-val WHILE_REGS = ((Key $ KEYWORD) | 
-                  (Id $ ID) | 
-                  (Op $ OP) | 
-                  (Num $ NUM) | 
-                  (Semi $ SEMI) | 
-                  (Str $ STRING) |
-                  (Paren $ (LPAREN | RPAREN)) | 
-                  (Wht $ WHITESPACE)).%
+val WHILE_REGS = ((Key & KEYWORD) | 
+                  (Id & ID) | 
+                  (Op & OP) | 
+                  (Num & NUM) | 
+                  (Semi & SEMI) | 
+                  (Str & STRING) |
+                  (Paren & (LPAREN | RPAREN)) | 
+                  (Wht & WHITESPACE)).%
 
 
 // Two Simple While Tests
Binary file slides/qr01.png has changed
Binary file slides/slides05.pdf has changed
--- a/slides/slides05.tex	Fri Oct 24 11:26:43 2025 +0100
+++ b/slides/slides05.tex	Fri Oct 31 11:25:14 2025 +0000
@@ -38,10 +38,10 @@
   \begin{center}
   \begin{tabular}{ll}
   Email:  & christian.urban at kcl.ac.uk\\
-Office Hour: & Fridays 12 -- 14\\  
+Office Hour: & Friday 11:30 -- 12:30\\
   Location: & N7.07 (North Wing, Bush House)\\
   Slides \& Progs: & KEATS\\
-  Pollev: & \texttt{\alert{https://pollev.com/cfltutoratki576}}\\  
+  %Pollev: & \texttt{\alert{https://pollev.com/cfltutoratki576}}\\  
   \end{tabular}
   \end{center}
 
@@ -60,6 +60,12 @@
       };
     \end{tikzpicture}
   \end{center}
+
+\begin{textblock}{5}(12,3)
+  \includegraphics[scale=0.35]{qr01}\\
+  %%\small{}Wifi: IET-Guest\\
+\end{textblock}
+
 \end{frame}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 
@@ -83,25 +89,62 @@
 
 {
 \setbeamercolor{background canvas}{bg=cream}
-\begin{frame}<1-10>[c]
+\begin{frame}[c]
+\frametitle{Some Housekeeping}
+
+\begin{itemize}
+%%\item the Discussion Forum is for everyone
+\item SGT groups 4 + 6 for 10th November
+\item Ammonite FAQ
+\end{itemize}
 \end{frame}
 
-
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\begin{frame}[c]
-  \frametitle{Coursework 1: Submissions}
+  \begin{frame}[c]
+  \frametitle{Inject}
+  
+  Injecting (``Adding'') a character to a value\\[-12mm]\mbox{}
+  
+  \begin{center}
+  \begin{tabular}{@{\hspace{-3mm}}l@{\hspace{1mm}}c@{\hspace{1mm}}l@{}}
+    \bl{$inj\,(c)\,c\,(Empty)$} & \bl{$\dn$}  & \bl{$Char\,c$}\\
+    \bl{$inj\,(r_1 + r_2)\,c\,(Left(v))$} & \bl{$\dn$}  & \bl{$Left(inj\,r_1\,c\,v)$}\\
+    \bl{$inj\,(r_1 + r_2)\,c\,(Right(v))$} & \bl{$\dn$}  & \bl{$Right(inj\,r_2\,c\,v)$}\\
+    \bl{$inj\,(r_1 \cdot r_2)\,c\,(Seq(v_1,v_2))$} & \bl{$\dn$}  & \bl{$Seq(inj\,r_1\,c\,v_1,v_2)$}\\
+    \bl{$inj\,(r_1 \cdot r_2)\,c\,(Left(Seq(v_1,v_2)))$} & \bl{$\dn$}  & \bl{$Seq(inj\,r_1\,c\,v_1,v_2)$}\\
+    \bl{$inj\,(r_1 \cdot r_2)\,c\,(Right(v))$} & \bl{$\dn$}  & \bl{$Seq(mkeps(r_1),inj\,r_2\,c\,v)$}\\
+    \bl{$inj\,(r^*)\,c\,(Seq(v,Stars\,vs))$} & \bl{$\dn$}  & \bl{$Stars\,((inj\,r\,c\,v)\,::\,vs)$}\\
+  \end{tabular}
+  \end{center}\bigskip
   
-  \begin{itemize}
-  \item Scala (162)
-  \item Ocaml (1)
-  \item Java (1)  \ldots uses new features of Java 21  
-  \item Rust (6)
-  \end{itemize}\bigskip\bigskip  
-  
+  \footnotesize
+  \begin{tabular}{l@{\hspace{2mm}}l}
+  \bl{$inj$}: & 1st arg $\mapsto$ a rexp; 2nd arg $\mapsto$ a character; 
+  3rd arg $\mapsto$ a value\\
+              & result $\mapsto$ a value 
+  \end{tabular}
+  \end{frame}
+  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\begin{frame}<1-10>[c]
+\end{frame}
+}
 
-\end{frame}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-}
+%\begin{frame}[c]
+%  \frametitle{Coursework 1: Submissions}
+%  
+%  \begin{itemize}
+%  \item Scala (162)
+%  \item Ocaml (1)
+%  \item Java (1)  \ldots uses new features of Java 21  
+%  \item Rust (6)
+%  \end{itemize}\bigskip\bigskip  
+%  %
+%
+%\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
 
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -178,34 +221,34 @@
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-{
-\setbeamercolor{background canvas}{bg=cream}
-\begin{frame}[c]
+% {
+% \setbeamercolor{background canvas}{bg=cream}
+% \begin{frame}[c]
 
-\begin{center}
-\begin{tikzpicture}[scale=1.5,>=stealth',very thick,
-                    every state/.style={minimum size=0pt,
-                    draw=blue!50,very thick,fill=blue!20}]
-  \node[state,initial]   (q0) at (0,2) {$q_0$};
-  \node[state,accepting] (q1) at (2,2) {$q_1$};
-  \node[state]           (q2) at (0,0) {$q_2$};
-  \node[state]           (q3) at (2,0) {$q_3$};
+% \begin{center}
+% \begin{tikzpicture}[scale=1.5,>=stealth',very thick,
+%                     every state/.style={minimum size=0pt,
+%                     draw=blue!50,very thick,fill=blue!20}]
+%   \node[state,initial]   (q0) at (0,2) {$q_0$};
+%   \node[state,accepting] (q1) at (2,2) {$q_1$};
+%   \node[state]           (q2) at (0,0) {$q_2$};
+%   \node[state]           (q3) at (2,0) {$q_3$};
 
-  \path[->] (q0) edge[bend left] node[above] {\alert{$a$}} (q1)
-            (q1) edge[bend left] node[above] {\alert{$a$}} (q0)
-            (q2) edge[bend left] node[above] {\alert{$a$}} (q3)
-            (q3) edge[bend left] node[above] {\alert{$a$}} (q2)
-            (q0) edge[bend left] node[right] {\alert{$b$}} (q2)
-            (q2) edge[bend left] node[left]  {\alert{$b$}} (q0)
-            (q1) edge[bend left] node[right] {\alert{$b$}} (q3)
-            (q3) edge[bend left] node[left]  {\alert{$b$}} (q1);
-\end{tikzpicture}
-\end{center}
+%   \path[->] (q0) edge[bend left] node[above] {\alert{$a$}} (q1)
+%             (q1) edge[bend left] node[above] {\alert{$a$}} (q0)
+%             (q2) edge[bend left] node[above] {\alert{$a$}} (q3)
+%             (q3) edge[bend left] node[above] {\alert{$a$}} (q2)
+%             (q0) edge[bend left] node[right] {\alert{$b$}} (q2)
+%             (q2) edge[bend left] node[left]  {\alert{$b$}} (q0)
+%             (q1) edge[bend left] node[right] {\alert{$b$}} (q3)
+%             (q3) edge[bend left] node[left]  {\alert{$b$}} (q1);
+% \end{tikzpicture}
+% \end{center}
 
-\hfill{}Which language?
+% \hfill{}Which language?
 
-\end{frame}
-}
+% \end{frame}
+% }
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 
@@ -668,44 +711,44 @@
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 
-\begin{frame}[t,fragile]
-\begin{mybox3}{}
-  For CW2, please include '$\backslash$' as a symbol in strings, because
-  the collatz program contains
-  \begin{lstlisting}[language=Scala, numbers=none]
-  write "\n";\end{lstlisting}  
-\end{mybox3}
-\end{frame}
+% \begin{frame}[t,fragile]
+% \begin{mybox3}{}
+%   For CW2, please include '$\backslash$' as a symbol in strings, because
+%   the collatz program contains
+%   \begin{lstlisting}[language=Scala, numbers=none]
+%   write "\n";\end{lstlisting}  
+% \end{mybox3}
+% \end{frame}
 
-\begin{frame}[t]
-\begin{mybox3}{}
-  val (r1s, f1s) = simp(r1)\\
-  val (r2s, f2s) = simp(r2)\\
-  how are the
-  first rectification functions f1s and f2s made? could you maybe
-  show an example?
-\end{mybox3}
-\end{frame}
+% \begin{frame}[t]
+% \begin{mybox3}{}
+%   val (r1s, f1s) = simp(r1)\\
+%   val (r2s, f2s) = simp(r2)\\
+%   how are the
+%   first rectification functions f1s and f2s made? could you maybe
+%   show an example?
+% \end{mybox3}
+% \end{frame}
 
-\begin{frame}<1-24>[c]
-\end{frame}
+% \begin{frame}<1-24>[c]
+% \end{frame}
 
 
-\begin{frame}[t]
-\begin{minipage}{1.2\textwidth}  
-  \begin{mybox3}{}\small
-    \textbf{Questions regarding CFL CW1}
+% \begin{frame}[t]
+% \begin{minipage}{1.2\textwidth}  
+%   \begin{mybox3}{}\small
+%     \textbf{Questions regarding CFL CW1}
 
-Dear Dr Urban    
+% Dear Dr Urban    
     
- Regarding CW1, I am stuck on finding the nullable and derivative rules for some important regexes.\smallskip
+%  Regarding CW1, I am stuck on finding the nullable and derivative rules for some important regexes.\smallskip
 
-The NOT Regex nullable rule: I am not sure how to approach this, I am inclined to simply put this as the negation of the nullable function on the input regex (e.g !nullable(r)). However I have found instances where negating a nullable does not make it un-nullable. For example the negation of r* can still match regex ab (which is not nullable). So I would like some actual clarification, pointers and help in this area.\smallskip
+% The NOT Regex nullable rule: I am not sure how to approach this, I am inclined to simply put this as the negation of the nullable function on the input regex (e.g !nullable(r)). However I have found instances where negating a nullable does not make it un-nullable. For example the negation of r* can still match regex ab (which is not nullable). So I would like some actual clarification, pointers and help in this area.\smallskip
 
-The NOT Regex derivation rule: again I am dumbfounded here, I am inclined to think that I should derive the regex and then negate that derivation. But none of this ever works. Please provide some helpful information so I can solve this.
-\end{mybox3}
-\end{minipage}
-\end{frame}
+% The NOT Regex derivation rule: again I am dumbfounded here, I am inclined to think that I should derive the regex and then negate that derivation. But none of this ever works. Please provide some helpful information so I can solve this.
+% \end{mybox3}
+% \end{minipage}
+% \end{frame}