| 876 |      1 | % !TEX program = xelatex
 | 
|  |      2 | \documentclass[dvipsnames,14pt,t,xelatex,aspectratio=169,xcolor={table}]{beamer}
 | 
|  |      3 | \usepackage{../slides}
 | 
|  |      4 | \usepackage{../graphicss}
 | 
|  |      5 | \usepackage{../langs}
 | 
|  |      6 | \usepackage{../data}
 | 
|  |      7 | \usetikzlibrary{cd}
 | 
|  |      8 | 
 | 
|  |      9 | 
 | 
|  |     10 | \usepackage{tcolorbox}
 | 
|  |     11 | \newtcolorbox{mybox}{colback=red!5!white,colframe=red!75!black}
 | 
|  |     12 | \newtcolorbox{mybox2}[1]{colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries,title=#1}
 | 
|  |     13 | \newtcolorbox{mybox3}[1]{colback=Cyan!5!white,colframe=Cyan!75!black,fonttitle=\bfseries,title=#1}
 | 
|  |     14 | 
 | 
|  |     15 | 
 | 
|  |     16 | 
 | 
|  |     17 | \hfuzz=220pt 
 | 
|  |     18 | 
 | 
|  |     19 | \lstset{language=Scala,
 | 
|  |     20 |         style=mystyle,
 | 
|  |     21 |         numbersep=0pt,
 | 
|  |     22 |         numbers=none,
 | 
|  |     23 |         xleftmargin=0mm}
 | 
|  |     24 | 
 | 
|  |     25 | \newcommand{\bl}[1]{\textcolor{blue}{#1}}     
 | 
|  |     26 |  
 | 
|  |     27 | % beamer stuff 
 | 
|  |     28 | \renewcommand{\slidecaption}{CFL 01, King's College London}
 | 
|  |     29 | 
 | 
|  |     30 | %% https://cs.rit.edu/~hh/teaching/_media/cc18/lectures/lect1/main.pdf
 | 
|  |     31 | %% https://cs.rit.edu/~hh/teaching/_media/cc18/lectures/lect2/main.pdf
 | 
|  |     32 | %% https://cs.rit.edu/~hh/teaching/_media/cc18/lectures/lect3/main.pdf
 | 
|  |     33 | 
 | 
|  |     34 | \begin{document}
 | 
|  |     35 | 
 | 
|  |     36 | %\begin{frame}[t]
 | 
|  |     37 | %
 | 
|  |     38 | %\begin{mybox}
 | 
|  |     39 | %A physical explanation the \emph{dynamic matrix}\\
 | 
|  |     40 | %lots of text
 | 
|  |     41 | %\end{mybox}
 | 
|  |     42 | 
 | 
|  |     43 | 
 | 
|  |     44 | %\begin{mybox2}{Test}
 | 
|  |     45 | %A physical explanation the \emph{dynamic matrix}\\
 | 
|  |     46 | %lots of text
 | 
|  |     47 | %\end{mybox2}
 | 
|  |     48 | 
 | 
|  |     49 | %\begin{mybox3}{Test}
 | 
|  |     50 | %A physical explanation the \emph{dynamic matrix}\\
 | 
|  |     51 | %lots of text
 | 
|  |     52 | %\end{mybox3}
 | 
|  |     53 | %\end{frame}
 | 
|  |     54 | 
 | 
|  |     55 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |     56 | \begin{frame}[t]
 | 
|  |     57 | \frametitle{%  
 | 
|  |     58 |   \begin{tabular}{@ {}c@ {}}
 | 
|  |     59 |   \\[-3mm]
 | 
|  |     60 |   \LARGE Compilers and \\[-1mm] 
 | 
|  |     61 |   \LARGE Formal Languages\\[-3mm] 
 | 
|  |     62 |   \end{tabular}}
 | 
|  |     63 | 
 | 
|  |     64 |   \begin{center}
 | 
|  |     65 |   %\includegraphics[scale=0.3]{pics/ante1.jpg}\hspace{5mm}
 | 
|  |     66 |   %\includegraphics[scale=0.31]{pics/ante2.jpg}\\
 | 
|  |     67 |   %\footnotesize\textcolor{gray}{Antikythera automaton, 100 BC (Archimedes?)}
 | 
|  |     68 |   \end{center}
 | 
|  |     69 | 
 | 
|  |     70 |   \normalsize
 | 
|  |     71 |   \begin{center}
 | 
|  |     72 |   \begin{tabular}{ll}
 | 
|  |     73 |   Email:  & christian.urban at kcl.ac.uk\\
 | 
|  |     74 |   %Office Hours: & Thursdays 12 -- 14\\
 | 
|  |     75 |   %Location: & N7.07 (North Wing, Bush House)\\
 | 
|  |     76 |   Slides \& Progs: & KEATS\\
 | 
|  |     77 |   \end{tabular}
 | 
|  |     78 |   \end{center}
 | 
|  |     79 | 
 | 
|  |     80 |   \begin{center}
 | 
|  |     81 |     \begin{tikzpicture}
 | 
|  |     82 |       \node[drop shadow,fill=white,inner sep=0pt] 
 | 
|  |     83 |       {\footnotesize\rowcolors{1}{capri!10}{white}
 | 
|  |     84 |         \begin{tabular}{|p{4.8cm}|p{4.8cm}|}\hline
 | 
|  |     85 |           \cellcolor{blue!50}
 | 
|  |     86 |           1 Introduction, Languages          & 6 While-Language \\
 | 
|  |     87 |           2 Regular Expressions, Derivatives & 7 Compilation, JVM \\
 | 
|  |     88 |           3 Automata, Regular Languages      & 8 Compiling Functional Languages \\
 | 
|  |     89 |           4 Lexing, Tokenising               & 9 Optimisations \\
 | 
|  |     90 |           5 Grammars, Parsing                & 10 LLVM \\ \hline
 | 
|  |     91 |         \end{tabular}%
 | 
|  |     92 |       };
 | 
|  |     93 |     \end{tikzpicture}
 | 
|  |     94 |   \end{center}
 | 
|  |     95 | 
 | 
|  |     96 | \end{frame}
 | 
|  |     97 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |     98 | 
 | 
|  |     99 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    100 | \begin{frame}<1-12>[c]
 | 
|  |    101 | \frametitle{The Goal of this Module\ldots}
 | 
|  |    102 | 
 | 
|  |    103 | \begin{center}
 | 
|  |    104 |   \begin{tikzpicture}[scale=1,
 | 
|  |    105 |                       node/.style={
 | 
|  |    106 |                       rectangle,rounded corners=3mm,
 | 
|  |    107 |                       very thick,draw=black!50,minimum height=18mm, minimum width=20mm,
 | 
|  |    108 |                       top color=white,bottom color=black!20,drop shadow}]
 | 
|  |    109 | 
 | 
|  |    110 |   \node at (3.05, 1.8) {\Large\bf \ldots{} you write a compiler};
 | 
|  |    111 | 
 | 
|  |    112 |   \node (0) at (-2.3,0) {};  
 | 
|  |    113 |   \node [above=5mm of 0]
 | 
|  |    114 |   {\makebox[0mm]{\footnotesize
 | 
|  |    115 |       \begin{tabular}{@{}l@{}}input\\[-1mm]program\end{tabular}}}; 
 | 
|  |    116 |      
 | 
|  |    117 |   \node (A) at (0,0)  [node] {};
 | 
|  |    118 |   \node [below right] at (A.north west) {lexer};
 | 
|  |    119 | 
 | 
|  |    120 |   \node (B) at (3,0)  [node] {};
 | 
|  |    121 |   \node [below right=1mm] at (B.north west) {\mbox{}\hspace{-1mm}parser};
 | 
|  |    122 | 
 | 
|  |    123 |   \node (C) at (6,0)  [node] {};
 | 
|  |    124 |   \node [below right] at (C.north west) {\mbox{}\hspace{-1mm}code gen};
 | 
|  |    125 | 
 | 
|  |    126 |   \node (1) at (8.4,0) {};
 | 
|  |    127 |   \node [above=5mm of 1]
 | 
|  |    128 |   {\makebox[0mm]{\footnotesize
 | 
|  |    129 |       \begin{tabular}{@{}r@{}}binary\\[-1mm]code\end{tabular}}};
 | 
|  |    130 | 
 | 
|  |    131 |   \draw [->,line width=4mm] (0) -- (A); 
 | 
|  |    132 |   \draw [->,line width=4mm] (A) -- (B); 
 | 
|  |    133 |   \draw [->,line width=4mm] (B) -- (C); 
 | 
|  |    134 |   \draw [->,line width=4mm] (C) -- (1); 
 | 
|  |    135 |   \end{tikzpicture}
 | 
|  |    136 |   \end{center}
 | 
|  |    137 | 
 | 
|  |    138 | \only<2,3,4>{
 | 
|  |    139 | \begin{textblock}{1}(1,2.1)
 | 
|  |    140 | \begin{bubble}[9.8cm]
 | 
|  |    141 | \normalsize
 | 
|  |    142 | lexer input: a string\smallskip\\
 | 
|  |    143 | \hspace{5mm}\code{"read(n);"}\medskip\\
 | 
|  |    144 | lexer output: a sequence of tokens\smallskip\\
 | 
|  |    145 | \hspace{5mm}\code{key(read) lpar id(n) rpar semi}
 | 
|  |    146 | \end{bubble}
 | 
|  |    147 | \end{textblock}} 
 | 
|  |    148 | 
 | 
|  |    149 | \only<3,4>{
 | 
|  |    150 | \begin{textblock}{1}(6,7.8)
 | 
|  |    151 | \begin{tabular}{c}
 | 
|  |    152 | \includegraphics[scale=0.2]{../pics/rosetta.jpg}\\[-2mm]
 | 
|  |    153 | \footnotesize lexing $\Rightarrow$ recognising words (Stone of Rosetta)
 | 
|  |    154 | \end{tabular}
 | 
|  |    155 | \end{textblock}}
 | 
|  |    156 | 
 | 
|  |    157 | \only<4>{
 | 
|  |    158 | \begin{textblock}{1}(0.5,12)\small
 | 
|  |    159 | \begin{tabular}{l@{}c@{}l}
 | 
|  |    160 |   \pcode{if}    & $\;\Rightarrow\;$ & keyword\\
 | 
|  |    161 |   \pcode{iffoo} & $\;\Rightarrow\;$ & identifier\\
 | 
|  |    162 | \end{tabular}  
 | 
|  |    163 | \end{textblock}}
 | 
|  |    164 | 
 | 
|  |    165 | \only<6>{
 | 
|  |    166 | \begin{textblock}{1}(1,1.5)
 | 
|  |    167 | \begin{bubble}[8.5cm]
 | 
|  |    168 | \normalsize
 | 
|  |    169 | parser input: a sequence of tokens\smallskip\\
 | 
|  |    170 | 
 | 
|  |    171 | {\small\hspace{5mm}\code{key(read) lpar id(n) rpar semi}}\smallskip\\
 | 
|  |    172 | 
 | 
|  |    173 | parser output: an abstract syntax tree\smallskip\\
 | 
|  |    174 | \footnotesize
 | 
|  |    175 | \hspace{2cm}\begin{tikzpicture}
 | 
|  |    176 |   \node {\code{read}}
 | 
|  |    177 |     child {node {\code{lpar}}}
 | 
|  |    178 |     child {node {\code{n}}}
 | 
|  |    179 |     child {node {\code{rpar}}};
 | 
|  |    180 | \end{tikzpicture}
 | 
|  |    181 | \end{bubble}
 | 
|  |    182 | \end{textblock}}
 | 
|  |    183 | 
 | 
|  |    184 | \only<8,9>{
 | 
|  |    185 | \begin{textblock}{1}(1,1.5)
 | 
|  |    186 | \begin{bubble}[4cm]
 | 
|  |    187 | \normalsize
 | 
|  |    188 | code generation:\smallskip\\
 | 
|  |    189 | \hspace{5mm}\code{istore 2}\\ 
 | 
|  |    190 | \hspace{5mm}\code{iload 2}\\ 
 | 
|  |    191 | \hspace{5mm}\code{ldc 10}\\
 | 
|  |    192 | \hspace{5mm}\code{isub}\\
 | 
|  |    193 | \hspace{5mm}\code{ifeq Label2}\\ 
 | 
|  |    194 | \hspace{5mm}\code{iload 2}\\
 | 
|  |    195 | \hspace{5mm}\code{...}\\
 | 
|  |    196 | \end{bubble}
 | 
|  |    197 | \end{textblock}}
 | 
|  |    198 | 
 | 
|  |    199 | \only<9>{
 | 
|  |    200 | \begin{textblock}{6}(8.4,7)
 | 
|  |    201 | \begin{bubble}[5cm]
 | 
|  |    202 | \mbox{\begin{tikzpicture}[scale=0.58,rounded corners=0mm]
 | 
|  |    203 | \begin{axis}[axis x line=bottom, axis y line=left, ylabel=secs,
 | 
|  |    204 |     xlabel=n,
 | 
|  |    205 |     enlargelimits=0.05,
 | 
|  |    206 |     ybar interval=0.7, legend style=small]
 | 
|  |    207 | \addplot file {interpreted2.data};
 | 
|  |    208 | \addplot file {compiled2.data};
 | 
|  |    209 | %\legend{interpreted, compiled}
 | 
|  |    210 | \end{axis}
 | 
|  |    211 | \end{tikzpicture}}
 | 
|  |    212 | \end{bubble}
 | 
|  |    213 | \end{textblock}}
 | 
|  |    214 | 
 | 
|  |    215 | \only<10>{
 | 
|  |    216 | \begin{textblock}{6}(1,3)
 | 
|  |    217 |   \begin{bubble}[11cm]
 | 
|  |    218 |     Compiler explorers, e.g.: \url{https://gcc.godbolt.org} \;\video{https://youtu.be/ysaBmhMEyUg}
 | 
|  |    219 |   \begin{tikzpicture}[]
 | 
|  |    220 |   \node (0) at (-2.3,0) {\includegraphics[scale=0.3]{pics/csource.png}};
 | 
|  |    221 |   \node (1) [right=35mm] at (0) {\includegraphics[scale=0.3]{pics/cassmbl.png}}; 
 | 
|  |    222 |   \draw [->,line width=4mm, red] (0) -- (1);   
 | 
|  |    223 |   \node (2) [below=20mm] at (0) {\LARGE\bf source};
 | 
|  |    224 |   \node (3) [right=40mm] at (2) {\LARGE\bf binary};
 | 
|  |    225 |   \draw [->,line width=1mm] (2) -- (3);   
 | 
|  |    226 | \end{tikzpicture}
 | 
|  |    227 | \end{bubble}
 | 
|  |    228 | 
 | 
|  |    229 | \end{textblock}}
 | 
|  |    230 | \only<11>{
 | 
|  |    231 | \begin{textblock}{6}(1,3)
 | 
|  |    232 |   \begin{bubble}[11cm]
 | 
|  |    233 |     Compiler explorer for Java: \url{https://javap.yawk.at} 
 | 
|  |    234 |   \begin{tikzpicture}[]
 | 
|  |    235 |   \node (0) at (-2.3,0) {\includegraphics[scale=0.4]{pics/jsource.png}};
 | 
|  |    236 |   \node (1) [right=35mm] at (0) {\includegraphics[scale=0.4]{pics/jassmbl.png}}; 
 | 
|  |    237 |   \draw [->,line width=4mm, red] (0) -- (1);   
 | 
|  |    238 |   \node (2) [below=20mm] at (0) {\LARGE\bf source};
 | 
|  |    239 |   \node (3) [right=40mm] at (2) {\LARGE\bf byte code};
 | 
|  |    240 |   \draw [->,line width=1mm] (2) -- (3);   
 | 
|  |    241 | \end{tikzpicture}
 | 
|  |    242 | \end{bubble}
 | 
|  |    243 | \end{textblock}}
 | 
|  |    244 | 
 | 
|  |    245 | 
 | 
|  |    246 | \end{frame}
 | 
|  |    247 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 | 
|  |    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 | \begin{frame}[c]
 | 
|  |    299 | \frametitle{Why Bother with Compilers?}
 | 
|  |    300 |   
 | 
|  |    301 | \textbf{Boeing 777's}: First flight in 1994. They want to achieve
 | 
|  |    302 | triple redundancy for potential hardware faults.
 | 
|  |    303 | \here{http://www.citemaster.net/get/db3a81c6-548e-11e5-9d2e-00163e009cc7/R8.pdf}\bigskip
 | 
|  |    304 |   
 | 
|  |    305 | They compile 1 Ada program to\medskip
 | 
|  |    306 |   
 | 
|  |    307 | \begin{itemize}
 | 
|  |    308 |   \item Intel 80486
 | 
|  |    309 |   \item Motorola 68040 (old Macintosh's)
 | 
|  |    310 |   \item AMD 29050 (RISC chips used often in laser printers)
 | 
|  |    311 | \end{itemize}\medskip\medskip
 | 
|  |    312 |   
 | 
|  |    313 | using 3 independent compilers.\bigskip\pause
 | 
|  |    314 |   
 | 
|  |    315 | \small Airbus uses C and static analysers. Recently started using CompCert.
 | 
|  |    316 | 
 | 
|  |    317 | \only<1->{%
 | 
|  |    318 | \begin{textblock}{6}(8,4.5)
 | 
|  |    319 | \includegraphics[scale=0.28]{../pics/777.png}
 | 
|  |    320 | \end{textblock}}
 | 
|  |    321 | 
 | 
|  |    322 | \end{frame}
 | 
|  |    323 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    324 | 
 | 
|  |    325 | 
 | 
|  |    326 | 
 | 
|  |    327 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    328 | \begin{frame}[c]
 | 
|  |    329 | \frametitle{What Do Compilers Do?}
 | 
|  |    330 | 
 | 
|  |    331 | Remember BF*** from PEP?
 | 
|  |    332 | 
 | 
|  |    333 | \begin{center}
 | 
|  |    334 | \begin{tabular}{rcl}
 | 
|  |    335 | \bl{\texttt{>}} & $\Rightarrow$ & move one cell right\\
 | 
|  |    336 | \bl{\texttt{<}} & $\Rightarrow$ & move one cell left\\
 | 
|  |    337 | \bl{\texttt{+}} & $\Rightarrow$ & increase cell by one\\
 | 
|  |    338 | \bl{\texttt{-}} & $\Rightarrow$ & decrease cell by one\\
 | 
|  |    339 | \bl{\texttt{.}} & $\Rightarrow$ & print current cell\\
 | 
|  |    340 | \bl{\texttt{,}} & $\Rightarrow$ & input current cell\\
 | 
|  |    341 | \bl{\texttt{[}} & $\Rightarrow$ & loop begin\\
 | 
|  |    342 | \bl{\texttt{]}} & $\Rightarrow$ & loop end\medskip\\
 | 
|  |    343 |                 & $\Rightarrow$ & everything else is a comment\\
 | 
|  |    344 | \end{tabular}  
 | 
|  |    345 | \end{center}  
 | 
|  |    346 | 
 | 
|  |    347 | \end{frame}
 | 
|  |    348 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    349 | 
 | 
|  |    350 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    351 | \begin{frame}[c]
 | 
|  |    352 |   \frametitle{A ``Compiler'' for BF*** to C}
 | 
|  |    353 |   
 | 
|  |    354 |   \begin{center}
 | 
|  |    355 |   \begin{tabular}{rcl}
 | 
|  |    356 |   \bl{\texttt{>}} & $\Rightarrow$ & \texttt{ptr++}\\
 | 
|  |    357 |   \bl{\texttt{<}} & $\Rightarrow$ & \texttt{ptr--}\\
 | 
|  |    358 |   \bl{\texttt{+}} & $\Rightarrow$ & \texttt{(*ptr)++}\\
 | 
|  |    359 |   \bl{\texttt{-}} & $\Rightarrow$ & \texttt{(*ptr)--}\\
 | 
|  |    360 |   \bl{\texttt{.}} & $\Rightarrow$ & \texttt{putchar(*ptr)}\\
 | 
|  |    361 |   \bl{\texttt{,}} & $\Rightarrow$ & \texttt{*ptr = getchar()}\\
 | 
|  |    362 |   \bl{\texttt{[}} & $\Rightarrow$ & \texttt{while(*ptr)\{}\\
 | 
|  |    363 |   \bl{\texttt{]}} & $\Rightarrow$ & \texttt{\}}\medskip\\
 | 
|  |    364 |                   & $\Rightarrow$ & ignore everything else\\
 | 
|  |    365 |   \end{tabular}  
 | 
|  |    366 |   \end{center}\bigskip  
 | 
|  |    367 |   
 | 
|  |    368 |   \texttt{char field[30000]\\ char *ptr = \&field[15000]}
 | 
|  |    369 |   
 | 
|  |    370 | \end{frame}
 | 
|  |    371 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    372 | 
 | 
|  |    373 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    374 | \begin{frame}[c]
 | 
|  |    375 |   \frametitle{Another~``Compiler''~for~BF~to~C}
 | 
|  |    376 |   
 | 
|  |    377 |   \begin{center}
 | 
|  |    378 |   \begin{tabular}{rcl}
 | 
|  |    379 |   \bl{\texttt{>\ldots>}} & $\Rightarrow$ & \texttt{ptr += n}\\
 | 
|  |    380 |   \bl{\texttt{<\ldots<}} & $\Rightarrow$ & \texttt{ptr -= n}\\
 | 
|  |    381 |   \bl{\texttt{+\ldots+}} & $\Rightarrow$ & \texttt{(*ptr) += n}\\
 | 
|  |    382 |   \bl{\texttt{-\ldots-}} & $\Rightarrow$ & \texttt{(*ptr) -= n}\\
 | 
|  |    383 |   \bl{\texttt{.}} & $\Rightarrow$ & \texttt{putchar(*ptr)}\\
 | 
|  |    384 |   \bl{\texttt{,}} & $\Rightarrow$ & \texttt{*ptr = getchar()}\\
 | 
|  |    385 |   \bl{\texttt{[}} & $\Rightarrow$ & \texttt{while(*ptr)\{}\\
 | 
|  |    386 |   \bl{\texttt{]}} & $\Rightarrow$ & \texttt{\}}\medskip\\
 | 
|  |    387 |                   & $\Rightarrow$ & ignore everything else\\
 | 
|  |    388 |   \end{tabular}  
 | 
|  |    389 |   \end{center}\bigskip  
 | 
|  |    390 |   
 | 
|  |    391 |   \texttt{char field[30000]\\ char *ptr = \&field[15000]}
 | 
|  |    392 |   
 | 
|  |    393 | \end{frame}
 | 
|  |    394 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    395 |     
 | 
|  |    396 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    397 | \begin{frame}[t]
 | 
|  |    398 | \frametitle{A Brief Compiler History}
 | 
|  |    399 | 
 | 
|  |    400 | \bigskip
 | 
|  |    401 | \begin{itemize}
 | 
|  |    402 | \item Turing Machines, 1936 (a tape as memory)
 | 
|  |    403 | \item Regular Expressions, 1956\\
 | 
|  |    404 | \item The first compiler for COBOL, 1957\\ (Grace Hopper)\medskip
 | 
|  |    405 | \item But surprisingly research papers are still published nowadays\\
 | 
|  |    406 | \item ``Parsing: The Solved Problem That Isn't''
 | 
|  |    407 |   \here{https://tratt.net/laurie/blog/entries/parsing_the_solved_problem_that_isnt.html}
 | 
|  |    408 | \end{itemize}
 | 
|  |    409 | 
 | 
|  |    410 | 
 | 
|  |    411 | \begin{textblock}{8.5}(5,7.6)
 | 
|  |    412 | \begin{flushright}
 | 
|  |    413 | \includegraphics[scale=0.3]{pics/hopper.jpg}\\
 | 
|  |    414 | \footnotesize\textcolor{gray}{Grace Hopper}\smallskip\\
 | 
|  |    415 | 
 | 
|  |    416 | {\small\textcolor{gray}{(she made it to David Letterman's Tonight Show
 | 
|  |    417 |  \here{https://youtu.be/3N_ywhx6_K0?t=31})}}
 | 
|  |    418 | \end{flushright}
 | 
|  |    419 | \end{textblock}
 | 
|  |    420 | 
 | 
|  |    421 | \end{frame}
 | 
|  |    422 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 | 
|  |    423 | 
 | 
|  |    424 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    425 | \begin{frame}[c]
 | 
|  |    426 | \frametitle{Some Housekeeping}
 | 
|  |    427 | 
 | 
|  |    428 | \textbf{Exam will be online:}\bigskip
 | 
|  |    429 | 
 | 
|  |    430 | \begin{itemize}
 | 
|  |    431 | \item final exam in January (35\%)
 | 
|  |    432 | \item five CWs (65\%) 
 | 
|  |    433 | \end{itemize}\bigskip\bigskip\pause
 | 
|  |    434 | 
 | 
|  |    435 | 
 | 
|  |    436 | \textbf{Weekly Homework (optional):}
 | 
|  |    437 | \begin{itemize}
 | 
|  |    438 | \item uploaded on KEATS, send answers via email, (try to!) respond individually
 | 
|  |    439 | \item \alert{\bf all} questions in the exam will be from the HWs!!
 | 
|  |    440 | \end{itemize}  
 | 
|  |    441 | 
 | 
|  |    442 | \end{frame}
 | 
|  |    443 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 | 
|  |    444 | 
 | 
|  |    445 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    446 | \begin{frame}[c]
 | 
|  |    447 | \frametitle{Some Housekeeping}
 | 
|  |    448 | 
 | 
|  |    449 | \textbf{Coursework (5 accounting for 65\%):}\bigskip
 | 
|  |    450 | 
 | 
|  |    451 | \begin{itemize}
 | 
|  |    452 | \item matcher (5\%)
 | 
|  |    453 | \item lexer (10\%)
 | 
|  |    454 | \item parser / interpreter (10\%)
 | 
|  |    455 | \item JVM compiler (15\%)
 | 
|  |    456 | \item LLVM compiler (25\%) 
 | 
|  |    457 | \end{itemize}\bigskip\pause
 | 
|  |    458 | 
 | 
|  |    459 | you can use \alert{any} programming language you like (Haskell, Rust)\\\pause
 | 
|  |    460 | you can use any code I show you and is uploaded to KEATS\ldots\textbf{BUT NOTHING ELSE!}
 | 
|  |    461 | 
 | 
|  |    462 | \end{frame}
 | 
|  |    463 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 | 
|  |    464 | 
 | 
|  |    465 | 
 | 
|  |    466 | 
 | 
|  |    467 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    468 | \begin{frame}[c]
 | 
|  |    469 | \frametitle{Lectures 1 - 5}
 | 
|  |    470 | 
 | 
|  |    471 | transforming strings into structured data\\[10mm]
 | 
|  |    472 | 
 | 
|  |    473 | {\LARGE\bf Lexing} {\hfill{}based on regular expressions}\medskip\\
 | 
|  |    474 | \hspace{5mm}(recognising ``words'')\\[6mm]
 | 
|  |    475 | 
 | 
|  |    476 | {\LARGE\bf Parsing}\medskip\\
 | 
|  |    477 | \hspace{5mm}(recognising ``sentences'')
 | 
|  |    478 | 
 | 
|  |    479 | \begin{textblock}{1}(10,9.1)
 | 
|  |    480 | \begin{tabular}{c}
 | 
|  |    481 | \includegraphics[scale=0.1]{../pics/rosetta.jpg}\\[-2mm]
 | 
|  |    482 | \footnotesize Stone of Rosetta
 | 
|  |    483 | \end{tabular}
 | 
|  |    484 | \end{textblock}
 | 
|  |    485 | 
 | 
|  |    486 | \end{frame}
 | 
|  |    487 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    488 | 
 | 
|  |    489 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    490 | \begin{frame}[c]
 | 
|  |    491 | \frametitle{Lectures 1 - 5}
 | 
|  |    492 | 
 | 
|  |    493 | transforming strings into structured data\\[10mm]
 | 
|  |    494 | 
 | 
|  |    495 | {\LARGE\bf Lexing} {\hfill{}based on regular expressions}\medskip\\
 | 
|  |    496 | \hspace{5mm}(recognising ``words'')\\[6mm]
 | 
|  |    497 | 
 | 
|  |    498 | {\LARGE\bf Parsing}\medskip\\
 | 
|  |    499 | \hspace{5mm}(recognising ``sentences'')
 | 
|  |    500 | 
 | 
|  |    501 | \begin{textblock}{1}(10,9.1)
 | 
|  |    502 | \begin{tabular}{c}
 | 
|  |    503 | \includegraphics[scale=0.1]{../pics/rosetta.jpg}\\[-2mm]
 | 
|  |    504 | \footnotesize Stone of Rosetta
 | 
|  |    505 | \end{tabular}
 | 
|  |    506 | \end{textblock}
 | 
|  |    507 | 
 | 
|  |    508 | \end{frame}
 | 
|  |    509 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    510 | 
 | 
|  |    511 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    512 | \begin{frame}[c]
 | 
|  |    513 |   \frametitle{Lectures 5 - 10}
 | 
|  |    514 |   
 | 
|  |    515 |   code generation for a small imperative and a small functional language\\[10mm]
 | 
|  |    516 |   
 | 
|  |    517 |   {\LARGE\bf Interpreters}\medskip\\
 | 
|  |    518 |   \hspace{5mm}(directly runs a program)\\[6mm]
 | 
|  |    519 |   
 | 
|  |    520 |   {\LARGE\bf Compilers}\medskip\\
 | 
|  |    521 |   \hspace{5mm}(generate JVM code and LLVM-IR code)
 | 
|  |    522 |   
 | 
|  |    523 |   \begin{textblock}{1}(8.8,8.1)
 | 
|  |    524 |   \begin{tabular}{c@{}c}
 | 
|  |    525 |     \includegraphics[scale=0.4]{../pics/javaduke.png} &
 | 
|  |    526 |     \includegraphics[scale=0.23]{../pics/llvmlogo.png}
 | 
|  |    527 |   \end{tabular}
 | 
|  |    528 |   \end{textblock}
 | 
|  |    529 |   
 | 
|  |    530 |   \end{frame}
 | 
|  |    531 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    532 |   
 | 
|  |    533 | 
 | 
|  |    534 | 
 | 
|  |    535 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    536 | \begin{frame}[t]
 | 
|  |    537 | \frametitle{Familiar Regular Expresssions}
 | 
|  |    538 | \small
 | 
|  |    539 | \begin{center}
 | 
|  |    540 | \texttt{[a-z0-9\_$\backslash{}$.-]+ @ [a-z0-9$\backslash{}$.-]+ . [a-z$\backslash{}$.]\{2,6\}}
 | 
|  |    541 | \end{center}\smallskip
 | 
|  |    542 | 
 | 
|  |    543 | \begin{center}
 | 
|  |    544 | \begin{tabular}{@{}lp{8.5cm}@{}}
 | 
|  |    545 | \pcode{re*} & matches 0 or more times\\
 | 
|  |    546 | \pcode{re+} & matches 1 or more times\\
 | 
|  |    547 | \pcode{re?} & matches 0 or 1 times\\
 | 
|  |    548 | \pcode{re\{n\}}	& matches exactly \pcode{n} number of times\\
 | 
|  |    549 | \pcode{re\{n,m\}} & matches at least \pcode{n} and at most {\tt m} times\\
 | 
|  |    550 | \pcode{[...]} & matches any single character inside the brackets\\
 | 
|  |    551 | \pcode{[^...]} & matches any single character not inside the 
 | 
|  |    552 | brackets\\
 | 
|  |    553 | \pcode{a-z A-Z} & character ranges\\
 | 
|  |    554 | \pcode{\\d} & matches digits; equivalent to \pcode{[0-9]}\\
 | 
|  |    555 | \pcode{.} & matches every character except newline\\
 | 
|  |    556 | \pcode{(re)}	& groups regular expressions and remembers 
 | 
|  |    557 | the matched text
 | 
|  |    558 | \end{tabular}
 | 
|  |    559 | \end{center}
 | 
|  |    560 | 
 | 
|  |    561 | \end{frame}
 | 
|  |    562 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    563 | 
 | 
|  |    564 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    565 | \begin{frame}[c]
 | 
|  |    566 | \frametitle{Some ``innocent'' examples}
 | 
|  |    567 | 
 | 
|  |    568 | Let's try two examples
 | 
|  |    569 | 
 | 
|  |    570 | \begin{center}
 | 
|  |    571 |   \bl{\texttt{(a*)*b}}
 | 
|  |    572 |   \hspace{2cm}
 | 
|  |    573 |   \bl{\texttt{[a?]\{n\}[a]\{n\}}}
 | 
|  |    574 | \end{center}\bigskip\pause  
 | 
|  |    575 | 
 | 
|  |    576 | and match them with strings of the form
 | 
|  |    577 | 
 | 
|  |    578 | \begin{center}
 | 
|  |    579 |   \bl{\texttt{a}},
 | 
|  |    580 |   \bl{\texttt{aa}},
 | 
|  |    581 |   \bl{\texttt{aaa}},
 | 
|  |    582 |   \bl{\texttt{aaaa}},
 | 
|  |    583 |   \bl{\texttt{aaaaa}},
 | 
|  |    584 |   \bl{$\underbrace{\texttt{a}...\texttt{a}}_n$}  
 | 
|  |    585 | \end{center}  
 | 
|  |    586 | 
 | 
|  |    587 | \end{frame}
 | 
|  |    588 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    589 | 
 | 
|  |    590 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    591 | \begin{frame}[c]
 | 
|  |    592 | \frametitle{Why Bother with Regexes?}
 | 
|  |    593 | 
 | 
|  |    594 | \begin{columns}[t,onlytextwidth]
 | 
|  |    595 | \begin{column}{1.8cm}
 | 
|  |    596 | \mbox{}   
 | 
|  |    597 | \end{column}    
 | 
|  |    598 | \begin{column}{.5\textwidth}
 | 
|  |    599 | \small{}Ruby, Python, Java 8\medskip\\
 | 
|  |    600 | \begin{tikzpicture}\footnotesize
 | 
|  |    601 | \begin{axis}[
 | 
|  |    602 |     xlabel={$n$},
 | 
|  |    603 |     x label style={at={(1.05,0.0)}},
 | 
|  |    604 |     ylabel={time in secs},
 | 
|  |    605 |     enlargelimits=false,
 | 
|  |    606 |     xtick={0,5,...,30},
 | 
|  |    607 |     xmax=33,
 | 
|  |    608 |     ymax=35,
 | 
|  |    609 |     ytick={0,5,...,30},
 | 
|  |    610 |     scaled ticks=false,
 | 
|  |    611 |     axis lines=left,
 | 
|  |    612 |     width=\textwidth,
 | 
|  |    613 |     height=4cm, 
 | 
|  |    614 |     legend entries={Python,Ruby},  
 | 
|  |    615 |     legend pos=north west,
 | 
|  |    616 |     legend cell align=left]
 | 
|  |    617 | \addplot[blue,mark=*, mark options={fill=white}] table {re-python.data};
 | 
|  |    618 | \addplot[brown,mark=triangle*, mark options={fill=white}] table {re-ruby.data};
 | 
|  |    619 | \end{axis}
 | 
|  |    620 | \end{tikzpicture}
 | 
|  |    621 | \begin{tikzpicture}\footnotesize
 | 
|  |    622 | \begin{axis}[
 | 
|  |    623 |     xlabel={$n$},
 | 
|  |    624 |     x label style={at={(1.05,0.0)}},
 | 
|  |    625 |     ylabel={time in secs},
 | 
|  |    626 |     enlargelimits=false,
 | 
|  |    627 |     xtick={0,5,...,30},
 | 
|  |    628 |     xmax=33,
 | 
|  |    629 |     ymax=35,
 | 
|  |    630 |     ytick={0,5,...,30},
 | 
|  |    631 |     scaled ticks=false,
 | 
|  |    632 |     axis lines=left,
 | 
|  |    633 |     width=\textwidth,
 | 
|  |    634 |     height=4cm, 
 | 
|  |    635 |     legend entries={Python, Java 8, JavaScript, Swift},  
 | 
|  |    636 |     legend pos=north west,
 | 
|  |    637 |     legend cell align=left]
 | 
|  |    638 | \addplot[blue,mark=*, mark options={fill=white}] table {re-python2.data};   
 | 
|  |    639 | \addplot[cyan,mark=*, mark options={fill=white}] table {re-java.data};
 | 
|  |    640 | \addplot[red,mark=*, mark options={fill=white}] table {re-js.data};
 | 
|  |    641 | \addplot[magenta,mark=*, mark options={fill=white}] table {re-swift.data};
 | 
|  |    642 | \end{axis}
 | 
|  |    643 | \end{tikzpicture}
 | 
|  |    644 | %
 | 
|  |    645 | \end{column}
 | 
|  |    646 | \begin{column}{.5\textwidth}
 | 
|  |    647 | \small{}Us (after next lecture)\medskip\\
 | 
|  |    648 | \begin{tikzpicture}\footnotesize
 | 
|  |    649 | \begin{axis}[
 | 
|  |    650 |     xlabel={$n$},
 | 
|  |    651 |     x label style={at={(1.07,0.0)}},
 | 
|  |    652 |     ylabel={time in secs},
 | 
|  |    653 |     enlargelimits=false,
 | 
|  |    654 |     xtick={0,5000,...,10000},
 | 
|  |    655 |     xmax=11000,
 | 
|  |    656 |     ymax=35,
 | 
|  |    657 |     ytick={0,5,...,30},
 | 
|  |    658 |     scaled ticks=false,
 | 
|  |    659 |     axis lines=left,
 | 
|  |    660 |     width=\textwidth,
 | 
|  |    661 |     height=4cm]
 | 
|  |    662 | \addplot[green,mark=square*,mark options={fill=white}] table {re2.data};
 | 
|  |    663 | \addplot[black,mark=square*,mark options={fill=white}] table {re3.data};
 | 
|  |    664 | \end{axis}
 | 
|  |    665 | \end{tikzpicture}
 | 
|  |    666 | \begin{tikzpicture}\footnotesize
 | 
|  |    667 | \begin{axis}[
 | 
|  |    668 |     xlabel={$n$},
 | 
|  |    669 |     x label style={at={(1.07,0.0)}},
 | 
|  |    670 |     ylabel={time in secs},
 | 
|  |    671 |     enlargelimits=false,
 | 
|  |    672 |     ymax=35,
 | 
|  |    673 |     ytick={0,5,...,30},
 | 
|  |    674 |     scaled ticks=false,
 | 
|  |    675 |     axis lines=left,
 | 
|  |    676 |     width=\textwidth,
 | 
|  |    677 |     height=4cm]
 | 
|  |    678 | \addplot[black,mark=square*,mark options={fill=white}] table {re3a.data};
 | 
|  |    679 | \end{axis}
 | 
|  |    680 | \end{tikzpicture}
 | 
|  |    681 | \end{column}
 | 
|  |    682 | \end{columns}
 | 
|  |    683 | \medskip
 | 
|  |    684 | 
 | 
|  |    685 | \begin{textblock}{3}(-0.1,3.3)
 | 
|  |    686 | \small\hfill\bl{\texttt{[a?]\{n\}[a]\{n\}}}:
 | 
|  |    687 | \end{textblock}
 | 
|  |    688 | 
 | 
|  |    689 | \begin{textblock}{3}(-0.1,8.7)  
 | 
|  |    690 | \small\hfill\bl{\texttt{(a*)*b}}:
 | 
|  |    691 | \end{textblock}
 | 
|  |    692 | 
 | 
|  |    693 | \begin{textblock}{3}(0.3,13)
 | 
|  |    694 | \small{}matching with strings
 | 
|  |    695 | \bl{$\underbrace{\texttt{a}...\texttt{a}}_n$}  
 | 
|  |    696 | \end{textblock}
 | 
|  |    697 | 
 | 
|  |    698 | \end{frame} 
 | 
|  |    699 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
 | 
|  |    700 |     
 | 
|  |    701 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    702 | \begin{frame}[c,fragile]
 | 
|  |    703 |   \frametitle{Incidents}
 | 
|  |    704 |     
 | 
|  |    705 |   \begin{itemize}
 | 
|  |    706 |   \item a global outage on 2 July 2019 at \textbf{Cloudflare} 
 | 
|  |    707 |   (first one for six years)\medskip
 | 
|  |    708 |   
 | 
|  |    709 |   \begin{center}\small\color{blue}
 | 
|  |    710 |   \begin{verbatim}  
 | 
|  |    711 |   (?:(?:\"|'|\]|\}|\\|\d|(?:nan|infinity|true|false|
 | 
|  |    712 |   null|undefined|symbol|math)|\`|\-|\+)+[)]*;?((?:\s
 | 
|  |    713 |   |-|~|!|{}|\|\||\+)*.*(?:.*=.*)))  
 | 
|  |    714 |   \end{verbatim}
 | 
|  |    715 |   \end{center}\bigskip\bigskip\bigskip\bigskip\bigskip\bigskip\bigskip    
 | 
|  |    716 |   
 | 
|  |    717 |   \item on 20 July 2016 the \textbf{Stack Exchange} webpage went down
 | 
|  |    718 |     because of an evil regular expression
 | 
|  |    719 |     \here{https://stackstatus.net/post/147710624694/outage-postmortem-july-20-2016}    
 | 
|  |    720 |   \end{itemize}
 | 
|  |    721 |   
 | 
|  |    722 |   \begin{textblock}{6}(6,7.6)
 | 
|  |    723 |     \includegraphics[scale=0.14]{../pics/cloudflare.png}\\
 | 
|  |    724 |     \footnotesize
 | 
|  |    725 |     It serves more web traffic than Twitter, Amazon, Apple,
 | 
|  |    726 |     Instagram, Bing \& Wikipedia combined.
 | 
|  |    727 |     \here{https://blog.cloudflare.com/details-of-the-cloudflare-outage-on-july-2-2019/}
 | 
|  |    728 |     \end{textblock}
 | 
|  |    729 |   
 | 
|  |    730 |   \end{frame}
 | 
|  |    731 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 | 
|  |    732 |     
 | 
|  |    733 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    734 | \begin{frame}[c]
 | 
|  |    735 | \frametitle{Evil Regular Expressions}
 | 
|  |    736 | 
 | 
|  |    737 | \begin{itemize}
 | 
|  |    738 | \item \alert{R}egular \alert{e}xpression \alert{D}enial \alert{o}f \alert{S}ervice (ReDoS)\medskip
 | 
|  |    739 | \item Some evil regular expressions:\medskip
 | 
|  |    740 | \begin{itemize}
 | 
|  |    741 | \item \bl{\texttt{[a?]\{n\}\;[a]\{n\}}}
 | 
|  |    742 | \item \bl{\texttt{(a*)*\;b}}  
 | 
|  |    743 | \item \bl{\texttt{([a-z]+)*}} 
 | 
|  |    744 | \item \bl{\texttt{(a + aa)*}}
 | 
|  |    745 | \item \bl{\texttt{(a + a?)*}}
 | 
|  |    746 | \end{itemize}
 | 
|  |    747 | 
 | 
|  |    748 | \item sometimes also called \alert{catastrophic backtracking}
 | 
|  |    749 | \item this is a problem for \alert{N}etwork \alert{I}ntrusion
 | 
|  |    750 |   \alert{D}etection systems, Cloudflare, StackExchange, Atom editor
 | 
|  |    751 | \item \url{https://vimeo.com/112065252}  
 | 
|  |    752 | \end{itemize}
 | 
|  |    753 | 
 | 
|  |    754 | \end{frame}
 | 
|  |    755 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    756 | 
 | 
|  |    757 | 
 | 
|  |    758 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    759 | %\begin{frame}[c]
 | 
|  |    760 | %\frametitle{Today}
 | 
|  |    761 | %
 | 
|  |    762 | %\begin{itemize}
 | 
|  |    763 | %\item While the ultimate goal is to implement a small compiler for the JVM
 | 
|  |    764 | %  \ldots\bigskip
 | 
|  |    765 | %\end{itemize}
 | 
|  |    766 | %
 | 
|  |    767 | %Let's start with:
 | 
|  |    768 | %
 | 
|  |    769 | %\begin{itemize}
 | 
|  |    770 | %\item a web-crawler
 | 
|  |    771 | %\item an email harvester
 | 
|  |    772 | %\item \textcolor{gray}{(a web-scraper)}
 | 
|  |    773 | %\end{itemize}
 | 
|  |    774 | %
 | 
|  |    775 | %\end{frame}
 | 
|  |    776 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
 | 
|  |    777 | 
 | 
|  |    778 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    779 | %\begin{frame}[t]
 | 
|  |    780 | %\frametitle{A Web-Crawler}
 | 
|  |    781 | %
 | 
|  |    782 | %\mbox{}\\[10mm]
 | 
|  |    783 | %
 | 
|  |    784 | %\begin{enumerate}
 | 
|  |    785 | %\item given an URL, read the corresponding webpage
 | 
|  |    786 | %\item extract all links from it
 | 
|  |    787 | %\item call the web-crawler again for all these links
 | 
|  |    788 | %\end{enumerate}
 | 
|  |    789 | %
 | 
|  |    790 | %\end{frame}
 | 
|  |    791 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    792 | 
 | 
|  |    793 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    794 | %\begin{frame}[t]
 | 
|  |    795 | %\frametitle{A Web-Crawler}
 | 
|  |    796 | %
 | 
|  |    797 | %\mbox{}\\[10mm]
 | 
|  |    798 | %
 | 
|  |    799 | %
 | 
|  |    800 | %\begin{enumerate}
 | 
|  |    801 | %\item given an URL, read the corresponding webpage
 | 
|  |    802 | %\item if not possible print, out a problem
 | 
|  |    803 | %\item if possible, extract all links from it
 | 
|  |    804 | %\item call the web-crawler again for all these links
 | 
|  |    805 | %\end{enumerate}\bigskip\pause
 | 
|  |    806 | %
 | 
|  |    807 | %\small (we need a bound for the number of recursive calls)
 | 
|  |    808 | %
 | 
|  |    809 | %\small (the purpose is to check all links on my own webpage)
 | 
|  |    810 | %\end{frame}
 | 
|  |    811 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    812 | 
 | 
|  |    813 | 
 | 
|  |    814 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    815 | %\begin{frame}[c]
 | 
|  |    816 | %
 | 
|  |    817 | %\begin{textblock}{1}(2,5)
 | 
|  |    818 | %\begin{tabular}{c}
 | 
|  |    819 | %\includegraphics[scale=0.15]{pics/servers.png}\\[-2mm]
 | 
|  |    820 | %\small Server
 | 
|  |    821 | %\end{tabular}
 | 
|  |    822 | %\end{textblock}
 | 
|  |    823 | %
 | 
|  |    824 | %\begin{textblock}{1}(5.6,4)
 | 
|  |    825 | %  \begin{tikzpicture}[scale=1.1]
 | 
|  |    826 | %  \draw[white] (0,1) node (X) {};
 | 
|  |    827 | %  \draw[white] (2,1) node (Y) {};
 | 
|  |    828 | %   \draw[white] (0,0) node (X1) {};
 | 
|  |    829 | %  \draw[white] (2,0) node (Y1) {};
 | 
|  |    830 | %   \draw[white] (0,-1) node (X2) {};
 | 
|  |    831 | %  \draw[white] (2,-1) node (Y2) {};
 | 
|  |    832 | %  \draw[red, <-, line width = 2mm] (X) -- (Y);
 | 
|  |    833 | %  \node [inner sep=5pt,label=above:\textcolor{black}{GET request}] at ($ (X)!.5!(Y) $) {};
 | 
|  |    834 | %  \draw[red, ->, line width = 2mm] (X1) -- (Y1);
 | 
|  |    835 | %  \node [inner sep=5pt,label=above:\textcolor{black}{webpage}] at ($ (X1)!.5!(Y1) $) {};
 | 
|  |    836 | %  \draw[red, <-, line width = 2mm] (X2) -- (Y2);
 | 
|  |    837 | %  \node [inner sep=7pt,label=above:\textcolor{black}{POST data}] at ($ (X2)!.5!(Y2) $) {};
 | 
|  |    838 | %  \end{tikzpicture}
 | 
|  |    839 | %\end{textblock}
 | 
|  |    840 | %
 | 
|  |    841 | %
 | 
|  |    842 | %\begin{textblock}{1}(9,5.5)
 | 
|  |    843 | %\begin{tabular}{c}
 | 
|  |    844 | %\includegraphics[scale=0.15]{pics/laptop.png}\\[-2mm]
 | 
|  |    845 | %\small Browser
 | 
|  |    846 | %\end{tabular}
 | 
|  |    847 | %\end{textblock}
 | 
|  |    848 | %\end{frame}
 | 
|  |    849 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    850 | 
 | 
|  |    851 |   
 | 
|  |    852 | 
 | 
|  |    853 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    854 | %\begin{frame}[c]
 | 
|  |    855 | %\frametitle{Scala}
 | 
|  |    856 | %
 | 
|  |    857 | %\small A simple Scala function for reading webpages:
 | 
|  |    858 | %\bigskip
 | 
|  |    859 | %
 | 
|  |    860 | %\footnotesize
 | 
|  |    861 | %\lstinputlisting{../progs/app0.scala}
 | 
|  |    862 | %\medskip\pause
 | 
|  |    863 | %
 | 
|  |    864 | %\lstinline{get_page("""https://nms.kcl.ac.uk/christian.urban/""")}
 | 
|  |    865 | %\bigskip\medskip\pause
 | 
|  |    866 | %
 | 
|  |    867 | %
 | 
|  |    868 | %\small A slightly more complicated version for handling errors:
 | 
|  |    869 | %\smallskip
 | 
|  |    870 | %
 | 
|  |    871 | %\footnotesize
 | 
|  |    872 | %\lstinputlisting[xleftmargin=-4mm]{../progs/app1.scala}
 | 
|  |    873 | %
 | 
|  |    874 | %
 | 
|  |    875 | %\end{frame}
 | 
|  |    876 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    877 | 
 | 
|  |    878 |  
 | 
|  |    879 | 
 | 
|  |    880 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    881 | %\begin{frame}[t]
 | 
|  |    882 | %\frametitle{A Regular Expression}
 | 
|  |    883 | %
 | 
|  |    884 | %\begin{itemize}
 | 
|  |    885 | %\item \ldots{} is a pattern or template for specifying strings
 | 
|  |    886 | %\end{itemize}\bigskip
 | 
|  |    887 | %  
 | 
|  |    888 | %\begin{center}  
 | 
|  |    889 | %\only<1>{\scode{"https?://[^"]*"}}%
 | 
|  |    890 | %\only<2>{\scode{""""https?://[^"]*"""".r}}
 | 
|  |    891 | %\end{center}\bigskip\bigskip
 | 
|  |    892 | %
 | 
|  |    893 | %matches for example\smallskip\\  
 | 
|  |    894 | %\hspace{2mm}\code{"http://www.foobar.com"}\\
 | 
|  |    895 | %\hspace{2mm}\code{"https://www.tls.org"}\smallskip\\
 | 
|  |    896 | %
 | 
|  |    897 | %but not\smallskip\\  
 | 
|  |    898 | %\hspace{2mm}\code{"http://www."foo"bar.com"}\\
 | 
|  |    899 | %
 | 
|  |    900 | %\end{frame}
 | 
|  |    901 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    902 | 
 | 
|  |    903 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    904 | %\begin{frame}[c]
 | 
|  |    905 | %\frametitle{Finding Operations in Scala}
 | 
|  |    906 | %
 | 
|  |    907 | %{\bf\code{rexp.findAllIn(string)}}\medskip
 | 
|  |    908 | %  
 | 
|  |    909 | %returns a list of all (sub)strings that match the 
 | 
|  |    910 | %regular expression
 | 
|  |    911 | %\bigskip\bigskip  
 | 
|  |    912 | %  
 | 
|  |    913 | %
 | 
|  |    914 | %{\bf\code{rexp.findFirstIn(string)}}\medskip
 | 
|  |    915 | % 
 | 
|  |    916 | %returns either 
 | 
|  |    917 | %
 | 
|  |    918 | %\begin{itemize}
 | 
|  |    919 | %\item \code{None} if no (sub)string matches or 
 | 
|  |    920 | %\item \code{Some(s)} with the first (sub)string
 | 
|  |    921 | %\end{itemize}
 | 
|  |    922 | %
 | 
|  |    923 | %\end{frame}
 | 
|  |    924 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    925 | 
 | 
|  |    926 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    927 | %\begin{frame}[c]
 | 
|  |    928 | %
 | 
|  |    929 | %\footnotesize
 | 
|  |    930 | %\lstinputlisting{../progs/app2.scala}
 | 
|  |    931 | %
 | 
|  |    932 | %\end{frame}
 | 
|  |    933 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    934 | 
 | 
|  |    935 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    936 | %\begin{frame}[c]
 | 
|  |    937 | %
 | 
|  |    938 | %\small
 | 
|  |    939 | %A version that only crawls links in ``my'' domain:\bigskip
 | 
|  |    940 | %
 | 
|  |    941 | %\footnotesize
 | 
|  |    942 | %\lstinputlisting{../progs/app3.scala}
 | 
|  |    943 | %
 | 
|  |    944 | %\end{frame}
 | 
|  |    945 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    946 | 
 | 
|  |    947 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    948 | %\begin{frame}[c]
 | 
|  |    949 | %\lstset{xleftmargin=-4mm}
 | 
|  |    950 | %\small
 | 
|  |    951 | %A little email harvester:
 | 
|  |    952 | %
 | 
|  |    953 | %\footnotesize
 | 
|  |    954 | %\lstinputlisting{../progs/app4.scala}\bigskip
 | 
|  |    955 | %
 | 
|  |    956 | %\tiny
 | 
|  |    957 | %\url{http://net.tutsplus.com/tutorials/other/8-regular-expressions-you-should-know/}
 | 
|  |    958 | %
 | 
|  |    959 | %\end{frame}
 | 
|  |    960 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    961 | 
 | 
|  |    962 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    963 | \begin{frame}[t]
 | 
|  |    964 | \frametitle{(Basic) Regular Expressions}
 | 
|  |    965 | 
 | 
|  |    966 | Their inductive definition:
 | 
|  |    967 | 
 | 
|  |    968 | 
 | 
|  |    969 | \begin{textblock}{6}(2,7.5)
 | 
|  |    970 |   \begin{tabular}{@ {}rrl@ {\hspace{13mm}}l}
 | 
|  |    971 |   \bl{$r$} & \bl{$::=$}  & \bl{$\ZERO$}  & nothing\\
 | 
|  |    972 |          & \bl{$\mid$} & \bl{$\ONE$}       & empty string / \pcode{""} / $[]$\\
 | 
|  |    973 |          & \bl{$\mid$} & \bl{$c$}                         & character\\
 | 
|  |    974 |          & \bl{$\mid$} & \bl{$r_1 + r_2$}  & alternative / choice\\
 | 
|  |    975 |          & \bl{$\mid$} & \bl{$r_1 \cdot r_2$} & sequence\\
 | 
|  |    976 |          & \bl{$\mid$} & \bl{$r^*$}            & star (zero or more)\\
 | 
|  |    977 |   \end{tabular}
 | 
|  |    978 |   \end{textblock}
 | 
|  |    979 |   
 | 
|  |    980 |   
 | 
|  |    981 | \only<2->{\footnotesize
 | 
|  |    982 | \begin{textblock}{9}(2,0.5)
 | 
|  |    983 | \begin{bubble}[9.8cm]
 | 
|  |    984 | \lstinputlisting{../progs/app01.scala}
 | 
|  |    985 | \end{bubble}
 | 
|  |    986 | \end{textblock}}
 | 
|  |    987 |   
 | 
|  |    988 | \end{frame}
 | 
|  |    989 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    990 | 
 | 
|  |    991 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    992 | %\begin{frame}[t]
 | 
|  |    993 | %\frametitle{Regular Expressions}
 | 
|  |    994 | %
 | 
|  |    995 | %\small
 | 
|  |    996 | %In Scala:\bigskip
 | 
|  |    997 | %
 | 
|  |    998 | %\footnotesize
 | 
|  |    999 | %\lstinputlisting{../progs/app51.scala}
 | 
|  |   1000 | %
 | 
|  |   1001 | %  
 | 
|  |   1002 | %\end{frame}
 | 
|  |   1003 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |   1004 | 
 | 
|  |   1005 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1006 | \begin{frame}[t]
 | 
|  |   1007 | \frametitle{Strings}
 | 
|  |   1008 | 
 | 
|  |   1009 | \ldots are lists of characters. For example \code{"hello"}
 | 
|  |   1010 | 
 | 
|  |   1011 | \begin{center}
 | 
|  |   1012 | \bl{$[h, e, l, l, o]$} or just \bl{$hello$}
 | 
|  |   1013 | \end{center}
 | 
|  |   1014 | 
 | 
|  |   1015 | the empty string: \bl{$[]$} or \bl{\pcode{""}}\bigskip\\
 | 
|  |   1016 | 
 | 
|  |   1017 | the concatenation of two strings:
 | 
|  |   1018 | 
 | 
|  |   1019 | \begin{center}
 | 
|  |   1020 | \bl{$s_1 \,@\, s_2$}
 | 
|  |   1021 | \end{center}
 | 
|  |   1022 | 
 | 
|  |   1023 | \bl{\textit{foo $@$ bar = foobar}}\\
 | 
|  |   1024 | \bl{\textit{baz $@\, []$ = baz}}
 | 
|  |   1025 |   
 | 
|  |   1026 | \end{frame}
 | 
|  |   1027 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |   1028 | 
 | 
|  |   1029 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1030 | \begin{frame}[c]
 | 
|  |   1031 | \frametitle{Languages, Strings}
 | 
|  |   1032 | 
 | 
|  |   1033 | \begin{itemize}
 | 
|  |   1034 | \item \alert{\bf Strings} are lists of characters, for example
 | 
|  |   1035 | \begin{center}
 | 
|  |   1036 | \bl{$[]$},\;\bl{$abc$}  \hspace{2cm}(Pattern match: \bl{$c\!::\!s$})
 | 
|  |   1037 | \end{center}\bigskip
 | 
|  |   1038 | 
 | 
|  |   1039 | 
 | 
|  |   1040 | \item A \alert{\bf language} is a set of strings, for example\medskip
 | 
|  |   1041 | \begin{center}
 | 
|  |   1042 | \bl{$\{[], hello, \textit{foobar}, a, abc\}$}
 | 
|  |   1043 | \end{center}\bigskip
 | 
|  |   1044 | 
 | 
|  |   1045 | \item \alert{\bf Concatenation} of strings and languages
 | 
|  |   1046 | 
 | 
|  |   1047 | \begin{center}
 | 
|  |   1048 | \begin{tabular}{rcl}
 | 
|  |   1049 | \bl{$\textit{foo}\;@\;bar$} & \bl{$=$} & \bl{$\textit{foobar}$}\medskip\\
 | 
|  |   1050 | \bl{$A\;@\;B$} & \bl{$\dn$} & \bl{$\{ s_1\,@\,s_2 \;\mid\; s_1 \in A \wedge s_2 \in B\}$}
 | 
|  |   1051 | \end{tabular}
 | 
|  |   1052 | \end{center}
 | 
|  |   1053 | 
 | 
|  |   1054 | %\item The \alert{\bf meaning} of a regular expression is a set of 
 | 
|  |   1055 | %  strings, or language.
 | 
|  |   1056 | \end{itemize}  
 | 
|  |   1057 | 
 | 
|  |   1058 | \only<2>{
 | 
|  |   1059 | \begin{textblock}{4}(10.5,8)
 | 
|  |   1060 | \small
 | 
|  |   1061 | Let
 | 
|  |   1062 | 
 | 
|  |   1063 | \bl{$A = \{foo, bar\}$} \bl{$B = \{a, b\}$}
 | 
|  |   1064 | \[
 | 
|  |   1065 | \bl{A \,@\, B = \{fooa, foob, bara, barb\}}
 | 
|  |   1066 | \]
 | 
|  |   1067 | \end{textblock}}  
 | 
|  |   1068 | 
 | 
|  |   1069 | \end{frame}
 | 
|  |   1070 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |   1071 | 
 | 
|  |   1072 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1073 | \begin{frame}[c]
 | 
|  |   1074 |   \frametitle{Two Corner Cases}
 | 
|  |   1075 |    
 | 
|  |   1076 |   \Large
 | 
|  |   1077 |   \begin{center}
 | 
|  |   1078 |   \bl{$A \,@\, \{[]\} = \;?$}\bigskip\bigskip\pause\\
 | 
|  |   1079 |   \bl{$A \,@\, \{\} = \;?$}
 | 
|  |   1080 |   \end{center}  
 | 
|  |   1081 |     
 | 
|  |   1082 |   \end{frame}
 | 
|  |   1083 |   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
 | 
|  |   1084 |   
 | 
|  |   1085 | 
 | 
|  |   1086 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1087 | \begin{frame}[c]
 | 
|  |   1088 | \frametitle{The Meaning of a Regex}
 | 
|  |   1089 | 
 | 
|  |   1090 |  ...all the strings a regular expression can match.   
 | 
|  |   1091 | 
 | 
|  |   1092 | \begin{center}
 | 
|  |   1093 |  \begin{tabular}{rcl}
 | 
|  |   1094 |  \bl{$L(\ZERO)$}  & \bl{$\dn$} & \bl{$\{\}$}\\
 | 
|  |   1095 |  \bl{$L(\ONE)$}     & \bl{$\dn$} & \bl{$\{[]\}$}\\
 | 
|  |   1096 |  \bl{$L(c)$}            & \bl{$\dn$} & \bl{$\{[c]\}$}\\
 | 
|  |   1097 |  \bl{$L(r_1 + r_2)$}    & \bl{$\dn$} & \bl{$L(r_1) \cup L(r_2)$}\\
 | 
|  |   1098 |  \bl{$L(r_1 \cdot r_2)$} & \bl{$\dn$} & \bl{$L(r_1) \,@\, L(r_2)$}\\
 | 
|  |   1099 |  \bl{$L(r^*)$}           & \bl{$\dn$} & \\
 | 
|  |   1100 |   \end{tabular}
 | 
|  |   1101 | \end{center}
 | 
|  |   1102 | 
 | 
|  |   1103 | \begin{textblock}{14}(1.5,13.5)\small
 | 
|  |   1104 | \bl{$L$} is a function from regular expressions to 
 | 
|  |   1105 | sets of strings (languages):\smallskip\\
 | 
|  |   1106 | \bl{\quad$L$ : Rexp $\Rightarrow$ Set$[$String$]$}
 | 
|  |   1107 | \end{textblock}
 | 
|  |   1108 | 
 | 
|  |   1109 | \end{frame}
 | 
|  |   1110 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1111 | 
 | 
|  |   1112 | 
 | 
|  |   1113 | 
 | 
|  |   1114 | 
 | 
|  |   1115 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1116 | \begin{frame}[c]
 | 
|  |   1117 |   \frametitle{The Power Operation}
 | 
|  |   1118 |   
 | 
|  |   1119 |   \begin{itemize}
 | 
|  |   1120 |   \item The \alert{\textbf{\boldmath$n$th Power}} of a language:
 | 
|  |   1121 |   
 | 
|  |   1122 |   \begin{center}
 | 
|  |   1123 |   \begin{tabular}{lcl}
 | 
|  |   1124 |   \bl{$A^0$}    & \bl{$\dn$} & \bl{$\{[]\}$}\\
 | 
|  |   1125 |   \bl{$A^{n+1}$} & \bl{$\dn$} & \bl{$A \,@\, A^n$}
 | 
|  |   1126 |   \end{tabular}
 | 
|  |   1127 |   \end{center}\bigskip
 | 
|  |   1128 |   
 | 
|  |   1129 |   \item[] For example
 | 
|  |   1130 |   
 | 
|  |   1131 |   \begin{center}
 | 
|  |   1132 |   \begin{tabular}{lcl@{\hspace{10mm}}l}
 | 
|  |   1133 |   \bl{$A^4$} & \bl{$=$} & \bl{$A \,@\, A \,@\, A \,@\, A$} & \bl{$(@\,\{[]\})$}\\
 | 
|  |   1134 |   \bl{$A^1$} & \bl{$=$} & \bl{$A$} & \bl{$(@\,\{[]\})$}\\
 | 
|  |   1135 |   \bl{$A^0$} & \bl{$=$} & \bl{$\{[]\}$}\\
 | 
|  |   1136 |   \end{tabular}
 | 
|  |   1137 |   \end{center}
 | 
|  |   1138 |   
 | 
|  |   1139 |   \end{itemize}  
 | 
|  |   1140 |   
 | 
|  |   1141 |   \end{frame}
 | 
|  |   1142 |   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1143 |   
 | 
|  |   1144 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1145 | \begin{frame}[c]
 | 
|  |   1146 | \frametitle{The Meaning of a Regex}
 | 
|  |   1147 | 
 | 
|  |   1148 | \begin{textblock}{15}(1,4)
 | 
|  |   1149 |  \begin{tabular}{rcl}
 | 
|  |   1150 |  \bl{$L(\ZERO)$}  & \bl{$\dn$} & \bl{$\{\}$}\\
 | 
|  |   1151 |  \bl{$L(\ONE)$}     & \bl{$\dn$} & \bl{$\{[]\}$}\\
 | 
|  |   1152 |  \bl{$L(c)$}            & \bl{$\dn$} & \bl{$\{[c]\}$}\\
 | 
|  |   1153 |  \bl{$L(r_1 + r_2)$}    & \bl{$\dn$} & \bl{$L(r_1) \cup L(r_2)$}\\
 | 
|  |   1154 |  \bl{$L(r_1 \cdot r_2)$} & \bl{$\dn$} & \bl{$\{ s_1 \,@\, s_2 \;|\; s_1 \in L(r_1) \wedge s_2 \in L(r_2) \}$}\\
 | 
|  |   1155 |  \bl{$L(r^*)$}           & \bl{$\dn$} & \onslide<2->{\bl{$\bigcup_{0 \le n} L(r)^n$}}\\
 | 
|  |   1156 |   \end{tabular}\bigskip
 | 
|  |   1157 |   
 | 
|  |   1158 | %\onslide<2->{
 | 
|  |   1159 | %\hspace{5mm}\bl{$L(r)^0 \;\dn\; \{[]\}$}\\
 | 
|  |   1160 | %\bl{$L(r)^{n+1} \;\dn\; L(r) \,@\, L(r)^n$}\hspace{9mm}\onslide<3->{\small\textcolor{gray}{(append on sets)}\\
 | 
|  |   1161 | %\small\hspace{5cm}\textcolor{gray}{$\{ s_1 @ s_2 \;|\; s_1\in L(r) \wedge s_2 \in L(r)^n \}$}}
 | 
|  |   1162 | %}  
 | 
|  |   1163 | \end{textblock}
 | 
|  |   1164 | 
 | 
|  |   1165 | \end{frame}
 | 
|  |   1166 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |   1167 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1168 | \begin{frame}[c]
 | 
|  |   1169 |   \frametitle{The Star Operation}
 | 
|  |   1170 |   
 | 
|  |   1171 |   \begin{itemize}
 | 
|  |   1172 |   \item The \alert{\bf Kleene Star} of a \underline{language}:
 | 
|  |   1173 |   \bigskip
 | 
|  |   1174 |   
 | 
|  |   1175 |   \begin{center}
 | 
|  |   1176 |   \begin{tabular}{c}
 | 
|  |   1177 |   \bl{$A\star \dn \bigcup_{0\le n} A^n$}
 | 
|  |   1178 |   \end{tabular}
 | 
|  |   1179 |   \end{center}\bigskip
 | 
|  |   1180 |   
 | 
|  |   1181 |   \item[] This expands to 
 | 
|  |   1182 |   
 | 
|  |   1183 |   \[
 | 
|  |   1184 |   \bl{A^0 \cup A^1 \cup A^2 \cup A^3 \cup A^4 \cup \ldots}
 | 
|  |   1185 |   \]
 | 
|  |   1186 |   
 | 
|  |   1187 |   or
 | 
|  |   1188 |   
 | 
|  |   1189 |   \small
 | 
|  |   1190 |   \[
 | 
|  |   1191 |   \bl{\{[]\} \;\cup\; A \;\cup\; A\,@\,A \;\cup\; 
 | 
|  |   1192 |     A\,@\,A\,@\,A \;\cup\; A\,@\,A\,@\,A\,@\,A \cup \ldots}
 | 
|  |   1193 |   \]
 | 
|  |   1194 |   
 | 
|  |   1195 |   \end{itemize}  
 | 
|  |   1196 |   
 | 
|  |   1197 |   \end{frame}
 | 
|  |   1198 |   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |   1199 | 
 | 
|  |   1200 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1201 | \begin{frame}[c]
 | 
|  |   1202 | \frametitle{The Meaning of a Regex}
 | 
|  |   1203 | 
 | 
|  |   1204 | \begin{textblock}{15}(1,4)
 | 
|  |   1205 |  \begin{tabular}{rcl}
 | 
|  |   1206 |  \bl{$L(\ZERO)$}  & \bl{$\dn$} & \bl{$\{\}$}\\
 | 
|  |   1207 |  \bl{$L(\ONE)$}     & \bl{$\dn$} & \bl{$\{[]\}$}\\
 | 
|  |   1208 |  \bl{$L(c)$}            & \bl{$\dn$} & \bl{$\{[c]\}$}\\
 | 
|  |   1209 |  \bl{$L(r_1 + r_2)$}    & \bl{$\dn$} & \bl{$L(r_1) \cup L(r_2)$}\\
 | 
|  |   1210 |  \bl{$L(r_1 \cdot r_2)$} & \bl{$\dn$} & \bl{$\{ s_1 \,@\, s_2 \;|\; s_1 \in L(r_1) \wedge s_2 \in L(r_2) \}$}\\
 | 
|  |   1211 |  \bl{$L(r^*)$}           & \bl{$\dn$} & \bl{$(L(r))\star$}\\
 | 
|  |   1212 |   \end{tabular}
 | 
|  |   1213 |   
 | 
|  |   1214 | \end{textblock}
 | 
|  |   1215 | 
 | 
|  |   1216 | \end{frame}
 | 
|  |   1217 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1218 | 
 | 
|  |   1219 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1220 | \begin{frame}[c]
 | 
|  |   1221 | \frametitle{The Meaning of Matching}
 | 
|  |   1222 | 
 | 
|  |   1223 | \begin{bubble}[10cm]
 | 
|  |   1224 | \large\bf 
 | 
|  |   1225 | A regular expression \bl{$r$} matches a string~\bl{$s$} 
 | 
|  |   1226 | provided
 | 
|  |   1227 | 
 | 
|  |   1228 | \begin{center}
 | 
|  |   1229 | \bl{$s \in L(r)$}\\ 
 | 
|  |   1230 | \end{center}
 | 
|  |   1231 | \end{bubble}\bigskip\bigskip
 | 
|  |   1232 | 
 | 
|  |   1233 | \ldots and the point of the next lecture is 
 | 
|  |   1234 | to decide this problem as fast as possible (unlike Python,
 | 
|  |   1235 | Ruby, Java)
 | 
|  |   1236 | 
 | 
|  |   1237 | \end{frame}
 | 
|  |   1238 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%      
 | 
|  |   1239 | 
 | 
|  |   1240 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1241 | \begin{frame}[c]
 | 
|  |   1242 |   \frametitle{Questions}
 | 
|  |   1243 |   
 | 
|  |   1244 |   \begin{itemize}
 | 
|  |   1245 |   \item Say \bl{$A = \{[a],[b],[c],[d]\}$}.\bigskip
 | 
|  |   1246 |   
 | 
|  |   1247 |   \item[]
 | 
|  |   1248 |   How many strings are in \bl{$A^4$}\,?
 | 
|  |   1249 |   \bigskip\medskip\pause
 | 
|  |   1250 |   
 | 
|  |   1251 |   
 | 
|  |   1252 |  \item[]
 | 
|  |   1253 |   What if \bl{$A = \{[a],[b],[c],[]\}$};\\ 
 | 
|  |   1254 |   how many strings are then in \bl{$A^4$}\,?
 | 
|  |   1255 |   \end{itemize}  
 | 
|  |   1256 |   
 | 
|  |   1257 | \end{frame}
 | 
|  |   1258 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
 | 
|  |   1259 | 
 | 
|  |   1260 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1261 | % \begin{frame}[c]
 | 
|  |   1262 | % \frametitle{Languages (Sets of Strings)}
 | 
|  |   1263 | 
 | 
|  |   1264 | % \begin{itemize}
 | 
|  |   1265 | 
 | 
|  |   1266 | % \item A \alert{\bf Language} is a set of strings, for example\medskip
 | 
|  |   1267 | % \begin{center}
 | 
|  |   1268 | % \bl{$\{[], hello, foobar, a, abc\}$}
 | 
|  |   1269 | % \end{center}\bigskip
 | 
|  |   1270 | 
 | 
|  |   1271 | % \item \alert{\bf Concatenation} for strings and languages
 | 
|  |   1272 | 
 | 
|  |   1273 | % \begin{center}
 | 
|  |   1274 | % \begin{tabular}{rcl}
 | 
|  |   1275 | % \bl{$foo\;@\;bar$} & \bl{$=$} & \bl{$foobar$}\medskip\\
 | 
|  |   1276 | % \bl{$A\;@\;B$}     & \bl{$\dn$} & \bl{$\{ s_1\,@\,s_2 \;\mid\; s_1 \in A \wedge s_2 \in B\}$}
 | 
|  |   1277 | % \end{tabular}
 | 
|  |   1278 | % \end{center}
 | 
|  |   1279 | % \bigskip
 | 
|  |   1280 | 
 | 
|  |   1281 | % \small
 | 
|  |   1282 | % \item [] For example \bl{$A = \{foo, bar\}$}, \bl{$B = \{a, b\}$}
 | 
|  |   1283 | 
 | 
|  |   1284 | % \[
 | 
|  |   1285 | % \bl{A \,@\, B = \{fooa, foob, bara, barb\}}
 | 
|  |   1286 | % \]
 | 
|  |   1287 | 
 | 
|  |   1288 | 
 | 
|  |   1289 | 
 | 
|  |   1290 | 
 | 
|  |   1291 | % \end{itemize}  
 | 
|  |   1292 | % \end{frame}
 | 
|  |   1293 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |   1294 | 
 | 
|  |   1295 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1296 | % \begin{frame}[c]
 | 
|  |   1297 | %   \frametitle{Two Corner Cases}
 | 
|  |   1298 |    
 | 
|  |   1299 | %   \Large
 | 
|  |   1300 | %   \begin{center}
 | 
|  |   1301 | %   \bl{$A \,@\, \{[]\} = \;?$}\bigskip\bigskip\pause\\
 | 
|  |   1302 | %   \bl{$A \,@\, \{\} = \;?$}
 | 
|  |   1303 | %   \end{center}  
 | 
|  |   1304 |     
 | 
|  |   1305 | %   \end{frame}
 | 
|  |   1306 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
 | 
|  |   1307 |   
 | 
|  |   1308 | 
 | 
|  |   1309 | 
 | 
|  |   1310 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1311 | % \begin{frame}[c]
 | 
|  |   1312 | % \frametitle{The Meaning of a Regex}
 | 
|  |   1313 | 
 | 
|  |   1314 | %  ...all the strings a regular expression can match.   
 | 
|  |   1315 | 
 | 
|  |   1316 | % \begin{center}
 | 
|  |   1317 | %  \begin{tabular}{rcl}
 | 
|  |   1318 | %  \bl{$L(\ZERO)$}  & \bl{$\dn$} & \bl{$\{\}$}\\
 | 
|  |   1319 | %  \bl{$L(\ONE)$}     & \bl{$\dn$} & \bl{$\{[]\}$}\\
 | 
|  |   1320 | %  \bl{$L(c)$}            & \bl{$\dn$} & \bl{$\{[c]\}$}\\
 | 
|  |   1321 | %  \bl{$L(r_1 + r_2)$}    & \bl{$\dn$} & \bl{$L(r_1) \cup L(r_2)$}\\
 | 
|  |   1322 | %  \bl{$L(r_1 \cdot r_2)$} & \bl{$\dn$} & \bl{$L(r_1) \,@\, L(r_2)$}\\
 | 
|  |   1323 | %  \bl{$L(r^*)$}           & \bl{$\dn$} & \\
 | 
|  |   1324 | %   \end{tabular}
 | 
|  |   1325 | % \end{center}
 | 
|  |   1326 | 
 | 
|  |   1327 | % \begin{textblock}{14}(1.5,13.5)\small
 | 
|  |   1328 | % \bl{$L$} is a function from regular expressions to 
 | 
|  |   1329 | % sets of strings (languages):\smallskip\\
 | 
|  |   1330 | % \bl{\quad$L$ : Rexp $\Rightarrow$ Set$[$String$]$}
 | 
|  |   1331 | % \end{textblock}
 | 
|  |   1332 | 
 | 
|  |   1333 | % \end{frame}
 | 
|  |   1334 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1335 | 
 | 
|  |   1336 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1337 | % \begin{frame}[c]
 | 
|  |   1338 | % \frametitle{The Power Operation}
 | 
|  |   1339 | 
 | 
|  |   1340 | % \begin{itemize}
 | 
|  |   1341 | % \item The \alert{\textbf{\boldmath$n$th Power}} of a language:
 | 
|  |   1342 | 
 | 
|  |   1343 | % \begin{center}
 | 
|  |   1344 | % \begin{tabular}{lcl}
 | 
|  |   1345 | % \bl{$A^0$}    & \bl{$\dn$} & \bl{$\{[]\}$}\\
 | 
|  |   1346 | % \bl{$A^{n+1}$} & \bl{$\dn$} & \bl{$A \,@\, A^n$}
 | 
|  |   1347 | % \end{tabular}
 | 
|  |   1348 | % \end{center}\bigskip
 | 
|  |   1349 | 
 | 
|  |   1350 | % \item[] For example
 | 
|  |   1351 | 
 | 
|  |   1352 | % \begin{center}
 | 
|  |   1353 | % \begin{tabular}{lcl@{\hspace{10mm}}l}
 | 
|  |   1354 | % \bl{$A^4$} & \bl{$=$} & \bl{$A \,@\, A \,@\, A \,@\, A$} & \bl{$(@\,\{[]\})$}\\
 | 
|  |   1355 | % \bl{$A^1$} & \bl{$=$} & \bl{$A$} & \bl{$(@\,\{[]\})$}\\
 | 
|  |   1356 | % \bl{$A^0$} & \bl{$=$} & \bl{$\{[]\}$}\\
 | 
|  |   1357 | % \end{tabular}
 | 
|  |   1358 | % \end{center}
 | 
|  |   1359 | 
 | 
|  |   1360 | % \end{itemize}  
 | 
|  |   1361 | 
 | 
|  |   1362 | % \end{frame}
 | 
|  |   1363 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 | 
|  |   1364 | 
 | 
|  |   1365 | 
 | 
|  |   1366 | 
 | 
|  |   1367 | 
 | 
|  |   1368 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1369 | % \begin{frame}[c]
 | 
|  |   1370 | % \frametitle{Written Exam}
 | 
|  |   1371 | 
 | 
|  |   1372 | % \begin{itemize}
 | 
|  |   1373 | % \item Accounts for 80\%.\bigskip
 | 
|  |   1374 | 
 | 
|  |   1375 | % \item The question ``\textit{Is this relevant for
 | 
|  |   1376 | %       the exam?}'' is very demotivating for the lecturer!\bigskip\\
 | 
|  |   1377 | 
 | 
|  |   1378 | % \item Deal: Whatever is in the homework (and is not marked
 | 
|  |   1379 | %       ``\textit{optional}'') is relevant for the exam.\bigskip
 | 
|  |   1380 |       
 | 
|  |   1381 | % \item Each lecture has also a handout. There are also handouts about
 | 
|  |   1382 | % notation and Scala.      
 | 
|  |   1383 | % \end{itemize}
 | 
|  |   1384 | 
 | 
|  |   1385 | % \end{frame}
 | 
|  |   1386 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |   1387 | 
 | 
|  |   1388 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1389 | % \begin{frame}[t]
 | 
|  |   1390 | % \frametitle{Coursework}
 | 
|  |   1391 | 
 | 
|  |   1392 | % \begin{itemize}
 | 
|  |   1393 | % \item Accounts for 20\%. Two strands. Choose \alert{\bf one}!\bigskip
 | 
|  |   1394 | % \end{itemize}
 | 
|  |   1395 | 
 | 
|  |   1396 | % \begin{columns}[t]
 | 
|  |   1397 | % \begin{column}{.5\textwidth}
 | 
|  |   1398 | % \underline{\bf Strand 1}\medskip
 | 
|  |   1399 | % \begin{itemize}
 | 
|  |   1400 | % \item 4 programming tasks:
 | 
|  |   1401 | % \begin{itemize}
 | 
|  |   1402 | % \item matcher (4\%, 11.10.) 
 | 
|  |   1403 | % \item lexer (5\%, 04.11.)
 | 
|  |   1404 | % \item parser (5\%, 22.11.)
 | 
|  |   1405 | % \item compiler (6\%, 13.12.)
 | 
|  |   1406 | % \end{itemize}
 | 
|  |   1407 | % \item in any lang.~you like,\\ but I want to see the\\ code
 | 
|  |   1408 | % \end{itemize}
 | 
|  |   1409 | % \end{column}
 | 
|  |   1410 | 
 | 
|  |   1411 | % \hspace{-45pt}\vrule{}\hspace{10pt}
 | 
|  |   1412 | % \begin{column}{.5\textwidth}
 | 
|  |   1413 | % \underline{\bf Strand 2}\smallskip\begin{itemize}
 | 
|  |   1414 | % \item one task: prove the correctness of a regular expression matcher in 
 | 
|  |   1415 | % the \underline{Isabelle} theorem prover
 | 
|  |   1416 | % \item 20\%, submission on~13.12.\hspace{-5mm}\mbox{}
 | 
|  |   1417 | % \end{itemize}
 | 
|  |   1418 | % \end{column}
 | 
|  |   1419 | % \end{columns}\medskip
 | 
|  |   1420 | 
 | 
|  |   1421 | % \small
 | 
|  |   1422 | % \begin{itemize}
 | 
|  |   1423 | % \item Solving more than one strand will {\bf not} give you more 
 | 
|  |   1424 | % marks.
 | 
|  |   1425 | 
 | 
|  |   1426 | % \end{itemize}
 | 
|  |   1427 | 
 | 
|  |   1428 | % \end{frame}
 | 
|  |   1429 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |   1430 | 
 | 
|  |   1431 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1432 | %\begin{frame}[c]
 | 
|  |   1433 | %\frametitle{Lecture Capture}
 | 
|  |   1434 | %
 | 
|  |   1435 | %\begin{itemize}
 | 
|  |   1436 | %\item Hope it works\ldots\pause actually no, it does not!\medskip\pause
 | 
|  |   1437 | %\item It is important to use lecture capture wisely\\ (it is only the ``baseline''):
 | 
|  |   1438 | %\begin{itemize}  
 | 
|  |   1439 | %\item Lecture recordings are a study and revision aid.
 | 
|  |   1440 | %\item Statistically, there is a clear and direct link between attendance and
 | 
|  |   1441 | %  attainment: students who do not attend lectures, do less well in exams.
 | 
|  |   1442 | %\end{itemize}
 | 
|  |   1443 | %
 | 
|  |   1444 | %\item Attending a lecture is more than watching it online -- if you do not
 | 
|  |   1445 | %attend, you miss out!  
 | 
|  |   1446 | %  
 | 
|  |   1447 | %\end{itemize}
 | 
|  |   1448 | %
 | 
|  |   1449 | %\end{frame}
 | 
|  |   1450 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |   1451 | 
 | 
|  |   1452 | 
 | 
|  |   1453 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1454 | \begin{frame}[c]
 | 
|  |   1455 | \frametitle{\begin{tabular}{c}\\[3cm]\alert{Questions?}\end{tabular}}
 | 
|  |   1456 | 
 | 
|  |   1457 | 
 | 
|  |   1458 | \begin{tabular}{lll}
 | 
|  |   1459 |   TAs: & Finley Warman    & (took the module last year)\\
 | 
|  |   1460 |        & Chengsong Tan    & (PhD student working on derivatives)  
 | 
|  |   1461 | \end{tabular}  
 | 
|  |   1462 | \mbox{}
 | 
|  |   1463 | \end{frame}
 | 
|  |   1464 | 
 | 
|  |   1465 | \begin{frame}[c]
 | 
|  |   1466 | \end{frame}
 | 
|  |   1467 | 
 | 
|  |   1468 | \begin{frame}[c]
 | 
|  |   1469 | \end{frame}
 | 
|  |   1470 | 
 | 
|  |   1471 | \begin{frame}[c]
 | 
|  |   1472 | \end{frame}
 | 
|  |   1473 | 
 | 
|  |   1474 | \begin{frame}[c]
 | 
|  |   1475 | \end{frame}
 | 
|  |   1476 | 
 | 
|  |   1477 | \begin{frame}[c]
 | 
|  |   1478 | \end{frame}
 | 
|  |   1479 | 
 | 
|  |   1480 | \begin{frame}[c]
 | 
|  |   1481 | \end{frame}
 | 
|  |   1482 | 
 | 
|  |   1483 | \begin{frame}[c]
 | 
|  |   1484 | \end{frame}
 | 
|  |   1485 | 
 | 
|  |   1486 | \begin{frame}[c]
 | 
|  |   1487 | \end{frame}
 | 
|  |   1488 | 
 | 
|  |   1489 | \begin{frame}[c]
 | 
|  |   1490 | \end{frame}
 | 
|  |   1491 | 
 | 
|  |   1492 | \begin{frame}[c]
 | 
|  |   1493 | \end{frame}
 | 
|  |   1494 | 
 | 
|  |   1495 | \begin{frame}[c]
 | 
|  |   1496 | \end{frame}
 | 
|  |   1497 | 
 | 
|  |   1498 | \begin{frame}[c]
 | 
|  |   1499 | \end{frame}
 | 
|  |   1500 | 
 | 
|  |   1501 | \begin{frame}[c]
 | 
|  |   1502 | \end{frame}
 | 
|  |   1503 | 
 | 
|  |   1504 | \begin{frame}[c]
 | 
|  |   1505 | \end{frame}
 | 
|  |   1506 | 
 | 
|  |   1507 | 
 | 
|  |   1508 | \begin{frame}[c]
 | 
|  |   1509 | \begin{mybox3}{Coursework}
 | 
|  |   1510 |   Do we need to provide instructions on running the coursework files
 | 
|  |   1511 |   if we're using languages other than Scala? Thanks
 | 
|  |   1512 | \end{mybox3}\pause
 | 
|  |   1513 | 
 | 
|  |   1514 | \begin{mybox2}{Zip-File for Coursework}
 | 
|  |   1515 |   Please, please submit a zipfile that generates a subdirectory
 | 
|  |   1516 |   \begin{center}
 | 
|  |   1517 |   \texttt{NameFamilyName}  
 | 
|  |   1518 |   \end{center}  
 | 
|  |   1519 | \end{mybox2}
 | 
|  |   1520 | \end{frame}
 | 
|  |   1521 | 
 | 
|  |   1522 | 
 | 
|  |   1523 | \begin{frame}[c]
 | 
|  |   1524 | \begin{mybox3}{Coursework}
 | 
|  |   1525 |   What is the purpose of the workshop session on the timetable?
 | 
|  |   1526 |   
 | 
|  |   1527 |   Slightly confused about how to undertake cw1 and what exactly we
 | 
|  |   1528 |   should be implementing. This is more for clarification of the cw1
 | 
|  |   1529 |   structure, including the implementation and questions present in
 | 
|  |   1530 |   cw1.
 | 
|  |   1531 | \end{mybox3}
 | 
|  |   1532 | \end{frame}
 | 
|  |   1533 | 
 | 
|  |   1534 | \begin{frame}[c]
 | 
|  |   1535 | \begin{mybox3}{What is the trick?}\small
 | 
|  |   1536 |   What was the trick to improve the evil regular expressions matcher
 | 
|  |   1537 |   to have such good results compared to other programming languages?
 | 
|  |   1538 |   Is it working better on casual regular expressions (the ones that
 | 
|  |   1539 |   Python and Java handle pretty well), too? Or was it just optimised
 | 
|  |   1540 |   for these evil ones?
 | 
|  |   1541 | \end{mybox3}
 | 
|  |   1542 | 
 | 
|  |   1543 | \begin{mybox3}{}\small
 | 
|  |   1544 |   It was shown in the lectures that the pattern matching algorithms
 | 
|  |   1545 |   currently implemented in popular programming languages (Python, JS,
 | 
|  |   1546 |   Java, etc) are far slower than the algorithm we are going to be
 | 
|  |   1547 |   implementing in this module. My question is why do these programming
 | 
|  |   1548 |   languages not implement the algorithm that we are going to implement
 | 
|  |   1549 |   in this module?
 | 
|  |   1550 | \end{mybox3}
 | 
|  |   1551 | \end{frame}
 | 
|  |   1552 | 
 | 
|  |   1553 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1554 | \begin{frame}[c]
 | 
|  |   1555 |   \frametitle{Thanks to Martin Mikusovic}
 | 
|  |   1556 | 
 | 
|  |   1557 | \bigskip    
 | 
|  |   1558 | \begin{center}
 | 
|  |   1559 | \begin{tikzpicture}
 | 
|  |   1560 |   \begin{axis}[
 | 
|  |   1561 |     xlabel={$n$},
 | 
|  |   1562 |     x label style={at={(1.05,0.0)}},
 | 
|  |   1563 |     ylabel={time in secs},
 | 
|  |   1564 |     enlargelimits=false,
 | 
|  |   1565 |     xtick={0,5,...,30},
 | 
|  |   1566 |     xmax=33,
 | 
|  |   1567 |     ymax=35,
 | 
|  |   1568 |     ytick={0,10,...,30},
 | 
|  |   1569 |     scaled ticks=false,
 | 
|  |   1570 |     axis lines=left,
 | 
|  |   1571 |     width=9cm,
 | 
|  |   1572 |     height=5.5cm, 
 | 
|  |   1573 |     legend entries={Java 8, Python, JavaScript, Swift},  
 | 
|  |   1574 |     legend pos=north west,
 | 
|  |   1575 |     legend cell align=left]
 | 
|  |   1576 | \addplot[blue,mark=*, mark options={fill=white}] table {re-python2.data};
 | 
|  |   1577 | \addplot[cyan,mark=*, mark options={fill=white}] table {re-java.data};
 | 
|  |   1578 | \addplot[red,mark=*, mark options={fill=white}] table {re-js.data};
 | 
|  |   1579 | \addplot[magenta,mark=*, mark options={fill=white}] table {re-swift.data};
 | 
|  |   1580 | \end{axis}
 | 
|  |   1581 | \end{tikzpicture}
 | 
|  |   1582 | \end{center}
 | 
|  |   1583 | 
 | 
|  |   1584 | Regex: \bl{$(a^*)^* \cdot b$}
 | 
|  |   1585 | 
 | 
|  |   1586 | Strings of the form \bl{$\underbrace{\,a\ldots a\,}_{n}$}
 | 
|  |   1587 | 
 | 
|  |   1588 | \end{frame}
 | 
|  |   1589 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1590 | 
 | 
|  |   1591 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1592 | \begin{frame}[c]
 | 
|  |   1593 | \frametitle{Same Example in Java 9+}
 | 
|  |   1594 | 
 | 
|  |   1595 | \begin{center}
 | 
|  |   1596 | \begin{tikzpicture}
 | 
|  |   1597 |   \begin{axis}[
 | 
|  |   1598 |     xlabel={$n$},
 | 
|  |   1599 |     x label style={at={(1.09,-0.15)}},
 | 
|  |   1600 |     ylabel={time in secs},
 | 
|  |   1601 |     scaled x ticks=false,
 | 
|  |   1602 |     enlargelimits=false,
 | 
|  |   1603 |     xtick distance=10000,
 | 
|  |   1604 |     xmax=44000, 
 | 
|  |   1605 |     ytick={0,10,...,30}, 
 | 
|  |   1606 |     ymax=35, 
 | 
|  |   1607 |     axis lines=left,
 | 
|  |   1608 |     width=9cm,
 | 
|  |   1609 |     height=5cm, 
 | 
|  |   1610 |     legend entries={Java \liningnums{9}+},
 | 
|  |   1611 |     legend pos=north west,
 | 
|  |   1612 |     legend cell align=left]
 | 
|  |   1613 | \addplot[blue,mark=square*,mark options={fill=white}] table {re-java9.data};
 | 
|  |   1614 | \end{axis}
 | 
|  |   1615 | \end{tikzpicture}
 | 
|  |   1616 | \end{center}
 | 
|  |   1617 | 
 | 
|  |   1618 | Regex: \bl{$(a^*)^* \cdot b$}
 | 
|  |   1619 | 
 | 
|  |   1620 | Strings of the form \bl{$\underbrace{\,a\ldots a\,}_{n}$}
 | 
|  |   1621 | 
 | 
|  |   1622 | \end{frame}
 | 
|  |   1623 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1624 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1625 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1626 | % Questions
 | 
|  |   1627 | 
 | 
|  |   1628 | \begin{frame}[c]
 | 
|  |   1629 | \begin{mybox3}{}
 | 
|  |   1630 |   Are there any (common) languages that have a built-in regex
 | 
|  |   1631 |   implementation matching the set of functions of a formal 'simple'
 | 
|  |   1632 |   regular expression, as opposed to an 'extended' regular expression
 | 
|  |   1633 |   implemented in most regex-supporting languages?
 | 
|  |   1634 | \end{mybox3}
 | 
|  |   1635 | \end{frame}
 | 
|  |   1636 | 
 | 
|  |   1637 | \begin{frame}[c]
 | 
|  |   1638 | \begin{mybox3}{Regexes}
 | 
|  |   1639 |   Can we determine all the possible regular expressions matching a
 | 
|  |   1640 |   certain string? If we take into account all the possible ways to
 | 
|  |   1641 |   combine the operations: \bl{$\ZERO$}, \bl{$\ONE$},
 | 
|  |   1642 |   \bl{$r_1 + r_2$}, \bl{$r_1 \cdot r_2$}, \bl{$r^*$}?
 | 
|  |   1643 | \end{mybox3}
 | 
|  |   1644 | \end{frame}
 | 
|  |   1645 | 
 | 
|  |   1646 | \begin{frame}[c]
 | 
|  |   1647 | \begin{mybox3}{\bl{$L$} + Equivalence}
 | 
|  |   1648 |   When we explain why two regular expressions are not equivalent, what
 | 
|  |   1649 |   method is better for us, using mathematics formulas or making an
 | 
|  |   1650 |   example? 
 | 
|  |   1651 | \end{mybox3}
 | 
|  |   1652 | \begin{mybox3}{}
 | 
|  |   1653 |   Meaning of Regex and Operations
 | 
|  |   1654 | \end{mybox3}
 | 
|  |   1655 | \end{frame}
 | 
|  |   1656 | 
 | 
|  |   1657 | \begin{frame}[c]
 | 
|  |   1658 | \begin{mybox3}{\bl{$L$}}
 | 
|  |   1659 |   Can the function L be applied to anything other than regular
 | 
|  |   1660 |   expressions? For example would L(L(c)) return anything?
 | 
|  |   1661 | \end{mybox3}
 | 
|  |   1662 | 
 | 
|  |   1663 | \hfill $\Rightarrow$ No
 | 
|  |   1664 | \end{frame} 
 | 
|  |   1665 | 
 | 
|  |   1666 | \begin{frame}[c]
 | 
|  |   1667 | \begin{mybox3}{\bl{$(a?)\{n\} \cdot a\{n\}$}}
 | 
|  |   1668 |   In the evil regexes section, is there any reason why in the regex
 | 
|  |   1669 |   \texttt{[a?]\{n\}[a]\{n\}} the square brackets are used? It is defined as a
 | 
|  |   1670 |   single character from the square brackets, however there is just one
 | 
|  |   1671 |   character, so it seems like it is not necessary. Maybe it is just
 | 
|  |   1672 |   necessary for the first part, because ? is a token instead of a
 | 
|  |   1673 |   character and we need to refer to a? as a ``unit''? Could regular
 | 
|  |   1674 |   brackets be used instead? Is there any difference apart from the
 | 
|  |   1675 |   fact that it would create a group? Also, are the regexes
 | 
|  |   1676 |   \texttt{[a?]\{n\}} and
 | 
|  |   1677 |   \texttt{a\{0,3\}} equivalent?
 | 
|  |   1678 | \end{mybox3}
 | 
|  |   1679 | \end{frame} 
 | 
|  |   1680 | 
 | 
|  |   1681 | \begin{frame}[c]
 | 
|  |   1682 | \begin{mybox3}{Python + Parser Combinators (CW3)}\small
 | 
|  |   1683 |   Hi Christian,
 | 
|  |   1684 | 
 | 
|  |   1685 |   I don’t see a problem: you certainly have higher order functions and
 | 
|  |   1686 |   it is easy to implement algebraic data types using classes. As far
 | 
|  |   1687 |   as I can see that’s all you need. You don’t get the static types but
 | 
|  |   1688 |   that should be obvious. Basically if you can do it in LISP you can
 | 
|  |   1689 |   do it in Python. The only problem could be stack overflows due to a
 | 
|  |   1690 |   lack of tail recursion optimisation. On the other hand you can
 | 
|  |   1691 |   simulate laziness using generators.
 | 
|  |   1692 | 
 | 
|  |   1693 |   Cheers,
 | 
|  |   1694 |   Thorsten 
 | 
|  |   1695 | \end{mybox3}
 | 
|  |   1696 | 
 | 
|  |   1697 | Trees \url{https://youtu.be/7tCNu4CnjVc}
 | 
|  |   1698 | 
 | 
|  |   1699 | Laziness \url{https://youtu.be/5jwV3zxXc8E}
 | 
|  |   1700 | 
 | 
|  |   1701 | \end{frame}
 | 
|  |   1702 | 
 | 
|  |   1703 | \begin{frame}[c]
 | 
|  |   1704 | \begin{mybox3}{}
 | 
|  |   1705 |   What suggestions do you have for us to get the most out of this
 | 
|  |   1706 |   module, especially in the online format? I.e. form discussion
 | 
|  |   1707 |   groups, will you have office hours?
 | 
|  |   1708 | \end{mybox3}
 | 
|  |   1709 | 
 | 
|  |   1710 | \small
 | 
|  |   1711 | \hfill $\Rightarrow$\mbox{} Discussion Forum on KEATS
 | 
|  |   1712 | 
 | 
|  |   1713 | \hfill online tutorial sessions
 | 
|  |   1714 | 
 | 
|  |   1715 | \end{frame}
 | 
|  |   1716 | 
 | 
|  |   1717 | \begin{frame}[c]
 | 
|  |   1718 |  \small
 | 
|  |   1719 | \begin{mybox3}{}
 | 
|  |   1720 | Where do most students struggle with this module? What will the format
 | 
|  |   1721 | of the exam be? What is the most efficient way of studying for the
 | 
|  |   1722 | exam? There are plenty of resources available on KEATS, but is there
 | 
|  |   1723 | anything else you'd recommend us to study? Although (just by skimming
 | 
|  |   1724 | the headings) the module seems to be a combination of practical and
 | 
|  |   1725 | theoretical matters, exactly in what field would the syllabus be
 | 
|  |   1726 | applied? Besides these questions and the ones other students asked, is
 | 
|  |   1727 | there anything else we should know? Thank you!
 | 
|  |   1728 | \end{mybox3}
 | 
|  |   1729 | \end{frame}
 | 
|  |   1730 | 
 | 
|  |   1731 | 
 | 
|  |   1732 | \begin{frame}[c]
 | 
|  |   1733 | \end{frame}
 | 
|  |   1734 | 
 | 
|  |   1735 | \begin{frame}[c]
 | 
|  |   1736 | \end{frame}
 | 
|  |   1737 | 
 | 
|  |   1738 | \begin{frame}[c]
 | 
|  |   1739 | \end{frame}
 | 
|  |   1740 | 
 | 
|  |   1741 | \begin{frame}[c]
 | 
|  |   1742 | \end{frame}
 | 
|  |   1743 | 
 | 
|  |   1744 | \begin{frame}[c,fragile]
 | 
|  |   1745 | 
 | 
|  |   1746 | \end{frame}
 | 
|  |   1747 | 
 | 
|  |   1748 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |   1749 | \end{document}
 | 
|  |   1750 | 
 | 
|  |   1751 | %%% Local Variables:  
 | 
|  |   1752 | %%% mode: latex
 | 
|  |   1753 | %%% TeX-master: t
 | 
|  |   1754 | %%% End: 
 | 
|  |   1755 | 
 |