48   | 
    48   | 
    49 %\begin{mybox3}{Test} | 
    49 %\begin{mybox3}{Test} | 
    50 %A physical explanation the \emph{dynamic matrix}\\ | 
    50 %A physical explanation the \emph{dynamic matrix}\\ | 
    51 %lots of text  | 
    51 %lots of text  | 
    52 %\end{mybox3} | 
    52 %\end{mybox3} | 
    53 %\end{frame} | 
    53 % \end{frame} | 
    54   | 
    54   | 
    55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
    55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
    56 \begin{frame}[t] | 
    56 \begin{frame}[t] | 
    57 \frametitle{%   | 
    57 \frametitle{%   | 
    58   \begin{tabular}{@ {}c@ {}} | 
    58   \begin{tabular}{@ {}c@ {}} | 
    59   \\[-3mm]  | 
    59   \\[-3mm]  | 
    60   \LARGE Compilers and \\[-1mm]   | 
    60   \LARGE Lunch with a Lecturer (29 March)\\[5mm]   | 
    61   \LARGE Formal Languages\\[-5mm]   | 
         | 
    62   \end{tabular}} | 
    61   \end{tabular}} | 
    63   | 
    62   | 
    64   %\begin{center} | 
    63   I teach CFL (compilers) and PEP (Scala)\bigskip  | 
    65   %\includegraphics[scale=0.3]{pics/ante1.jpg}\hspace{5mm} | 
    64   | 
    66   %\includegraphics[scale=0.31]{pics/ante2.jpg}\\ | 
    65   \begin{itemize} | 
    67   %\footnotesize\textcolor{gray}{Antikythera automaton, 100 BC (Archimedes?)} | 
    66   \item did undergraduate in Germany  | 
    68   %\end{center} | 
    67   \item Master in St Andrews  | 
    69   | 
    68   \item PhD in Cambridge    | 
    70   \normalsize  | 
    69   \end{itemize}\bigskip\bigskip | 
    71   \begin{center} | 
    70   | 
    72   \begin{tabular}{ll} | 
    71   use mainly the Isabelle theorem prover in my work (see 6CCS3VER)  | 
    73   Email:  & christian.urban at kcl.ac.uk\\  | 
    72   | 
    74   Office Hour: & Fridays 11 -- 12\\  | 
    73   write code in functional programming languages (Scala, SML, Ocaml, Haskell)  | 
    75   Location: & N7.07 (North Wing, Bush House)\\  | 
    74 \end{frame} | 
    76   Slides \& Progs: & KEATS\\  | 
    75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
    77   Pollev: & \texttt{\alert{https://pollev.com/cfltutoratki576}}\\   | 
         | 
    78   \end{tabular} | 
         | 
    79   \end{center} | 
         | 
    80   | 
         | 
    81   \begin{center} | 
         | 
    82     \begin{tikzpicture} | 
         | 
    83       \node[drop shadow,fill=white,inner sep=0pt]   | 
         | 
    84       {\footnotesize\rowcolors{1}{capri!10}{white} | 
         | 
    85         \begin{tabular}{|p{4.8cm}|p{4.8cm}|}\hline | 
         | 
    86           \cellcolor{blue!50} | 
         | 
    87           1 Introduction, Languages          & 6 While-Language \\  | 
         | 
    88           2 Regular Expressions, Derivatives & 7 Compilation, JVM \\  | 
         | 
    89           3 Automata, Regular Languages      & 8 Compiling Functional Languages \\  | 
         | 
    90           4 Lexing, Tokenising               & 9 Optimisations \\  | 
         | 
    91           5 Grammars, Parsing                & 10 LLVM \\ \hline  | 
         | 
    92         \end{tabular}% | 
         | 
    93       };  | 
         | 
    94     \end{tikzpicture} | 
         | 
    95   \end{center} | 
         | 
    96   | 
         | 
    97 \end{frame} | 
         | 
    98 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
    99   | 
         | 
   100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   101 \begin{frame}<1-12>[c] | 
         | 
   102 \frametitle{The Goal of this Module\ldots} | 
         | 
   103   | 
         | 
   104 \begin{center} | 
         | 
   105   \begin{tikzpicture}[scale=1, | 
         | 
   106                       node/.style={ | 
         | 
   107                       rectangle,rounded corners=3mm,  | 
         | 
   108                       very thick,draw=black!50,minimum height=18mm, minimum width=20mm,  | 
         | 
   109                       top color=white,bottom color=black!20,drop shadow}]  | 
         | 
   110   | 
         | 
   111   \node at (3.05, 1.8) {\Large\bf \ldots{} you write a compiler}; | 
         | 
   112   | 
         | 
   113   \node (0) at (-2.3,0) {};   | 
         | 
   114   \node [above=5mm of 0]  | 
         | 
   115   {\makebox[0mm]{\footnotesize | 
         | 
   116       \begin{tabular}{@{}l@{}}input\\[-1mm]program\end{tabular}}};  | 
         | 
   117        | 
         | 
   118   \node (A) at (0,0)  [node] {}; | 
         | 
   119   \node [below right] at (A.north west) {lexer}; | 
         | 
   120   | 
         | 
   121   \node (B) at (3,0)  [node] {}; | 
         | 
   122   \node [below right=1mm] at (B.north west) {\mbox{}\hspace{-1mm}parser}; | 
         | 
   123   | 
         | 
   124   \node (C) at (6,0)  [node] {}; | 
         | 
   125   \node [below right] at (C.north west) {\mbox{}\hspace{-1mm}code gen}; | 
         | 
   126   | 
         | 
   127   \node (1) at (8.4,0) {}; | 
         | 
   128   \node [above=5mm of 1]  | 
         | 
   129   {\makebox[0mm]{\footnotesize | 
         | 
   130       \begin{tabular}{@{}r@{}}binary\\[-1mm]code\end{tabular}}}; | 
         | 
   131   | 
         | 
   132   \draw [->,line width=4mm] (0) -- (A);   | 
         | 
   133   \draw [->,line width=4mm] (A) -- (B);   | 
         | 
   134   \draw [->,line width=4mm] (B) -- (C);   | 
         | 
   135   \draw [->,line width=4mm] (C) -- (1);   | 
         | 
   136   \end{tikzpicture} | 
         | 
   137   \end{center} | 
         | 
   138   | 
         | 
   139 \only<2,3,4>{ | 
         | 
   140 \begin{textblock}{1}(1,2.1) | 
         | 
   141 \begin{bubble}[9.8cm] | 
         | 
   142 \normalsize  | 
         | 
   143 lexer input: a string\smallskip\\  | 
         | 
   144 \hspace{5mm}\code{"read(n);"}\medskip\\ | 
         | 
   145 lexer output: a sequence of tokens\smallskip\\  | 
         | 
   146 \hspace{5mm}\code{key(read) lpar id(n) rpar semi} | 
         | 
   147 \end{bubble} | 
         | 
   148 \end{textblock}}  | 
         | 
   149   | 
         | 
   150 \only<3,4>{ | 
         | 
   151 \begin{textblock}{1}(6,7.8) | 
         | 
   152 \begin{tabular}{c} | 
         | 
   153 \includegraphics[scale=0.2]{../pics/rosetta.jpg}\\[-2mm] | 
         | 
   154 \footnotesize lexing $\Rightarrow$ recognising words (Stone of Rosetta)  | 
         | 
   155 \end{tabular} | 
         | 
   156 \end{textblock}} | 
         | 
   157   | 
         | 
   158 \only<4>{ | 
         | 
   159 \begin{textblock}{1}(0.5,12)\small | 
         | 
   160 \begin{tabular}{l@{}c@{}l} | 
         | 
   161   \pcode{if}    & $\;\Rightarrow\;$ & keyword\\ | 
         | 
   162   \pcode{iffoo} & $\;\Rightarrow\;$ & identifier\\ | 
         | 
   163 \end{tabular}   | 
         | 
   164 \end{textblock}} | 
         | 
   165   | 
         | 
   166 \only<6>{ | 
         | 
   167 \begin{textblock}{1}(1,1.5) | 
         | 
   168 \begin{bubble}[8.5cm] | 
         | 
   169 \normalsize  | 
         | 
   170 parser input: a sequence of tokens\smallskip\\  | 
         | 
   171   | 
         | 
   172 {\small\hspace{5mm}\code{key(read) lpar id(n) rpar semi}}\smallskip\\ | 
         | 
   173   | 
         | 
   174 parser output: an abstract syntax tree\smallskip\\  | 
         | 
   175 \footnotesize  | 
         | 
   176 \hspace{2cm}\begin{tikzpicture} | 
         | 
   177   \node {\code{read}} | 
         | 
   178     child {node {\code{lpar}}} | 
         | 
   179     child {node {\code{n}}} | 
         | 
   180     child {node {\code{rpar}}}; | 
         | 
   181 \end{tikzpicture} | 
         | 
   182 \end{bubble} | 
         | 
   183 \end{textblock}} | 
         | 
   184   | 
         | 
   185 \only<8,9>{ | 
         | 
   186 \begin{textblock}{1}(1,1.5) | 
         | 
   187 \begin{bubble}[4cm] | 
         | 
   188 \normalsize  | 
         | 
   189 code generation:\smallskip\\  | 
         | 
   190 \hspace{5mm}\code{istore 2}\\  | 
         | 
   191 \hspace{5mm}\code{iload 2}\\  | 
         | 
   192 \hspace{5mm}\code{ldc 10}\\ | 
         | 
   193 \hspace{5mm}\code{isub}\\ | 
         | 
   194 \hspace{5mm}\code{ifeq Label2}\\  | 
         | 
   195 \hspace{5mm}\code{iload 2}\\ | 
         | 
   196 \hspace{5mm}\code{...}\\ | 
         | 
   197 \end{bubble} | 
         | 
   198 \end{textblock}} | 
         | 
   199   | 
         | 
   200 \only<9>{ | 
         | 
   201 \begin{textblock}{6}(8.4,7) | 
         | 
   202 \begin{bubble}[5cm] | 
         | 
   203 \mbox{\begin{tikzpicture}[scale=0.58,rounded corners=0mm] | 
         | 
   204 \begin{axis}[axis x line=bottom, axis y line=left, ylabel=secs, | 
         | 
   205     xlabel=n,  | 
         | 
   206     enlargelimits=0.05,  | 
         | 
   207     ybar interval=0.7, legend style=small]  | 
         | 
   208 \addplot file {interpreted2.data}; | 
         | 
   209 \addplot file {compiled2.data}; | 
         | 
   210 %\legend{interpreted, compiled} | 
         | 
   211 \end{axis} | 
         | 
   212 \end{tikzpicture}} | 
         | 
   213 \end{bubble} | 
         | 
   214 \end{textblock}} | 
         | 
   215   | 
         | 
   216 \only<10>{ | 
         | 
   217 \begin{textblock}{6}(1,3) | 
         | 
   218   \begin{bubble}[11cm] | 
         | 
   219     Compiler explorers, e.g.: \url{https://gcc.godbolt.org} \;\video{https://youtu.be/ysaBmhMEyUg} | 
         | 
   220   \begin{tikzpicture}[] | 
         | 
   221   \node (0) at (-2.3,0) {\includegraphics[scale=0.3]{pics/csource.png}}; | 
         | 
   222   \node (1) [right=35mm] at (0) {\includegraphics[scale=0.3]{pics/cassmbl.png}};  | 
         | 
   223   \draw [->,line width=4mm, red] (0) -- (1);     | 
         | 
   224   \node (2) [below=20mm] at (0) {\LARGE\bf source}; | 
         | 
   225   \node (3) [right=40mm] at (2) {\LARGE\bf binary}; | 
         | 
   226   \draw [->,line width=1mm] (2) -- (3);     | 
         | 
   227 \end{tikzpicture} | 
         | 
   228 \end{bubble} | 
         | 
   229   | 
         | 
   230 \end{textblock}} | 
         | 
   231 \only<11>{ | 
         | 
   232 \begin{textblock}{6}(1,3) | 
         | 
   233   \begin{bubble}[11cm] | 
         | 
   234     Compiler explorer for Java: \url{https://javap.yawk.at}  | 
         | 
   235   \begin{tikzpicture}[] | 
         | 
   236   \node (0) at (-2.3,0) {\includegraphics[scale=0.4]{pics/jsource.png}}; | 
         | 
   237   \node (1) [right=35mm] at (0) {\includegraphics[scale=0.4]{pics/jassmbl.png}};  | 
         | 
   238   \draw [->,line width=4mm, red] (0) -- (1);     | 
         | 
   239   \node (2) [below=20mm] at (0) {\LARGE\bf source}; | 
         | 
   240   \node (3) [right=40mm] at (2) {\LARGE\bf byte code}; | 
         | 
   241   \draw [->,line width=1mm] (2) -- (3);     | 
         | 
   242 \end{tikzpicture} | 
         | 
   243 \end{bubble} | 
         | 
   244 \end{textblock}} | 
         | 
   245   | 
         | 
   246   | 
         | 
   247 \end{frame} | 
         | 
   248 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%       | 
         | 
   249   | 
         | 
   250   | 
         | 
   251 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   252 \begin{frame}[t] | 
         | 
   253 \frametitle{Why Study Compilers?} | 
         | 
   254   | 
         | 
   255   | 
         | 
   256 John Regehr {\small(Univ.~Utah, LLVM compiler hacker)} | 
         | 
   257 \here{https://blog.regehr.org/archives/1419} | 
         | 
   258 \smallskip\\  | 
         | 
   259   | 
         | 
   260 \begin{bubble}[10.5cm] | 
         | 
   261   \bf ``\ldots{}It’s effectively a perpetual | 
         | 
   262   employment act for solid compiler hackers.''  | 
         | 
   263 \end{bubble} | 
         | 
   264   | 
         | 
   265 \onslide<1->{ | 
         | 
   266 \only<2>{ | 
         | 
   267 \begin{itemize} | 
         | 
   268 \item {\bf Hardware is getting weirder | 
         | 
   269   rather than getting clocked faster.}  | 
         | 
   270   | 
         | 
   271 \begin{itemize} | 
         | 
   272 \item[]  ``Almost all processors are multicores nowadays and it looks  | 
         | 
   273   like there is increasing asymmetry in resources across cores.  | 
         | 
   274   Processors come with vector units, crypto accelerators etc. We have  | 
         | 
   275   DSPs, GPUs, ARM big.little, and Xeon Phi. This is only scratching the  | 
         | 
   276   surface.''  | 
         | 
   277 \end{itemize}   | 
         | 
   278 \end{itemize}} | 
         | 
   279 \only<3>{ | 
         | 
   280 \begin{itemize} | 
         | 
   281 \item {\bf We’re getting tired of low-level languages and | 
         | 
   282     their associated security disasters.}  | 
         | 
   283     | 
         | 
   284 \begin{itemize} | 
         | 
   285 \item [] ``We want to write new code, to whatever extent possible, in  | 
         | 
   286   safer, higher-level languages. Compilers are caught right in the  | 
         | 
   287   middle of these opposing trends: one of their main jobs is to help  | 
         | 
   288   bridge the large and growing gap between increasingly high-level  | 
         | 
   289   languages and increasingly wacky platforms.''  | 
         | 
   290 \end{itemize}   | 
         | 
   291 \end{itemize}}} | 
         | 
   292   | 
         | 
   293 \end{frame} | 
         | 
   294 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   295   | 
         | 
   296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   297 { | 
         | 
   298 \setbeamercolor{background canvas}{bg=cream} | 
         | 
   299 \begin{frame}[c] | 
         | 
   300   | 
         | 
   301 \frametitle{} | 
         | 
   302 \begin{mybox3}{}\it | 
         | 
   303    ``I enjoyed the module - it was genuinely the stand out academic  | 
         | 
   304 experience of my undergraduate degree, and very much influenced my  | 
         | 
   305 career interests. In fact I am currently working at ARM, in their Open  | 
         | 
   306 Source Software group, on AArch64 specific optimisations for the  | 
         | 
   307 Java/Kotlin compiler that forms part of the Android Runtime.''\\  | 
         | 
   308 \mbox{}\hfill-- Hari Limaye in year 2021/22 | 
         | 
   309 \end{mybox3}\pause | 
         | 
   310   | 
         | 
   311   | 
         | 
   312 Student numbers in CFL\medskip\\  | 
         | 
   313 \begin{tabular}{ll} | 
         | 
   314 2019: & 32\\    | 
         | 
   315 2020: & 59\\    | 
         | 
   316 2021: & 109\\  | 
         | 
   317 2022: & 121\\    | 
         | 
   318 \end{tabular}   | 
         | 
   319   | 
         | 
   320 \end{frame} | 
         | 
   321 }  | 
         | 
   322 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     | 
         | 
   323   | 
         | 
   324   | 
         | 
   325   | 
         | 
   326   | 
         | 
   327 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   328 \begin{frame}[c] | 
         | 
   329 \frametitle{Why Bother with Compilers?} | 
         | 
   330     | 
         | 
   331 \textbf{Boeing 777's}: First flight in 1994. They want to achieve | 
         | 
   332 triple redundancy for potential hardware faults.  | 
         | 
   333 \here{http://www.citemaster.net/get/db3a81c6-548e-11e5-9d2e-00163e009cc7/R8.pdf}\bigskip | 
         | 
   334     | 
         | 
   335 They compile 1 Ada program to\medskip  | 
         | 
   336     | 
         | 
   337 \begin{itemize} | 
         | 
   338   \item Intel 80486  | 
         | 
   339   \item Motorola 68040 (old Macintosh's)  | 
         | 
   340   \item AMD 29050 (RISC chips used often in laser printers)  | 
         | 
   341 \end{itemize}\medskip\medskip | 
         | 
   342     | 
         | 
   343 using 3 independent compilers.\bigskip\pause  | 
         | 
   344     | 
         | 
   345 \small Airbus uses C and static analysers. Recently started using CompCert.  | 
         | 
   346   | 
         | 
   347 \only<1->{% | 
         | 
   348 \begin{textblock}{6}(8,4.5) | 
         | 
   349 \includegraphics[scale=0.28]{../pics/777.png} | 
         | 
   350 \end{textblock}} | 
         | 
   351   | 
         | 
   352 \end{frame} | 
         | 
   353 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   354   | 
         | 
   355   | 
         | 
   356   | 
         | 
   357 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   358 \begin{frame}[c] | 
         | 
   359 \frametitle{What Do Compilers Do?} | 
         | 
   360   | 
         | 
   361 Remember BF*** from PEP?  | 
         | 
   362   | 
         | 
   363 \begin{center} | 
         | 
   364 \begin{tabular}{rcl} | 
         | 
   365 \bl{\texttt{>}} & $\Rightarrow$ & move one cell right\\ | 
         | 
   366 \bl{\texttt{<}} & $\Rightarrow$ & move one cell left\\ | 
         | 
   367 \bl{\texttt{+}} & $\Rightarrow$ & increase cell by one\\ | 
         | 
   368 \bl{\texttt{-}} & $\Rightarrow$ & decrease cell by one\\ | 
         | 
   369 \bl{\texttt{.}} & $\Rightarrow$ & print current cell\\ | 
         | 
   370 \bl{\texttt{,}} & $\Rightarrow$ & input current cell\\ | 
         | 
   371 \bl{\texttt{[}} & $\Rightarrow$ & loop begin\\ | 
         | 
   372 \bl{\texttt{]}} & $\Rightarrow$ & loop end\medskip\\ | 
         | 
   373                 & $\Rightarrow$ & everything else is a comment\\  | 
         | 
   374 \end{tabular}   | 
         | 
   375 \end{center}   | 
         | 
   376   | 
         | 
   377 \end{frame} | 
         | 
   378 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     | 
         | 
   379   | 
         | 
   380 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   381 \begin{frame}[c] | 
         | 
   382   \frametitle{A ``Compiler'' for BF*** to C} | 
         | 
   383     | 
         | 
   384   \begin{center} | 
         | 
   385   \begin{tabular}{rcl} | 
         | 
   386   \bl{\texttt{>}} & $\Rightarrow$ & \texttt{ptr++}\\ | 
         | 
   387   \bl{\texttt{<}} & $\Rightarrow$ & \texttt{ptr--}\\ | 
         | 
   388   \bl{\texttt{+}} & $\Rightarrow$ & \texttt{(*ptr)++}\\ | 
         | 
   389   \bl{\texttt{-}} & $\Rightarrow$ & \texttt{(*ptr)--}\\ | 
         | 
   390   \bl{\texttt{.}} & $\Rightarrow$ & \texttt{putchar(*ptr)}\\ | 
         | 
   391   \bl{\texttt{,}} & $\Rightarrow$ & \texttt{*ptr = getchar()}\\ | 
         | 
   392   \bl{\texttt{[}} & $\Rightarrow$ & \texttt{while(*ptr)\{}\\ | 
         | 
   393   \bl{\texttt{]}} & $\Rightarrow$ & \texttt{\}}\medskip\\ | 
         | 
   394                   & $\Rightarrow$ & ignore everything else\\  | 
         | 
   395   \end{tabular}   | 
         | 
   396   \end{center}\bigskip   | 
         | 
   397     | 
         | 
   398   \texttt{char field[30000]\\ char *ptr = \&field[15000]} | 
         | 
   399     | 
         | 
   400 \end{frame} | 
         | 
   401 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   402   | 
         | 
   403 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   404 \begin{frame}[c] | 
         | 
   405   \frametitle{Another~``Compiler''~for~BF~to~C} | 
         | 
   406     | 
         | 
   407   \begin{center} | 
         | 
   408   \begin{tabular}{rcl} | 
         | 
   409   \bl{\texttt{>\ldots>}} & $\Rightarrow$ & \texttt{ptr += n}\\ | 
         | 
   410   \bl{\texttt{<\ldots<}} & $\Rightarrow$ & \texttt{ptr -= n}\\ | 
         | 
   411   \bl{\texttt{+\ldots+}} & $\Rightarrow$ & \texttt{(*ptr) += n}\\ | 
         | 
   412   \bl{\texttt{-\ldots-}} & $\Rightarrow$ & \texttt{(*ptr) -= n}\\ | 
         | 
   413   \bl{\texttt{.}} & $\Rightarrow$ & \texttt{putchar(*ptr)}\\ | 
         | 
   414   \bl{\texttt{,}} & $\Rightarrow$ & \texttt{*ptr = getchar()}\\ | 
         | 
   415   \bl{\texttt{[}} & $\Rightarrow$ & \texttt{while(*ptr)\{}\\ | 
         | 
   416   \bl{\texttt{]}} & $\Rightarrow$ & \texttt{\}}\medskip\\ | 
         | 
   417                   & $\Rightarrow$ & ignore everything else\\  | 
         | 
   418   \end{tabular}   | 
         | 
   419   \end{center}\bigskip   | 
         | 
   420     | 
         | 
   421   \texttt{char field[30000]\\ char *ptr = \&field[15000]} | 
         | 
   422     | 
         | 
   423 \end{frame} | 
         | 
   424 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     | 
         | 
   425       | 
         | 
   426 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   427 \begin{frame}[t] | 
         | 
   428 \frametitle{A Brief Compiler History} | 
         | 
   429   | 
         | 
   430 \bigskip  | 
         | 
   431 \begin{itemize} | 
         | 
   432 \item Turing Machines, 1936 (a tape as memory)  | 
         | 
   433 \item Regular Expressions, 1956\\  | 
         | 
   434 \item The first compiler for COBOL, 1957\\ (Grace Hopper)\medskip  | 
         | 
   435 \item But surprisingly research papers are still published nowadays\\  | 
         | 
   436 \item ``Parsing: The Solved Problem That Isn't''  | 
         | 
   437   \here{https://tratt.net/laurie/blog/entries/parsing_the_solved_problem_that_isnt.html} | 
         | 
   438 \end{itemize} | 
         | 
   439   | 
         | 
   440   | 
         | 
   441 \begin{textblock}{8.5}(5,7.6) | 
         | 
   442 \begin{flushright} | 
         | 
   443 \includegraphics[scale=0.3]{pics/hopper.jpg}\\ | 
         | 
   444 \footnotesize\textcolor{gray}{Grace Hopper}\smallskip\\ | 
         | 
   445   | 
         | 
   446 {\small\textcolor{gray}{(she made it to David Letterman's Tonight Show | 
         | 
   447  \here{https://youtu.be/3N_ywhx6_K0?t=31})}} | 
         | 
   448 \end{flushright} | 
         | 
   449 \end{textblock} | 
         | 
   450   | 
         | 
   451 \end{frame} | 
         | 
   452 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%       | 
         | 
   453   | 
         | 
   454 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   455 \begin{frame}[c] | 
         | 
   456 \frametitle{Some Housekeeping} | 
         | 
   457   | 
         | 
   458 \textbf{Exam will be online:}\bigskip | 
         | 
   459   | 
         | 
   460 \begin{itemize} | 
         | 
   461 \item final exam in January (35\%)  | 
         | 
   462 \item five CWs (65\%)   | 
         | 
   463 \end{itemize}\bigskip\bigskip\pause | 
         | 
   464   | 
         | 
   465   | 
         | 
   466 \textbf{Weekly Homework (optional):} | 
         | 
   467 \begin{itemize} | 
         | 
   468 \item uploaded on KEATS, send answers via email, (try to!) respond individually  | 
         | 
   469 \item \alert{\bf all} questions in the exam will be from the HWs!! | 
         | 
   470 \end{itemize}   | 
         | 
   471   | 
         | 
   472 \end{frame} | 
         | 
   473 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   | 
         | 
   474   | 
         | 
   475 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   | 
         | 
   476 { | 
         | 
   477 \setbeamercolor{background canvas}{bg=cream} | 
         | 
   478 \begin{frame}[c] | 
         | 
   479 \frametitle{Homework} | 
         | 
   480   | 
         | 
   481 Last year(s): I did not give out solutions; students sent emails to me and I responded them individually\bigskip\\  | 
         | 
   482   | 
         | 
   483   | 
         | 
   484 This year: We will do homework mainly during the Labs (TAs have the solutions)\bigskip\\\pause  | 
         | 
   485   | 
         | 
   486 I will still choose the questions from the HW for the exam, but there might be  | 
         | 
   487 some larger amount of deviation.  | 
         | 
   488   | 
         | 
   489 \end{frame} | 
         | 
   490 }  | 
         | 
   491   | 
         | 
   492 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   493 \begin{frame}[c] | 
         | 
   494 \frametitle{Some Housekeeping} | 
         | 
   495   | 
         | 
   496 \textbf{Coursework (5 accounting for 65\%):}\bigskip | 
         | 
   497   | 
         | 
   498 \begin{itemize} | 
         | 
   499 \item matcher (5\%)  | 
         | 
   500 \item lexer (10\%)  | 
         | 
   501 \item parser / interpreter (10\%)  | 
         | 
   502 \item JVM compiler (15\%)  | 
         | 
   503 \item LLVM compiler (25\%)   | 
         | 
   504 \end{itemize}\bigskip\pause | 
         | 
   505   | 
         | 
   506 you can use \alert{any} programming language you like (Haskell, Rust)\\\pause | 
         | 
   507 you can use any code I show you and is uploaded to KEATS\ldots\textbf{BUT NOTHING ELSE!} | 
         | 
   508   | 
         | 
   509 \end{frame} | 
         | 
   510   | 
         | 
   511   | 
         | 
   512 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   513 \begin{frame}[c] | 
         | 
   514 \frametitle{Lectures 1 - 5} | 
         | 
   515   | 
         | 
   516 transforming strings into structured data\\[10mm]  | 
         | 
   517   | 
         | 
   518 {\LARGE\bf Lexing} {\hfill{}based on regular expressions}\medskip\\ | 
         | 
   519 \hspace{5mm}(recognising ``words'')\\[6mm] | 
         | 
   520   | 
         | 
   521 {\LARGE\bf Parsing}\medskip\\ | 
         | 
   522 \hspace{5mm}(recognising ``sentences'') | 
         | 
   523   | 
         | 
   524 \begin{textblock}{1}(10,9.1) | 
         | 
   525 \begin{tabular}{c} | 
         | 
   526 \includegraphics[scale=0.1]{../pics/rosetta.jpg}\\[-2mm] | 
         | 
   527 \footnotesize Stone of Rosetta  | 
         | 
   528 \end{tabular} | 
         | 
   529 \end{textblock} | 
         | 
   530   | 
         | 
   531 \end{frame} | 
         | 
   532 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     | 
         | 
   533   | 
         | 
   534 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   535 \begin{frame}[c] | 
         | 
   536 \frametitle{Lectures 1 - 5} | 
         | 
   537   | 
         | 
   538 transforming strings into structured data\\[10mm]  | 
         | 
   539   | 
         | 
   540 {\LARGE\bf Lexing} {\hfill{}based on regular expressions}\medskip\\ | 
         | 
   541 \hspace{5mm}(recognising ``words'')\\[6mm] | 
         | 
   542   | 
         | 
   543 {\LARGE\bf Parsing}\medskip\\ | 
         | 
   544 \hspace{5mm}(recognising ``sentences'') | 
         | 
   545   | 
         | 
   546 \begin{textblock}{1}(10,9.1) | 
         | 
   547 \begin{tabular}{c} | 
         | 
   548 \includegraphics[scale=0.1]{../pics/rosetta.jpg}\\[-2mm] | 
         | 
   549 \footnotesize Stone of Rosetta  | 
         | 
   550 \end{tabular} | 
         | 
   551 \end{textblock} | 
         | 
   552   | 
         | 
   553 \end{frame} | 
         | 
   554 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     | 
         | 
   555   | 
         | 
   556 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   557 \begin{frame}[c] | 
         | 
   558   \frametitle{Lectures 5 - 10} | 
         | 
   559     | 
         | 
   560   code generation for a small imperative and a small functional language\\[10mm]  | 
         | 
   561     | 
         | 
   562   {\LARGE\bf Interpreters}\medskip\\ | 
         | 
   563   \hspace{5mm}(directly runs a program)\\[6mm] | 
         | 
   564     | 
         | 
   565   {\LARGE\bf Compilers}\medskip\\ | 
         | 
   566   \hspace{5mm}(generate JVM code and LLVM-IR code) | 
         | 
   567     | 
         | 
   568   \begin{textblock}{1}(8.8,8.1) | 
         | 
   569   \begin{tabular}{c@{}c} | 
         | 
   570     \includegraphics[scale=0.4]{../pics/javaduke.png} & | 
         | 
   571     \includegraphics[scale=0.23]{../pics/llvmlogo.png} | 
         | 
   572   \end{tabular} | 
         | 
   573   \end{textblock} | 
         | 
   574     | 
         | 
   575   \end{frame} | 
         | 
   576 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     | 
         | 
   577     | 
         | 
   578   | 
         | 
   579   | 
         | 
   580 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   581 \begin{frame}[t] | 
         | 
   582 \frametitle{Familiar Regular Expresssions} | 
         | 
   583 \small  | 
         | 
   584 \begin{center} | 
         | 
   585 \texttt{[a-z0-9\_$\backslash{}$.-]+ @ [a-z0-9$\backslash{}$.-]+ . [a-z$\backslash{}$.]\{2,6\}} | 
         | 
   586 \end{center}\smallskip | 
         | 
   587   | 
         | 
   588 \begin{center} | 
         | 
   589 \begin{tabular}{@{}lp{8.5cm}@{}} | 
         | 
   590 \pcode{re*} & matches 0 or more times\\ | 
         | 
   591 \pcode{re+} & matches 1 or more times\\ | 
         | 
   592 \pcode{re?} & matches 0 or 1 times\\ | 
         | 
   593 \pcode{re\{n\}}	& matches exactly \pcode{n} number of times\\ | 
         | 
   594 \pcode{re\{n,m\}} & matches at least \pcode{n} and at most {\tt m} times\\ | 
         | 
   595 \pcode{[...]} & matches any single character inside the brackets\\ | 
         | 
   596 \pcode{[^...]} & matches any single character not inside the  | 
         | 
   597 brackets\\  | 
         | 
   598 \pcode{a-z A-Z} & character ranges\\ | 
         | 
   599 \pcode{\\d} & matches digits; equivalent to \pcode{[0-9]}\\ | 
         | 
   600 \pcode{.} & matches every character except newline\\ | 
         | 
   601 \pcode{(re)}	& groups regular expressions and remembers  | 
         | 
   602 the matched text  | 
         | 
   603 \end{tabular} | 
         | 
   604 \end{center} | 
         | 
   605   | 
         | 
   606 \end{frame} | 
         | 
   607 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     | 
         | 
   608 { | 
         | 
   609 \setbeamercolor{background canvas}{bg=cream} | 
         | 
   610 \begin{frame}[t] | 
         | 
   611 \frametitle{Notation for REs} | 
         | 
   612   | 
         | 
   613   | 
         | 
   614   | 
         | 
   615     | 
         | 
   616 \end{frame}   | 
         | 
   617 }  | 
         | 
   618   | 
         | 
   619 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   620 \begin{frame}[c] | 
         | 
   621 \frametitle{Some ``innocent'' examples} | 
         | 
   622   | 
         | 
   623 Let's try two examples  | 
         | 
   624   | 
         | 
   625 \begin{center} | 
         | 
   626   \bl{\texttt{(a*)*b}} | 
         | 
   627   \hspace{2cm} | 
         | 
   628   \bl{\texttt{[a?]\{n\}[a]\{n\}}} | 
         | 
   629 \end{center}\bigskip\pause   | 
         | 
   630   | 
         | 
   631 and match them with strings of the form  | 
         | 
   632   | 
         | 
   633 \begin{center} | 
         | 
   634   \bl{\texttt{a}}, | 
         | 
   635   \bl{\texttt{aa}}, | 
         | 
   636   \bl{\texttt{aaa}}, | 
         | 
   637   \bl{\texttt{aaaa}}, | 
         | 
   638   \bl{\texttt{aaaaa}}, | 
         | 
   639   \bl{$\underbrace{\texttt{a}...\texttt{a}}_n$}   | 
         | 
   640 \end{center}   | 
         | 
   641   | 
         | 
   642 \end{frame} | 
         | 
   643 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     | 
         | 
   644   | 
    76   | 
   645 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
    77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
   646 \begin{frame}[c] | 
    78 \begin{frame}[c] | 
   647 \frametitle{Why Bother with Regexes?} | 
    79 \frametitle{Why Bother with Regexes?} | 
   648   | 
    80   | 
   697 \end{axis} | 
   129 \end{axis} | 
   698 \end{tikzpicture} | 
   130 \end{tikzpicture} | 
   699 %  | 
   131 %  | 
   700 \end{column} | 
   132 \end{column} | 
   701 \begin{column}{.5\textwidth} | 
   133 \begin{column}{.5\textwidth} | 
         | 
   134 \small{}In PEP \& CFL \medskip\\ | 
         | 
   135 \begin{tikzpicture}\footnotesize | 
         | 
   136 \begin{axis}[ | 
         | 
   137     xlabel={$n$}, | 
         | 
   138     x label style={at={(1.07,0.0)}}, | 
         | 
   139     ylabel={time in secs}, | 
         | 
   140     enlargelimits=false,  | 
         | 
   141     xtick={0,5000,...,10000}, | 
         | 
   142     xmax=11000,  | 
         | 
   143     ymax=35,  | 
         | 
   144     ytick={0,5,...,30}, | 
         | 
   145     scaled ticks=false,  | 
         | 
   146     axis lines=left,  | 
         | 
   147     width=\textwidth,  | 
         | 
   148     height=4cm]  | 
         | 
   149 \addplot[green,mark=square*,mark options={fill=white}] table {re2.data}; | 
         | 
   150 \addplot[black,mark=square*,mark options={fill=white}] table {re3.data}; | 
         | 
   151 \end{axis} | 
         | 
   152 \end{tikzpicture} | 
         | 
   153 \begin{tikzpicture}\footnotesize | 
         | 
   154 \begin{axis}[ | 
         | 
   155     xlabel={$n$}, | 
         | 
   156     x label style={at={(1.07,0.0)}}, | 
         | 
   157     ylabel={time in secs}, | 
         | 
   158     enlargelimits=false,  | 
         | 
   159     ymax=35,  | 
         | 
   160     ytick={0,5,...,30}, | 
         | 
   161     scaled ticks=false,  | 
         | 
   162     axis lines=left,  | 
         | 
   163     width=\textwidth,  | 
         | 
   164     height=4cm]  | 
         | 
   165 \addplot[black,mark=square*,mark options={fill=white}] table {re3a.data}; | 
         | 
   166 \end{axis} | 
         | 
   167 \end{tikzpicture} | 
         | 
   168 \end{column} | 
         | 
   169 \end{columns} | 
         | 
   170 \medskip  | 
         | 
   171   | 
         | 
   172 \begin{textblock}{3}(-0.1,3.3) | 
         | 
   173 \small\hfill\bl{\texttt{[a?]\{n\}[a]\{n\}}}: | 
         | 
   174 \end{textblock} | 
         | 
   175   | 
         | 
   176 \begin{textblock}{3}(-0.1,8.7)   | 
         | 
   177 \small\hfill\bl{\texttt{(a*)*b}}: | 
         | 
   178 \end{textblock} | 
         | 
   179   | 
         | 
   180 \begin{textblock}{3}(0.3,13) | 
         | 
   181 \small{}matching with strings | 
         | 
   182 \bl{$\underbrace{\texttt{a}...\texttt{a}}_n$}   | 
         | 
   183 \end{textblock} | 
         | 
   184   | 
         | 
   185 \end{frame}  | 
         | 
   186 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    | 
         | 
   187       | 
         | 
   188 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   189 \begin{frame}[c,fragile] | 
         | 
   190   \frametitle{Incidents} | 
         | 
   191       | 
         | 
   192   \begin{itemize} | 
         | 
   193   \item a global outage on 2 July 2019 at \textbf{Cloudflare}  | 
         | 
   194   (first one for six years)\medskip  | 
         | 
   195     | 
         | 
   196   \begin{center}\small\color{blue} | 
         | 
   197   \begin{verbatim}   | 
         | 
   198   (?:(?:\"|'|\]|\}|\\|\d|(?:nan|infinity|true|false|  | 
         | 
   199   null|undefined|symbol|math)|\`|\-|\+)+[)]*;?((?:\s  | 
         | 
   200   |-|~|!|{}|\|\||\+)*.*(?:.*=.*)))   | 
         | 
   201   \end{verbatim} | 
         | 
   202   \end{center}\bigskip\bigskip\bigskip\bigskip\bigskip\bigskip\bigskip     | 
         | 
   203     | 
         | 
   204   \item on 20 July 2016 the \textbf{Stack Exchange} webpage went down | 
         | 
   205     because of an evil regular expression  | 
         | 
   206     \here{https://stackstatus.net/post/147710624694/outage-postmortem-july-20-2016}     | 
         | 
   207   \end{itemize} | 
         | 
   208     | 
         | 
   209   \begin{textblock}{6}(6,7.6) | 
         | 
   210     \includegraphics[scale=0.14]{../pics/cloudflare.png}\\ | 
         | 
   211     \footnotesize  | 
         | 
   212     It serves more web traffic than Twitter, Amazon, Apple,  | 
         | 
   213     Instagram, Bing \& Wikipedia combined.  | 
         | 
   214     \here{https://blog.cloudflare.com/details-of-the-cloudflare-outage-on-july-2-2019/} | 
         | 
   215     \end{textblock} | 
         | 
   216     | 
         | 
   217   \end{frame} | 
         | 
   218 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%       | 
         | 
   219       | 
         | 
   220 \begin{frame}[c] | 
         | 
   221   | 
         | 
   222 \frametitle{} | 
         | 
   223 \begin{mybox3}{}\it | 
         | 
   224   ``This conversation is interesting to me, and I've researched it a little bit... I also disagree with Dr. Urban on the cost/benefit of non-GC languages...[..]\\  | 
         | 
   225   | 
         | 
   226   But regardless, Scala is a lot slower than, say, C or Rust. To say it's not is basically wrong (imo)....[..]  | 
         | 
   227   ''\\  | 
         | 
   228 \mbox{}\hfill-- Oliver Iliffe,  discussion this year in PEP | 
         | 
   229 \end{mybox3}\pause | 
         | 
   230   | 
         | 
   231 \end{frame} | 
         | 
   232   | 
         | 
   233 \begin{frame}<1-10> | 
         | 
   234 \end{frame}   | 
         | 
   235   | 
         | 
   236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   237 \begin{frame}[t] | 
         | 
   238 \frametitle{%   | 
         | 
   239   \begin{tabular}{@ {}c@ {}} | 
         | 
   240   \\[-3mm]  | 
         | 
   241   \LARGE Compilers and \\[-1mm]   | 
         | 
   242   \LARGE Formal Languages\\[-5mm]   | 
         | 
   243   \end{tabular}} | 
         | 
   244   | 
         | 
   245   %\begin{center} | 
         | 
   246   %\includegraphics[scale=0.3]{pics/ante1.jpg}\hspace{5mm} | 
         | 
   247   %\includegraphics[scale=0.31]{pics/ante2.jpg}\\ | 
         | 
   248   %\footnotesize\textcolor{gray}{Antikythera automaton, 100 BC (Archimedes?)} | 
         | 
   249   %\end{center} | 
         | 
   250   | 
         | 
   251   \normalsize  | 
         | 
   252   \begin{center} | 
         | 
   253   \begin{tabular}{ll} | 
         | 
   254   Email:  & christian.urban at kcl.ac.uk\\  | 
         | 
   255   Office Hour: & Fridays 11 -- 12\\  | 
         | 
   256   Location: & N7.07 (North Wing, Bush House)\\  | 
         | 
   257   Slides \& Progs: & KEATS\\  | 
         | 
   258   Pollev: & \texttt{\alert{https://pollev.com/cfltutoratki576}}\\   | 
         | 
   259   \end{tabular} | 
         | 
   260   \end{center} | 
         | 
   261   | 
         | 
   262   \begin{center} | 
         | 
   263     \begin{tikzpicture} | 
         | 
   264       \node[drop shadow,fill=white,inner sep=0pt]   | 
         | 
   265       {\footnotesize\rowcolors{1}{capri!10}{white} | 
         | 
   266         \begin{tabular}{|p{4.8cm}|p{4.8cm}|}\hline | 
         | 
   267           \cellcolor{blue!50} | 
         | 
   268           1 Introduction, Languages          & 6 While-Language \\  | 
         | 
   269           2 Regular Expressions, Derivatives & 7 Compilation, JVM \\  | 
         | 
   270           3 Automata, Regular Languages      & 8 Compiling Functional Languages \\  | 
         | 
   271           4 Lexing, Tokenising               & 9 Optimisations \\  | 
         | 
   272           5 Grammars, Parsing                & 10 LLVM \\ \hline  | 
         | 
   273         \end{tabular}% | 
         | 
   274       };  | 
         | 
   275     \end{tikzpicture} | 
         | 
   276   \end{center} | 
         | 
   277   | 
         | 
   278 \end{frame} | 
         | 
   279 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   280   | 
         | 
   281 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   282 \begin{frame}<1-12>[c] | 
         | 
   283 \frametitle{The Goal of this Module\ldots} | 
         | 
   284   | 
         | 
   285 \begin{center} | 
         | 
   286   \begin{tikzpicture}[scale=1, | 
         | 
   287                       node/.style={ | 
         | 
   288                       rectangle,rounded corners=3mm,  | 
         | 
   289                       very thick,draw=black!50,minimum height=18mm, minimum width=20mm,  | 
         | 
   290                       top color=white,bottom color=black!20,drop shadow}]  | 
         | 
   291   | 
         | 
   292   \node at (3.05, 1.8) {\Large\bf \ldots{} you write a compiler}; | 
         | 
   293   | 
         | 
   294   \node (0) at (-2.3,0) {};   | 
         | 
   295   \node [above=5mm of 0]  | 
         | 
   296   {\makebox[0mm]{\footnotesize | 
         | 
   297       \begin{tabular}{@{}l@{}}input\\[-1mm]program\end{tabular}}};  | 
         | 
   298        | 
         | 
   299   \node (A) at (0,0)  [node] {}; | 
         | 
   300   \node [below right] at (A.north west) {lexer}; | 
         | 
   301   | 
         | 
   302   \node (B) at (3,0)  [node] {}; | 
         | 
   303   \node [below right=1mm] at (B.north west) {\mbox{}\hspace{-1mm}parser}; | 
         | 
   304   | 
         | 
   305   \node (C) at (6,0)  [node] {}; | 
         | 
   306   \node [below right] at (C.north west) {\mbox{}\hspace{-1mm}code gen}; | 
         | 
   307   | 
         | 
   308   \node (1) at (8.4,0) {}; | 
         | 
   309   \node [above=5mm of 1]  | 
         | 
   310   {\makebox[0mm]{\footnotesize | 
         | 
   311       \begin{tabular}{@{}r@{}}binary\\[-1mm]code\end{tabular}}}; | 
         | 
   312   | 
         | 
   313   \draw [->,line width=4mm] (0) -- (A);   | 
         | 
   314   \draw [->,line width=4mm] (A) -- (B);   | 
         | 
   315   \draw [->,line width=4mm] (B) -- (C);   | 
         | 
   316   \draw [->,line width=4mm] (C) -- (1);   | 
         | 
   317   \end{tikzpicture} | 
         | 
   318   \end{center} | 
         | 
   319   | 
         | 
   320 \only<2,3,4>{ | 
         | 
   321 \begin{textblock}{1}(1,2.1) | 
         | 
   322 \begin{bubble}[9.8cm] | 
         | 
   323 \normalsize  | 
         | 
   324 lexer input: a string\smallskip\\  | 
         | 
   325 \hspace{5mm}\code{"read(n);"}\medskip\\ | 
         | 
   326 lexer output: a sequence of tokens\smallskip\\  | 
         | 
   327 \hspace{5mm}\code{key(read) lpar id(n) rpar semi} | 
         | 
   328 \end{bubble} | 
         | 
   329 \end{textblock}}  | 
         | 
   330   | 
         | 
   331 \only<3,4>{ | 
         | 
   332 \begin{textblock}{1}(6,7.8) | 
         | 
   333 \begin{tabular}{c} | 
         | 
   334 \includegraphics[scale=0.2]{../pics/rosetta.jpg}\\[-2mm] | 
         | 
   335 \footnotesize lexing $\Rightarrow$ recognising words (Stone of Rosetta)  | 
         | 
   336 \end{tabular} | 
         | 
   337 \end{textblock}} | 
         | 
   338   | 
         | 
   339 \only<4>{ | 
         | 
   340 \begin{textblock}{1}(0.5,12)\small | 
         | 
   341 \begin{tabular}{l@{}c@{}l} | 
         | 
   342   \pcode{if}    & $\;\Rightarrow\;$ & keyword\\ | 
         | 
   343   \pcode{iffoo} & $\;\Rightarrow\;$ & identifier\\ | 
         | 
   344 \end{tabular}   | 
         | 
   345 \end{textblock}} | 
         | 
   346   | 
         | 
   347 \only<6>{ | 
         | 
   348 \begin{textblock}{1}(1,1.5) | 
         | 
   349 \begin{bubble}[8.5cm] | 
         | 
   350 \normalsize  | 
         | 
   351 parser input: a sequence of tokens\smallskip\\  | 
         | 
   352   | 
         | 
   353 {\small\hspace{5mm}\code{key(read) lpar id(n) rpar semi}}\smallskip\\ | 
         | 
   354   | 
         | 
   355 parser output: an abstract syntax tree\smallskip\\  | 
         | 
   356 \footnotesize  | 
         | 
   357 \hspace{2cm}\begin{tikzpicture} | 
         | 
   358   \node {\code{read}} | 
         | 
   359     child {node {\code{lpar}}} | 
         | 
   360     child {node {\code{n}}} | 
         | 
   361     child {node {\code{rpar}}}; | 
         | 
   362 \end{tikzpicture} | 
         | 
   363 \end{bubble} | 
         | 
   364 \end{textblock}} | 
         | 
   365   | 
         | 
   366 \only<8,9>{ | 
         | 
   367 \begin{textblock}{1}(1,1.5) | 
         | 
   368 \begin{bubble}[4cm] | 
         | 
   369 \normalsize  | 
         | 
   370 code generation:\smallskip\\  | 
         | 
   371 \hspace{5mm}\code{istore 2}\\  | 
         | 
   372 \hspace{5mm}\code{iload 2}\\  | 
         | 
   373 \hspace{5mm}\code{ldc 10}\\ | 
         | 
   374 \hspace{5mm}\code{isub}\\ | 
         | 
   375 \hspace{5mm}\code{ifeq Label2}\\  | 
         | 
   376 \hspace{5mm}\code{iload 2}\\ | 
         | 
   377 \hspace{5mm}\code{...}\\ | 
         | 
   378 \end{bubble} | 
         | 
   379 \end{textblock}} | 
         | 
   380   | 
         | 
   381 \only<9>{ | 
         | 
   382 \begin{textblock}{6}(8.4,7) | 
         | 
   383 \begin{bubble}[5cm] | 
         | 
   384 \mbox{\begin{tikzpicture}[scale=0.58,rounded corners=0mm] | 
         | 
   385 \begin{axis}[axis x line=bottom, axis y line=left, ylabel=secs, | 
         | 
   386     xlabel=n,  | 
         | 
   387     enlargelimits=0.05,  | 
         | 
   388     ybar interval=0.7, legend style=small]  | 
         | 
   389 \addplot file {interpreted2.data}; | 
         | 
   390 \addplot file {compiled2.data}; | 
         | 
   391 %\legend{interpreted, compiled} | 
         | 
   392 \end{axis} | 
         | 
   393 \end{tikzpicture}} | 
         | 
   394 \end{bubble} | 
         | 
   395 \end{textblock}} | 
         | 
   396   | 
         | 
   397 \only<10>{ | 
         | 
   398 \begin{textblock}{6}(1,3) | 
         | 
   399   \begin{bubble}[11cm] | 
         | 
   400     Compiler explorers, e.g.: \url{https://gcc.godbolt.org} \;\video{https://youtu.be/ysaBmhMEyUg} | 
         | 
   401   \begin{tikzpicture}[] | 
         | 
   402   \node (0) at (-2.3,0) {\includegraphics[scale=0.3]{pics/csource.png}}; | 
         | 
   403   \node (1) [right=35mm] at (0) {\includegraphics[scale=0.3]{pics/cassmbl.png}};  | 
         | 
   404   \draw [->,line width=4mm, red] (0) -- (1);     | 
         | 
   405   \node (2) [below=20mm] at (0) {\LARGE\bf source}; | 
         | 
   406   \node (3) [right=40mm] at (2) {\LARGE\bf binary}; | 
         | 
   407   \draw [->,line width=1mm] (2) -- (3);     | 
         | 
   408 \end{tikzpicture} | 
         | 
   409 \end{bubble} | 
         | 
   410   | 
         | 
   411 \end{textblock}} | 
         | 
   412 \only<11>{ | 
         | 
   413 \begin{textblock}{6}(1,3) | 
         | 
   414   \begin{bubble}[11cm] | 
         | 
   415     Compiler explorer for Java: \url{https://javap.yawk.at}  | 
         | 
   416   \begin{tikzpicture}[] | 
         | 
   417   \node (0) at (-2.3,0) {\includegraphics[scale=0.4]{pics/jsource.png}}; | 
         | 
   418   \node (1) [right=35mm] at (0) {\includegraphics[scale=0.4]{pics/jassmbl.png}};  | 
         | 
   419   \draw [->,line width=4mm, red] (0) -- (1);     | 
         | 
   420   \node (2) [below=20mm] at (0) {\LARGE\bf source}; | 
         | 
   421   \node (3) [right=40mm] at (2) {\LARGE\bf byte code}; | 
         | 
   422   \draw [->,line width=1mm] (2) -- (3);     | 
         | 
   423 \end{tikzpicture} | 
         | 
   424 \end{bubble} | 
         | 
   425 \end{textblock}} | 
         | 
   426   | 
         | 
   427   | 
         | 
   428 \end{frame} | 
         | 
   429 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%       | 
         | 
   430   | 
         | 
   431   | 
         | 
   432 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   433 \begin{frame}[t] | 
         | 
   434 \frametitle{Why Study Compilers?} | 
         | 
   435   | 
         | 
   436   | 
         | 
   437 John Regehr {\small(Univ.~Utah, LLVM compiler hacker)} | 
         | 
   438 \here{https://blog.regehr.org/archives/1419} | 
         | 
   439 \smallskip\\  | 
         | 
   440   | 
         | 
   441 \begin{bubble}[10.5cm] | 
         | 
   442   \bf ``\ldots{}It’s effectively a perpetual | 
         | 
   443   employment act for solid compiler hackers.''  | 
         | 
   444 \end{bubble} | 
         | 
   445   | 
         | 
   446 \onslide<1->{ | 
         | 
   447 \only<2>{ | 
         | 
   448 \begin{itemize} | 
         | 
   449 \item {\bf Hardware is getting weirder | 
         | 
   450   rather than getting clocked faster.}  | 
         | 
   451   | 
         | 
   452 \begin{itemize} | 
         | 
   453 \item[]  ``Almost all processors are multicores nowadays and it looks  | 
         | 
   454   like there is increasing asymmetry in resources across cores.  | 
         | 
   455   Processors come with vector units, crypto accelerators etc. We have  | 
         | 
   456   DSPs, GPUs, ARM big.little, and Xeon Phi. This is only scratching the  | 
         | 
   457   surface.''  | 
         | 
   458 \end{itemize}   | 
         | 
   459 \end{itemize}} | 
         | 
   460 \only<3>{ | 
         | 
   461 \begin{itemize} | 
         | 
   462 \item {\bf We’re getting tired of low-level languages and | 
         | 
   463     their associated security disasters.}  | 
         | 
   464     | 
         | 
   465 \begin{itemize} | 
         | 
   466 \item [] ``We want to write new code, to whatever extent possible, in  | 
         | 
   467   safer, higher-level languages. Compilers are caught right in the  | 
         | 
   468   middle of these opposing trends: one of their main jobs is to help  | 
         | 
   469   bridge the large and growing gap between increasingly high-level  | 
         | 
   470   languages and increasingly wacky platforms.''  | 
         | 
   471 \end{itemize}   | 
         | 
   472 \end{itemize}}} | 
         | 
   473   | 
         | 
   474 \end{frame} | 
         | 
   475 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   476   | 
         | 
   477 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   478 { | 
         | 
   479 \setbeamercolor{background canvas}{bg=cream} | 
         | 
   480 \begin{frame}[c] | 
         | 
   481   | 
         | 
   482 \frametitle{} | 
         | 
   483 \begin{mybox3}{}\it | 
         | 
   484    ``I enjoyed the module - it was genuinely the stand out academic  | 
         | 
   485 experience of my undergraduate degree, and very much influenced my  | 
         | 
   486 career interests. In fact I am currently working at ARM, in their Open  | 
         | 
   487 Source Software group, on AArch64 specific optimisations for the  | 
         | 
   488 Java/Kotlin compiler that forms part of the Android Runtime.''\\  | 
         | 
   489 \mbox{}\hfill-- Hari Limaye in year 2021/22 | 
         | 
   490 \end{mybox3}\pause | 
         | 
   491   | 
         | 
   492   | 
         | 
   493 Student numbers in CFL\medskip\\  | 
         | 
   494 \begin{tabular}{ll} | 
         | 
   495 2019: & 32\\    | 
         | 
   496 2020: & 59\\    | 
         | 
   497 2021: & 109\\  | 
         | 
   498 2022: & 121\\    | 
         | 
   499 \end{tabular}   | 
         | 
   500   | 
         | 
   501 \end{frame} | 
         | 
   502 }  | 
         | 
   503 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     | 
         | 
   504   | 
         | 
   505   | 
         | 
   506   | 
         | 
   507   | 
         | 
   508 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   509 \begin{frame}[c] | 
         | 
   510 \frametitle{Why Bother with Compilers?} | 
         | 
   511     | 
         | 
   512 \textbf{Boeing 777's}: First flight in 1994. They want to achieve | 
         | 
   513 triple redundancy for potential hardware faults.  | 
         | 
   514 \here{http://www.citemaster.net/get/db3a81c6-548e-11e5-9d2e-00163e009cc7/R8.pdf}\bigskip | 
         | 
   515     | 
         | 
   516 They compile 1 Ada program to\medskip  | 
         | 
   517     | 
         | 
   518 \begin{itemize} | 
         | 
   519   \item Intel 80486  | 
         | 
   520   \item Motorola 68040 (old Macintosh's)  | 
         | 
   521   \item AMD 29050 (RISC chips used often in laser printers)  | 
         | 
   522 \end{itemize}\medskip\medskip | 
         | 
   523     | 
         | 
   524 using 3 independent compilers.\bigskip\pause  | 
         | 
   525     | 
         | 
   526 \small Airbus uses C and static analysers. Recently started using CompCert.  | 
         | 
   527   | 
         | 
   528 \only<1->{% | 
         | 
   529 \begin{textblock}{6}(8,4.5) | 
         | 
   530 \includegraphics[scale=0.28]{../pics/777.png} | 
         | 
   531 \end{textblock}} | 
         | 
   532   | 
         | 
   533 \end{frame} | 
         | 
   534 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   535   | 
         | 
   536   | 
         | 
   537   | 
         | 
   538 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   539 \begin{frame}[c] | 
         | 
   540 \frametitle{What Do Compilers Do?} | 
         | 
   541   | 
         | 
   542 Remember BF*** from PEP?  | 
         | 
   543   | 
         | 
   544 \begin{center} | 
         | 
   545 \begin{tabular}{rcl} | 
         | 
   546 \bl{\texttt{>}} & $\Rightarrow$ & move one cell right\\ | 
         | 
   547 \bl{\texttt{<}} & $\Rightarrow$ & move one cell left\\ | 
         | 
   548 \bl{\texttt{+}} & $\Rightarrow$ & increase cell by one\\ | 
         | 
   549 \bl{\texttt{-}} & $\Rightarrow$ & decrease cell by one\\ | 
         | 
   550 \bl{\texttt{.}} & $\Rightarrow$ & print current cell\\ | 
         | 
   551 \bl{\texttt{,}} & $\Rightarrow$ & input current cell\\ | 
         | 
   552 \bl{\texttt{[}} & $\Rightarrow$ & loop begin\\ | 
         | 
   553 \bl{\texttt{]}} & $\Rightarrow$ & loop end\medskip\\ | 
         | 
   554                 & $\Rightarrow$ & everything else is a comment\\  | 
         | 
   555 \end{tabular}   | 
         | 
   556 \end{center}   | 
         | 
   557   | 
         | 
   558 \end{frame} | 
         | 
   559 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     | 
         | 
   560   | 
         | 
   561 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   562 \begin{frame}[c] | 
         | 
   563   \frametitle{A ``Compiler'' for BF*** to C} | 
         | 
   564     | 
         | 
   565   \begin{center} | 
         | 
   566   \begin{tabular}{rcl} | 
         | 
   567   \bl{\texttt{>}} & $\Rightarrow$ & \texttt{ptr++}\\ | 
         | 
   568   \bl{\texttt{<}} & $\Rightarrow$ & \texttt{ptr--}\\ | 
         | 
   569   \bl{\texttt{+}} & $\Rightarrow$ & \texttt{(*ptr)++}\\ | 
         | 
   570   \bl{\texttt{-}} & $\Rightarrow$ & \texttt{(*ptr)--}\\ | 
         | 
   571   \bl{\texttt{.}} & $\Rightarrow$ & \texttt{putchar(*ptr)}\\ | 
         | 
   572   \bl{\texttt{,}} & $\Rightarrow$ & \texttt{*ptr = getchar()}\\ | 
         | 
   573   \bl{\texttt{[}} & $\Rightarrow$ & \texttt{while(*ptr)\{}\\ | 
         | 
   574   \bl{\texttt{]}} & $\Rightarrow$ & \texttt{\}}\medskip\\ | 
         | 
   575                   & $\Rightarrow$ & ignore everything else\\  | 
         | 
   576   \end{tabular}   | 
         | 
   577   \end{center}\bigskip   | 
         | 
   578     | 
         | 
   579   \texttt{char field[30000]\\ char *ptr = \&field[15000]} | 
         | 
   580     | 
         | 
   581 \end{frame} | 
         | 
   582 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   583   | 
         | 
   584 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   585 \begin{frame}[c] | 
         | 
   586   \frametitle{Another~``Compiler''~for~BF~to~C} | 
         | 
   587     | 
         | 
   588   \begin{center} | 
         | 
   589   \begin{tabular}{rcl} | 
         | 
   590   \bl{\texttt{>\ldots>}} & $\Rightarrow$ & \texttt{ptr += n}\\ | 
         | 
   591   \bl{\texttt{<\ldots<}} & $\Rightarrow$ & \texttt{ptr -= n}\\ | 
         | 
   592   \bl{\texttt{+\ldots+}} & $\Rightarrow$ & \texttt{(*ptr) += n}\\ | 
         | 
   593   \bl{\texttt{-\ldots-}} & $\Rightarrow$ & \texttt{(*ptr) -= n}\\ | 
         | 
   594   \bl{\texttt{.}} & $\Rightarrow$ & \texttt{putchar(*ptr)}\\ | 
         | 
   595   \bl{\texttt{,}} & $\Rightarrow$ & \texttt{*ptr = getchar()}\\ | 
         | 
   596   \bl{\texttt{[}} & $\Rightarrow$ & \texttt{while(*ptr)\{}\\ | 
         | 
   597   \bl{\texttt{]}} & $\Rightarrow$ & \texttt{\}}\medskip\\ | 
         | 
   598                   & $\Rightarrow$ & ignore everything else\\  | 
         | 
   599   \end{tabular}   | 
         | 
   600   \end{center}\bigskip   | 
         | 
   601     | 
         | 
   602   \texttt{char field[30000]\\ char *ptr = \&field[15000]} | 
         | 
   603     | 
         | 
   604 \end{frame} | 
         | 
   605 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     | 
         | 
   606       | 
         | 
   607 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   608 \begin{frame}[t] | 
         | 
   609 \frametitle{A Brief Compiler History} | 
         | 
   610   | 
         | 
   611 \bigskip  | 
         | 
   612 \begin{itemize} | 
         | 
   613 \item Turing Machines, 1936 (a tape as memory)  | 
         | 
   614 \item Regular Expressions, 1956\\  | 
         | 
   615 \item The first compiler for COBOL, 1957\\ (Grace Hopper)\medskip  | 
         | 
   616 \item But surprisingly research papers are still published nowadays\\  | 
         | 
   617 \item ``Parsing: The Solved Problem That Isn't''  | 
         | 
   618   \here{https://tratt.net/laurie/blog/entries/parsing_the_solved_problem_that_isnt.html} | 
         | 
   619 \end{itemize} | 
         | 
   620   | 
         | 
   621   | 
         | 
   622 \begin{textblock}{8.5}(5,7.6) | 
         | 
   623 \begin{flushright} | 
         | 
   624 \includegraphics[scale=0.3]{pics/hopper.jpg}\\ | 
         | 
   625 \footnotesize\textcolor{gray}{Grace Hopper}\smallskip\\ | 
         | 
   626   | 
         | 
   627 {\small\textcolor{gray}{(she made it to David Letterman's Tonight Show | 
         | 
   628  \here{https://youtu.be/3N_ywhx6_K0?t=31})}} | 
         | 
   629 \end{flushright} | 
         | 
   630 \end{textblock} | 
         | 
   631   | 
         | 
   632 \end{frame} | 
         | 
   633 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%       | 
         | 
   634   | 
         | 
   635 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   636 \begin{frame}[c] | 
         | 
   637 \frametitle{Some Housekeeping} | 
         | 
   638   | 
         | 
   639 \textbf{Exam will be online:}\bigskip | 
         | 
   640   | 
         | 
   641 \begin{itemize} | 
         | 
   642 \item final exam in January (35\%)  | 
         | 
   643 \item five CWs (65\%)   | 
         | 
   644 \end{itemize}\bigskip\bigskip\pause | 
         | 
   645   | 
         | 
   646   | 
         | 
   647 \textbf{Weekly Homework (optional):} | 
         | 
   648 \begin{itemize} | 
         | 
   649 \item uploaded on KEATS, send answers via email, (try to!) respond individually  | 
         | 
   650 \item \alert{\bf all} questions in the exam will be from the HWs!! | 
         | 
   651 \end{itemize}   | 
         | 
   652   | 
         | 
   653 \end{frame} | 
         | 
   654 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   | 
         | 
   655   | 
         | 
   656 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   | 
         | 
   657 { | 
         | 
   658 \setbeamercolor{background canvas}{bg=cream} | 
         | 
   659 \begin{frame}[c] | 
         | 
   660 \frametitle{Homework} | 
         | 
   661   | 
         | 
   662 Last year(s): I did not give out solutions; students sent emails to me and I responded them individually\bigskip\\  | 
         | 
   663   | 
         | 
   664   | 
         | 
   665 This year: We will do homework mainly during the Labs (TAs have the solutions)\bigskip\\\pause  | 
         | 
   666   | 
         | 
   667 I will still choose the questions from the HW for the exam, but there might be  | 
         | 
   668 some larger amount of deviation.  | 
         | 
   669   | 
         | 
   670 \end{frame} | 
         | 
   671 }  | 
         | 
   672   | 
         | 
   673 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   674 \begin{frame}[c] | 
         | 
   675 \frametitle{Some Housekeeping} | 
         | 
   676   | 
         | 
   677 \textbf{Coursework (5 accounting for 65\%):}\bigskip | 
         | 
   678   | 
         | 
   679 \begin{itemize} | 
         | 
   680 \item matcher (5\%)  | 
         | 
   681 \item lexer (10\%)  | 
         | 
   682 \item parser / interpreter (10\%)  | 
         | 
   683 \item JVM compiler (15\%)  | 
         | 
   684 \item LLVM compiler (25\%)   | 
         | 
   685 \end{itemize}\bigskip\pause | 
         | 
   686   | 
         | 
   687 you can use \alert{any} programming language you like (Haskell, Rust)\\\pause | 
         | 
   688 you can use any code I show you and is uploaded to KEATS\ldots\textbf{BUT NOTHING ELSE!} | 
         | 
   689   | 
         | 
   690 \end{frame} | 
         | 
   691   | 
         | 
   692   | 
         | 
   693 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   694 \begin{frame}[c] | 
         | 
   695 \frametitle{Lectures 1 - 5} | 
         | 
   696   | 
         | 
   697 transforming strings into structured data\\[10mm]  | 
         | 
   698   | 
         | 
   699 {\LARGE\bf Lexing} {\hfill{}based on regular expressions}\medskip\\ | 
         | 
   700 \hspace{5mm}(recognising ``words'')\\[6mm] | 
         | 
   701   | 
         | 
   702 {\LARGE\bf Parsing}\medskip\\ | 
         | 
   703 \hspace{5mm}(recognising ``sentences'') | 
         | 
   704   | 
         | 
   705 \begin{textblock}{1}(10,9.1) | 
         | 
   706 \begin{tabular}{c} | 
         | 
   707 \includegraphics[scale=0.1]{../pics/rosetta.jpg}\\[-2mm] | 
         | 
   708 \footnotesize Stone of Rosetta  | 
         | 
   709 \end{tabular} | 
         | 
   710 \end{textblock} | 
         | 
   711   | 
         | 
   712 \end{frame} | 
         | 
   713 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     | 
         | 
   714   | 
         | 
   715 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   716 \begin{frame}[c] | 
         | 
   717 \frametitle{Lectures 1 - 5} | 
         | 
   718   | 
         | 
   719 transforming strings into structured data\\[10mm]  | 
         | 
   720   | 
         | 
   721 {\LARGE\bf Lexing} {\hfill{}based on regular expressions}\medskip\\ | 
         | 
   722 \hspace{5mm}(recognising ``words'')\\[6mm] | 
         | 
   723   | 
         | 
   724 {\LARGE\bf Parsing}\medskip\\ | 
         | 
   725 \hspace{5mm}(recognising ``sentences'') | 
         | 
   726   | 
         | 
   727 \begin{textblock}{1}(10,9.1) | 
         | 
   728 \begin{tabular}{c} | 
         | 
   729 \includegraphics[scale=0.1]{../pics/rosetta.jpg}\\[-2mm] | 
         | 
   730 \footnotesize Stone of Rosetta  | 
         | 
   731 \end{tabular} | 
         | 
   732 \end{textblock} | 
         | 
   733   | 
         | 
   734 \end{frame} | 
         | 
   735 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     | 
         | 
   736   | 
         | 
   737 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   738 \begin{frame}[c] | 
         | 
   739   \frametitle{Lectures 5 - 10} | 
         | 
   740     | 
         | 
   741   code generation for a small imperative and a small functional language\\[10mm]  | 
         | 
   742     | 
         | 
   743   {\LARGE\bf Interpreters}\medskip\\ | 
         | 
   744   \hspace{5mm}(directly runs a program)\\[6mm] | 
         | 
   745     | 
         | 
   746   {\LARGE\bf Compilers}\medskip\\ | 
         | 
   747   \hspace{5mm}(generate JVM code and LLVM-IR code) | 
         | 
   748     | 
         | 
   749   \begin{textblock}{1}(8.8,8.1) | 
         | 
   750   \begin{tabular}{c@{}c} | 
         | 
   751     \includegraphics[scale=0.4]{../pics/javaduke.png} & | 
         | 
   752     \includegraphics[scale=0.23]{../pics/llvmlogo.png} | 
         | 
   753   \end{tabular} | 
         | 
   754   \end{textblock} | 
         | 
   755     | 
         | 
   756   \end{frame} | 
         | 
   757 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     | 
         | 
   758     | 
         | 
   759   | 
         | 
   760   | 
         | 
   761 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   762 \begin{frame}[t] | 
         | 
   763 \frametitle{Familiar Regular Expresssions} | 
         | 
   764 \small  | 
         | 
   765 \begin{center} | 
         | 
   766 \texttt{[a-z0-9\_$\backslash{}$.-]+ @ [a-z0-9$\backslash{}$.-]+ . [a-z$\backslash{}$.]\{2,6\}} | 
         | 
   767 \end{center}\smallskip | 
         | 
   768   | 
         | 
   769 \begin{center} | 
         | 
   770 \begin{tabular}{@{}lp{8.5cm}@{}} | 
         | 
   771 \pcode{re*} & matches 0 or more times\\ | 
         | 
   772 \pcode{re+} & matches 1 or more times\\ | 
         | 
   773 \pcode{re?} & matches 0 or 1 times\\ | 
         | 
   774 \pcode{re\{n\}}	& matches exactly \pcode{n} number of times\\ | 
         | 
   775 \pcode{re\{n,m\}} & matches at least \pcode{n} and at most {\tt m} times\\ | 
         | 
   776 \pcode{[...]} & matches any single character inside the brackets\\ | 
         | 
   777 \pcode{[^...]} & matches any single character not inside the  | 
         | 
   778 brackets\\  | 
         | 
   779 \pcode{a-z A-Z} & character ranges\\ | 
         | 
   780 \pcode{\\d} & matches digits; equivalent to \pcode{[0-9]}\\ | 
         | 
   781 \pcode{.} & matches every character except newline\\ | 
         | 
   782 \pcode{(re)}	& groups regular expressions and remembers  | 
         | 
   783 the matched text  | 
         | 
   784 \end{tabular} | 
         | 
   785 \end{center} | 
         | 
   786   | 
         | 
   787 \end{frame} | 
         | 
   788 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     | 
         | 
   789 { | 
         | 
   790 \setbeamercolor{background canvas}{bg=cream} | 
         | 
   791 \begin{frame}[t] | 
         | 
   792 \frametitle{Notation for REs} | 
         | 
   793   | 
         | 
   794   | 
         | 
   795   | 
         | 
   796     | 
         | 
   797 \end{frame}   | 
         | 
   798 }  | 
         | 
   799   | 
         | 
   800 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   801 \begin{frame}[c] | 
         | 
   802 \frametitle{Some ``innocent'' examples} | 
         | 
   803   | 
         | 
   804 Let's try two examples  | 
         | 
   805   | 
         | 
   806 \begin{center} | 
         | 
   807   \bl{\texttt{(a*)*b}} | 
         | 
   808   \hspace{2cm} | 
         | 
   809   \bl{\texttt{[a?]\{n\}[a]\{n\}}} | 
         | 
   810 \end{center}\bigskip\pause   | 
         | 
   811   | 
         | 
   812 and match them with strings of the form  | 
         | 
   813   | 
         | 
   814 \begin{center} | 
         | 
   815   \bl{\texttt{a}}, | 
         | 
   816   \bl{\texttt{aa}}, | 
         | 
   817   \bl{\texttt{aaa}}, | 
         | 
   818   \bl{\texttt{aaaa}}, | 
         | 
   819   \bl{\texttt{aaaaa}}, | 
         | 
   820   \bl{$\underbrace{\texttt{a}...\texttt{a}}_n$}   | 
         | 
   821 \end{center}   | 
         | 
   822   | 
         | 
   823 \end{frame} | 
         | 
   824 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     | 
         | 
   825   | 
         | 
   826 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
         | 
   827 \begin{frame}[c] | 
         | 
   828 \frametitle{Why Bother with Regexes?} | 
         | 
   829   | 
         | 
   830 \begin{columns}[t,onlytextwidth] | 
         | 
   831 \begin{column}{1.8cm} | 
         | 
   832 \mbox{}    | 
         | 
   833 \end{column}     | 
         | 
   834 \begin{column}{.5\textwidth} | 
         | 
   835 \small{}Ruby, Python, Java 8\medskip\\ | 
         | 
   836 \begin{tikzpicture}\footnotesize | 
         | 
   837 \begin{axis}[ | 
         | 
   838     xlabel={$n$}, | 
         | 
   839     x label style={at={(1.05,0.0)}}, | 
         | 
   840     ylabel={time in secs}, | 
         | 
   841     enlargelimits=false,  | 
         | 
   842     xtick={0,5,...,30}, | 
         | 
   843     xmax=33,  | 
         | 
   844     ymax=35,  | 
         | 
   845     ytick={0,5,...,30}, | 
         | 
   846     scaled ticks=false,  | 
         | 
   847     axis lines=left,  | 
         | 
   848     width=\textwidth,  | 
         | 
   849     height=4cm,   | 
         | 
   850     legend entries={Python,Ruby},   | 
         | 
   851     legend pos=north west,  | 
         | 
   852     legend cell align=left]  | 
         | 
   853 \addplot[blue,mark=*, mark options={fill=white}] table {re-python.data}; | 
         | 
   854 \addplot[brown,mark=triangle*, mark options={fill=white}] table {re-ruby.data}; | 
         | 
   855 \end{axis} | 
         | 
   856 \end{tikzpicture} | 
         | 
   857 \begin{tikzpicture}\footnotesize | 
         | 
   858 \begin{axis}[ | 
         | 
   859     xlabel={$n$}, | 
         | 
   860     x label style={at={(1.05,0.0)}}, | 
         | 
   861     ylabel={time in secs}, | 
         | 
   862     enlargelimits=false,  | 
         | 
   863     xtick={0,5,...,30}, | 
         | 
   864     xmax=33,  | 
         | 
   865     ymax=35,  | 
         | 
   866     ytick={0,5,...,30}, | 
         | 
   867     scaled ticks=false,  | 
         | 
   868     axis lines=left,  | 
         | 
   869     width=\textwidth,  | 
         | 
   870     height=4cm,   | 
         | 
   871     legend entries={Python, Java 8, JavaScript, Swift},   | 
         | 
   872     legend pos=north west,  | 
         | 
   873     legend cell align=left]  | 
         | 
   874 \addplot[blue,mark=*, mark options={fill=white}] table {re-python2.data};    | 
         | 
   875 \addplot[cyan,mark=*, mark options={fill=white}] table {re-java.data}; | 
         | 
   876 \addplot[red,mark=*, mark options={fill=white}] table {re-js.data}; | 
         | 
   877 \addplot[magenta,mark=*, mark options={fill=white}] table {re-swift.data}; | 
         | 
   878 \end{axis} | 
         | 
   879 \end{tikzpicture} | 
         | 
   880 %  | 
         | 
   881 \end{column} | 
         | 
   882 \begin{column}{.5\textwidth} | 
   702 \small{}Us (after next lecture)\medskip\\ | 
   883 \small{}Us (after next lecture)\medskip\\ | 
   703 \begin{tikzpicture}\footnotesize | 
   884 \begin{tikzpicture}\footnotesize | 
   704 \begin{axis}[ | 
   885 \begin{axis}[ | 
   705     xlabel={$n$}, | 
   886     xlabel={$n$}, | 
   706     x label style={at={(1.07,0.0)}}, | 
   887     x label style={at={(1.07,0.0)}}, |