| 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] 
 | 
| 880 |     61 |   \LARGE Formal Languages\\[-5mm] 
 | 
| 876 |     62 |   \end{tabular}}
 | 
|  |     63 | 
 | 
| 880 |     64 |   %\begin{center}
 | 
| 876 |     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?)}
 | 
| 880 |     68 |   %\end{center}
 | 
| 876 |     69 | 
 | 
|  |     70 |   \normalsize
 | 
|  |     71 |   \begin{center}
 | 
|  |     72 |   \begin{tabular}{ll}
 | 
|  |     73 |   Email:  & christian.urban at kcl.ac.uk\\
 | 
| 880 |     74 |   Office Hour: & Fridays 11 -- 12\\
 | 
|  |     75 |   Location: & N7.07 (North Wing, Bush House)\\
 | 
| 876 |     76 |   Slides \& Progs: & KEATS\\
 | 
| 880 |     77 |   Pollev: & \texttt{\alert{https://pollev.com/cfltutoratki576}}\\  
 | 
| 876 |     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 | 
 | 
| 879 |    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 | 
 | 
| 876 |    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 | 
 | 
| 879 |    475 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 | 
|  |    476 | {
 | 
|  |    477 | \setbeamercolor{background canvas}{bg=cream}
 | 
|  |    478 | \begin{frame}[c]
 | 
|  |    479 | \frametitle{Homework}
 | 
|  |    480 | 
 | 
| 880 |    481 | Last year(s): I did not give out solutions; students sent emails to me and I responded them individually\bigskip\\
 | 
| 879 |    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 | 
 | 
| 876 |    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 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
| 879 |    608 | {
 | 
|  |    609 | \setbeamercolor{background canvas}{bg=cream}
 | 
|  |    610 | \begin{frame}[t]
 | 
|  |    611 | \frametitle{Notation for REs}
 | 
|  |    612 | 
 | 
|  |    613 | 
 | 
|  |    614 | 
 | 
|  |    615 |   
 | 
|  |    616 | \end{frame}  
 | 
|  |    617 | }
 | 
| 876 |    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 | 
 | 
|  |    645 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    646 | \begin{frame}[c]
 | 
|  |    647 | \frametitle{Why Bother with Regexes?}
 | 
|  |    648 | 
 | 
|  |    649 | \begin{columns}[t,onlytextwidth]
 | 
|  |    650 | \begin{column}{1.8cm}
 | 
|  |    651 | \mbox{}   
 | 
|  |    652 | \end{column}    
 | 
|  |    653 | \begin{column}{.5\textwidth}
 | 
|  |    654 | \small{}Ruby, Python, Java 8\medskip\\
 | 
|  |    655 | \begin{tikzpicture}\footnotesize
 | 
|  |    656 | \begin{axis}[
 | 
|  |    657 |     xlabel={$n$},
 | 
|  |    658 |     x label style={at={(1.05,0.0)}},
 | 
|  |    659 |     ylabel={time in secs},
 | 
|  |    660 |     enlargelimits=false,
 | 
|  |    661 |     xtick={0,5,...,30},
 | 
|  |    662 |     xmax=33,
 | 
|  |    663 |     ymax=35,
 | 
|  |    664 |     ytick={0,5,...,30},
 | 
|  |    665 |     scaled ticks=false,
 | 
|  |    666 |     axis lines=left,
 | 
|  |    667 |     width=\textwidth,
 | 
|  |    668 |     height=4cm, 
 | 
|  |    669 |     legend entries={Python,Ruby},  
 | 
|  |    670 |     legend pos=north west,
 | 
|  |    671 |     legend cell align=left]
 | 
|  |    672 | \addplot[blue,mark=*, mark options={fill=white}] table {re-python.data};
 | 
|  |    673 | \addplot[brown,mark=triangle*, mark options={fill=white}] table {re-ruby.data};
 | 
|  |    674 | \end{axis}
 | 
|  |    675 | \end{tikzpicture}
 | 
|  |    676 | \begin{tikzpicture}\footnotesize
 | 
|  |    677 | \begin{axis}[
 | 
|  |    678 |     xlabel={$n$},
 | 
|  |    679 |     x label style={at={(1.05,0.0)}},
 | 
|  |    680 |     ylabel={time in secs},
 | 
|  |    681 |     enlargelimits=false,
 | 
|  |    682 |     xtick={0,5,...,30},
 | 
|  |    683 |     xmax=33,
 | 
|  |    684 |     ymax=35,
 | 
|  |    685 |     ytick={0,5,...,30},
 | 
|  |    686 |     scaled ticks=false,
 | 
|  |    687 |     axis lines=left,
 | 
|  |    688 |     width=\textwidth,
 | 
|  |    689 |     height=4cm, 
 | 
|  |    690 |     legend entries={Python, Java 8, JavaScript, Swift},  
 | 
|  |    691 |     legend pos=north west,
 | 
|  |    692 |     legend cell align=left]
 | 
|  |    693 | \addplot[blue,mark=*, mark options={fill=white}] table {re-python2.data};   
 | 
|  |    694 | \addplot[cyan,mark=*, mark options={fill=white}] table {re-java.data};
 | 
|  |    695 | \addplot[red,mark=*, mark options={fill=white}] table {re-js.data};
 | 
|  |    696 | \addplot[magenta,mark=*, mark options={fill=white}] table {re-swift.data};
 | 
|  |    697 | \end{axis}
 | 
|  |    698 | \end{tikzpicture}
 | 
|  |    699 | %
 | 
|  |    700 | \end{column}
 | 
|  |    701 | \begin{column}{.5\textwidth}
 | 
|  |    702 | \small{}Us (after next lecture)\medskip\\
 | 
|  |    703 | \begin{tikzpicture}\footnotesize
 | 
|  |    704 | \begin{axis}[
 | 
|  |    705 |     xlabel={$n$},
 | 
|  |    706 |     x label style={at={(1.07,0.0)}},
 | 
|  |    707 |     ylabel={time in secs},
 | 
|  |    708 |     enlargelimits=false,
 | 
|  |    709 |     xtick={0,5000,...,10000},
 | 
|  |    710 |     xmax=11000,
 | 
|  |    711 |     ymax=35,
 | 
|  |    712 |     ytick={0,5,...,30},
 | 
|  |    713 |     scaled ticks=false,
 | 
|  |    714 |     axis lines=left,
 | 
|  |    715 |     width=\textwidth,
 | 
|  |    716 |     height=4cm]
 | 
|  |    717 | \addplot[green,mark=square*,mark options={fill=white}] table {re2.data};
 | 
|  |    718 | \addplot[black,mark=square*,mark options={fill=white}] table {re3.data};
 | 
|  |    719 | \end{axis}
 | 
|  |    720 | \end{tikzpicture}
 | 
|  |    721 | \begin{tikzpicture}\footnotesize
 | 
|  |    722 | \begin{axis}[
 | 
|  |    723 |     xlabel={$n$},
 | 
|  |    724 |     x label style={at={(1.07,0.0)}},
 | 
|  |    725 |     ylabel={time in secs},
 | 
|  |    726 |     enlargelimits=false,
 | 
|  |    727 |     ymax=35,
 | 
|  |    728 |     ytick={0,5,...,30},
 | 
|  |    729 |     scaled ticks=false,
 | 
|  |    730 |     axis lines=left,
 | 
|  |    731 |     width=\textwidth,
 | 
|  |    732 |     height=4cm]
 | 
|  |    733 | \addplot[black,mark=square*,mark options={fill=white}] table {re3a.data};
 | 
|  |    734 | \end{axis}
 | 
|  |    735 | \end{tikzpicture}
 | 
|  |    736 | \end{column}
 | 
|  |    737 | \end{columns}
 | 
|  |    738 | \medskip
 | 
|  |    739 | 
 | 
|  |    740 | \begin{textblock}{3}(-0.1,3.3)
 | 
|  |    741 | \small\hfill\bl{\texttt{[a?]\{n\}[a]\{n\}}}:
 | 
|  |    742 | \end{textblock}
 | 
|  |    743 | 
 | 
|  |    744 | \begin{textblock}{3}(-0.1,8.7)  
 | 
|  |    745 | \small\hfill\bl{\texttt{(a*)*b}}:
 | 
|  |    746 | \end{textblock}
 | 
|  |    747 | 
 | 
|  |    748 | \begin{textblock}{3}(0.3,13)
 | 
|  |    749 | \small{}matching with strings
 | 
|  |    750 | \bl{$\underbrace{\texttt{a}...\texttt{a}}_n$}  
 | 
|  |    751 | \end{textblock}
 | 
|  |    752 | 
 | 
|  |    753 | \end{frame} 
 | 
|  |    754 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
 | 
|  |    755 |     
 | 
|  |    756 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    757 | \begin{frame}[c,fragile]
 | 
|  |    758 |   \frametitle{Incidents}
 | 
|  |    759 |     
 | 
|  |    760 |   \begin{itemize}
 | 
|  |    761 |   \item a global outage on 2 July 2019 at \textbf{Cloudflare} 
 | 
|  |    762 |   (first one for six years)\medskip
 | 
|  |    763 |   
 | 
|  |    764 |   \begin{center}\small\color{blue}
 | 
|  |    765 |   \begin{verbatim}  
 | 
|  |    766 |   (?:(?:\"|'|\]|\}|\\|\d|(?:nan|infinity|true|false|
 | 
|  |    767 |   null|undefined|symbol|math)|\`|\-|\+)+[)]*;?((?:\s
 | 
|  |    768 |   |-|~|!|{}|\|\||\+)*.*(?:.*=.*)))  
 | 
|  |    769 |   \end{verbatim}
 | 
|  |    770 |   \end{center}\bigskip\bigskip\bigskip\bigskip\bigskip\bigskip\bigskip    
 | 
|  |    771 |   
 | 
|  |    772 |   \item on 20 July 2016 the \textbf{Stack Exchange} webpage went down
 | 
|  |    773 |     because of an evil regular expression
 | 
|  |    774 |     \here{https://stackstatus.net/post/147710624694/outage-postmortem-july-20-2016}    
 | 
|  |    775 |   \end{itemize}
 | 
|  |    776 |   
 | 
|  |    777 |   \begin{textblock}{6}(6,7.6)
 | 
|  |    778 |     \includegraphics[scale=0.14]{../pics/cloudflare.png}\\
 | 
|  |    779 |     \footnotesize
 | 
|  |    780 |     It serves more web traffic than Twitter, Amazon, Apple,
 | 
|  |    781 |     Instagram, Bing \& Wikipedia combined.
 | 
|  |    782 |     \here{https://blog.cloudflare.com/details-of-the-cloudflare-outage-on-july-2-2019/}
 | 
|  |    783 |     \end{textblock}
 | 
|  |    784 |   
 | 
|  |    785 |   \end{frame}
 | 
|  |    786 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 | 
|  |    787 |     
 | 
|  |    788 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    789 | \begin{frame}[c]
 | 
|  |    790 | \frametitle{Evil Regular Expressions}
 | 
|  |    791 | 
 | 
|  |    792 | \begin{itemize}
 | 
|  |    793 | \item \alert{R}egular \alert{e}xpression \alert{D}enial \alert{o}f \alert{S}ervice (ReDoS)\medskip
 | 
|  |    794 | \item Some evil regular expressions:\medskip
 | 
|  |    795 | \begin{itemize}
 | 
|  |    796 | \item \bl{\texttt{[a?]\{n\}\;[a]\{n\}}}
 | 
|  |    797 | \item \bl{\texttt{(a*)*\;b}}  
 | 
|  |    798 | \item \bl{\texttt{([a-z]+)*}} 
 | 
|  |    799 | \item \bl{\texttt{(a + aa)*}}
 | 
|  |    800 | \item \bl{\texttt{(a + a?)*}}
 | 
|  |    801 | \end{itemize}
 | 
|  |    802 | 
 | 
|  |    803 | \item sometimes also called \alert{catastrophic backtracking}
 | 
|  |    804 | \item this is a problem for \alert{N}etwork \alert{I}ntrusion
 | 
|  |    805 |   \alert{D}etection systems, Cloudflare, StackExchange, Atom editor
 | 
|  |    806 | \item \url{https://vimeo.com/112065252}  
 | 
|  |    807 | \end{itemize}
 | 
|  |    808 | 
 | 
|  |    809 | \end{frame}
 | 
|  |    810 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    811 | 
 | 
|  |    812 | 
 | 
|  |    813 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    814 | %\begin{frame}[c]
 | 
|  |    815 | %\frametitle{Today}
 | 
|  |    816 | %
 | 
|  |    817 | %\begin{itemize}
 | 
|  |    818 | %\item While the ultimate goal is to implement a small compiler for the JVM
 | 
|  |    819 | %  \ldots\bigskip
 | 
|  |    820 | %\end{itemize}
 | 
|  |    821 | %
 | 
|  |    822 | %Let's start with:
 | 
|  |    823 | %
 | 
|  |    824 | %\begin{itemize}
 | 
|  |    825 | %\item a web-crawler
 | 
|  |    826 | %\item an email harvester
 | 
|  |    827 | %\item \textcolor{gray}{(a web-scraper)}
 | 
|  |    828 | %\end{itemize}
 | 
|  |    829 | %
 | 
|  |    830 | %\end{frame}
 | 
|  |    831 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
 | 
|  |    832 | 
 | 
|  |    833 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    834 | %\begin{frame}[t]
 | 
|  |    835 | %\frametitle{A Web-Crawler}
 | 
|  |    836 | %
 | 
|  |    837 | %\mbox{}\\[10mm]
 | 
|  |    838 | %
 | 
|  |    839 | %\begin{enumerate}
 | 
|  |    840 | %\item given an URL, read the corresponding webpage
 | 
|  |    841 | %\item extract all links from it
 | 
|  |    842 | %\item call the web-crawler again for all these links
 | 
|  |    843 | %\end{enumerate}
 | 
|  |    844 | %
 | 
|  |    845 | %\end{frame}
 | 
|  |    846 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    847 | 
 | 
|  |    848 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    849 | %\begin{frame}[t]
 | 
|  |    850 | %\frametitle{A Web-Crawler}
 | 
|  |    851 | %
 | 
|  |    852 | %\mbox{}\\[10mm]
 | 
|  |    853 | %
 | 
|  |    854 | %
 | 
|  |    855 | %\begin{enumerate}
 | 
|  |    856 | %\item given an URL, read the corresponding webpage
 | 
|  |    857 | %\item if not possible print, out a problem
 | 
|  |    858 | %\item if possible, extract all links from it
 | 
|  |    859 | %\item call the web-crawler again for all these links
 | 
|  |    860 | %\end{enumerate}\bigskip\pause
 | 
|  |    861 | %
 | 
|  |    862 | %\small (we need a bound for the number of recursive calls)
 | 
|  |    863 | %
 | 
|  |    864 | %\small (the purpose is to check all links on my own webpage)
 | 
|  |    865 | %\end{frame}
 | 
|  |    866 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    867 | 
 | 
|  |    868 | 
 | 
|  |    869 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    870 | %\begin{frame}[c]
 | 
|  |    871 | %
 | 
|  |    872 | %\begin{textblock}{1}(2,5)
 | 
|  |    873 | %\begin{tabular}{c}
 | 
|  |    874 | %\includegraphics[scale=0.15]{pics/servers.png}\\[-2mm]
 | 
|  |    875 | %\small Server
 | 
|  |    876 | %\end{tabular}
 | 
|  |    877 | %\end{textblock}
 | 
|  |    878 | %
 | 
|  |    879 | %\begin{textblock}{1}(5.6,4)
 | 
|  |    880 | %  \begin{tikzpicture}[scale=1.1]
 | 
|  |    881 | %  \draw[white] (0,1) node (X) {};
 | 
|  |    882 | %  \draw[white] (2,1) node (Y) {};
 | 
|  |    883 | %   \draw[white] (0,0) node (X1) {};
 | 
|  |    884 | %  \draw[white] (2,0) node (Y1) {};
 | 
|  |    885 | %   \draw[white] (0,-1) node (X2) {};
 | 
|  |    886 | %  \draw[white] (2,-1) node (Y2) {};
 | 
|  |    887 | %  \draw[red, <-, line width = 2mm] (X) -- (Y);
 | 
|  |    888 | %  \node [inner sep=5pt,label=above:\textcolor{black}{GET request}] at ($ (X)!.5!(Y) $) {};
 | 
|  |    889 | %  \draw[red, ->, line width = 2mm] (X1) -- (Y1);
 | 
|  |    890 | %  \node [inner sep=5pt,label=above:\textcolor{black}{webpage}] at ($ (X1)!.5!(Y1) $) {};
 | 
|  |    891 | %  \draw[red, <-, line width = 2mm] (X2) -- (Y2);
 | 
|  |    892 | %  \node [inner sep=7pt,label=above:\textcolor{black}{POST data}] at ($ (X2)!.5!(Y2) $) {};
 | 
|  |    893 | %  \end{tikzpicture}
 | 
|  |    894 | %\end{textblock}
 | 
|  |    895 | %
 | 
|  |    896 | %
 | 
|  |    897 | %\begin{textblock}{1}(9,5.5)
 | 
|  |    898 | %\begin{tabular}{c}
 | 
|  |    899 | %\includegraphics[scale=0.15]{pics/laptop.png}\\[-2mm]
 | 
|  |    900 | %\small Browser
 | 
|  |    901 | %\end{tabular}
 | 
|  |    902 | %\end{textblock}
 | 
|  |    903 | %\end{frame}
 | 
|  |    904 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    905 | 
 | 
|  |    906 |   
 | 
|  |    907 | 
 | 
|  |    908 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    909 | %\begin{frame}[c]
 | 
|  |    910 | %\frametitle{Scala}
 | 
|  |    911 | %
 | 
|  |    912 | %\small A simple Scala function for reading webpages:
 | 
|  |    913 | %\bigskip
 | 
|  |    914 | %
 | 
|  |    915 | %\footnotesize
 | 
|  |    916 | %\lstinputlisting{../progs/app0.scala}
 | 
|  |    917 | %\medskip\pause
 | 
|  |    918 | %
 | 
|  |    919 | %\lstinline{get_page("""https://nms.kcl.ac.uk/christian.urban/""")}
 | 
|  |    920 | %\bigskip\medskip\pause
 | 
|  |    921 | %
 | 
|  |    922 | %
 | 
|  |    923 | %\small A slightly more complicated version for handling errors:
 | 
|  |    924 | %\smallskip
 | 
|  |    925 | %
 | 
|  |    926 | %\footnotesize
 | 
|  |    927 | %\lstinputlisting[xleftmargin=-4mm]{../progs/app1.scala}
 | 
|  |    928 | %
 | 
|  |    929 | %
 | 
|  |    930 | %\end{frame}
 | 
|  |    931 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    932 | 
 | 
|  |    933 |  
 | 
|  |    934 | 
 | 
|  |    935 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    936 | %\begin{frame}[t]
 | 
|  |    937 | %\frametitle{A Regular Expression}
 | 
|  |    938 | %
 | 
|  |    939 | %\begin{itemize}
 | 
|  |    940 | %\item \ldots{} is a pattern or template for specifying strings
 | 
|  |    941 | %\end{itemize}\bigskip
 | 
|  |    942 | %  
 | 
|  |    943 | %\begin{center}  
 | 
|  |    944 | %\only<1>{\scode{"https?://[^"]*"}}%
 | 
|  |    945 | %\only<2>{\scode{""""https?://[^"]*"""".r}}
 | 
|  |    946 | %\end{center}\bigskip\bigskip
 | 
|  |    947 | %
 | 
|  |    948 | %matches for example\smallskip\\  
 | 
|  |    949 | %\hspace{2mm}\code{"http://www.foobar.com"}\\
 | 
|  |    950 | %\hspace{2mm}\code{"https://www.tls.org"}\smallskip\\
 | 
|  |    951 | %
 | 
|  |    952 | %but not\smallskip\\  
 | 
|  |    953 | %\hspace{2mm}\code{"http://www."foo"bar.com"}\\
 | 
|  |    954 | %
 | 
|  |    955 | %\end{frame}
 | 
|  |    956 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    957 | 
 | 
|  |    958 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    959 | %\begin{frame}[c]
 | 
|  |    960 | %\frametitle{Finding Operations in Scala}
 | 
|  |    961 | %
 | 
|  |    962 | %{\bf\code{rexp.findAllIn(string)}}\medskip
 | 
|  |    963 | %  
 | 
|  |    964 | %returns a list of all (sub)strings that match the 
 | 
|  |    965 | %regular expression
 | 
|  |    966 | %\bigskip\bigskip  
 | 
|  |    967 | %  
 | 
|  |    968 | %
 | 
|  |    969 | %{\bf\code{rexp.findFirstIn(string)}}\medskip
 | 
|  |    970 | % 
 | 
|  |    971 | %returns either 
 | 
|  |    972 | %
 | 
|  |    973 | %\begin{itemize}
 | 
|  |    974 | %\item \code{None} if no (sub)string matches or 
 | 
|  |    975 | %\item \code{Some(s)} with the first (sub)string
 | 
|  |    976 | %\end{itemize}
 | 
|  |    977 | %
 | 
|  |    978 | %\end{frame}
 | 
|  |    979 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    980 | 
 | 
|  |    981 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    982 | %\begin{frame}[c]
 | 
|  |    983 | %
 | 
|  |    984 | %\footnotesize
 | 
|  |    985 | %\lstinputlisting{../progs/app2.scala}
 | 
|  |    986 | %
 | 
|  |    987 | %\end{frame}
 | 
|  |    988 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |    989 | 
 | 
|  |    990 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |    991 | %\begin{frame}[c]
 | 
|  |    992 | %
 | 
|  |    993 | %\small
 | 
|  |    994 | %A version that only crawls links in ``my'' domain:\bigskip
 | 
|  |    995 | %
 | 
|  |    996 | %\footnotesize
 | 
|  |    997 | %\lstinputlisting{../progs/app3.scala}
 | 
|  |    998 | %
 | 
|  |    999 | %\end{frame}
 | 
|  |   1000 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |   1001 | 
 | 
|  |   1002 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1003 | %\begin{frame}[c]
 | 
|  |   1004 | %\lstset{xleftmargin=-4mm}
 | 
|  |   1005 | %\small
 | 
|  |   1006 | %A little email harvester:
 | 
|  |   1007 | %
 | 
|  |   1008 | %\footnotesize
 | 
|  |   1009 | %\lstinputlisting{../progs/app4.scala}\bigskip
 | 
|  |   1010 | %
 | 
|  |   1011 | %\tiny
 | 
|  |   1012 | %\url{http://net.tutsplus.com/tutorials/other/8-regular-expressions-you-should-know/}
 | 
|  |   1013 | %
 | 
|  |   1014 | %\end{frame}
 | 
|  |   1015 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |   1016 | 
 | 
|  |   1017 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1018 | \begin{frame}[t]
 | 
|  |   1019 | \frametitle{(Basic) Regular Expressions}
 | 
|  |   1020 | 
 | 
|  |   1021 | Their inductive definition:
 | 
|  |   1022 | 
 | 
|  |   1023 | 
 | 
|  |   1024 | \begin{textblock}{6}(2,7.5)
 | 
|  |   1025 |   \begin{tabular}{@ {}rrl@ {\hspace{13mm}}l}
 | 
|  |   1026 |   \bl{$r$} & \bl{$::=$}  & \bl{$\ZERO$}  & nothing\\
 | 
|  |   1027 |          & \bl{$\mid$} & \bl{$\ONE$}       & empty string / \pcode{""} / $[]$\\
 | 
|  |   1028 |          & \bl{$\mid$} & \bl{$c$}                         & character\\
 | 
|  |   1029 |          & \bl{$\mid$} & \bl{$r_1 + r_2$}  & alternative / choice\\
 | 
|  |   1030 |          & \bl{$\mid$} & \bl{$r_1 \cdot r_2$} & sequence\\
 | 
|  |   1031 |          & \bl{$\mid$} & \bl{$r^*$}            & star (zero or more)\\
 | 
|  |   1032 |   \end{tabular}
 | 
|  |   1033 |   \end{textblock}
 | 
|  |   1034 |   
 | 
|  |   1035 |   
 | 
|  |   1036 | \only<2->{\footnotesize
 | 
|  |   1037 | \begin{textblock}{9}(2,0.5)
 | 
|  |   1038 | \begin{bubble}[9.8cm]
 | 
|  |   1039 | \lstinputlisting{../progs/app01.scala}
 | 
|  |   1040 | \end{bubble}
 | 
|  |   1041 | \end{textblock}}
 | 
|  |   1042 |   
 | 
|  |   1043 | \end{frame}
 | 
|  |   1044 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |   1045 | 
 | 
|  |   1046 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1047 | %\begin{frame}[t]
 | 
|  |   1048 | %\frametitle{Regular Expressions}
 | 
|  |   1049 | %
 | 
|  |   1050 | %\small
 | 
|  |   1051 | %In Scala:\bigskip
 | 
|  |   1052 | %
 | 
|  |   1053 | %\footnotesize
 | 
|  |   1054 | %\lstinputlisting{../progs/app51.scala}
 | 
|  |   1055 | %
 | 
|  |   1056 | %  
 | 
|  |   1057 | %\end{frame}
 | 
|  |   1058 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |   1059 | 
 | 
|  |   1060 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1061 | \begin{frame}[t]
 | 
|  |   1062 | \frametitle{Strings}
 | 
|  |   1063 | 
 | 
|  |   1064 | \ldots are lists of characters. For example \code{"hello"}
 | 
|  |   1065 | 
 | 
|  |   1066 | \begin{center}
 | 
|  |   1067 | \bl{$[h, e, l, l, o]$} or just \bl{$hello$}
 | 
|  |   1068 | \end{center}
 | 
|  |   1069 | 
 | 
|  |   1070 | the empty string: \bl{$[]$} or \bl{\pcode{""}}\bigskip\\
 | 
|  |   1071 | 
 | 
|  |   1072 | the concatenation of two strings:
 | 
|  |   1073 | 
 | 
|  |   1074 | \begin{center}
 | 
|  |   1075 | \bl{$s_1 \,@\, s_2$}
 | 
|  |   1076 | \end{center}
 | 
|  |   1077 | 
 | 
|  |   1078 | \bl{\textit{foo $@$ bar = foobar}}\\
 | 
|  |   1079 | \bl{\textit{baz $@\, []$ = baz}}
 | 
|  |   1080 |   
 | 
|  |   1081 | \end{frame}
 | 
|  |   1082 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |   1083 | 
 | 
|  |   1084 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1085 | \begin{frame}[c]
 | 
|  |   1086 | \frametitle{Languages, Strings}
 | 
|  |   1087 | 
 | 
|  |   1088 | \begin{itemize}
 | 
|  |   1089 | \item \alert{\bf Strings} are lists of characters, for example
 | 
|  |   1090 | \begin{center}
 | 
|  |   1091 | \bl{$[]$},\;\bl{$abc$}  \hspace{2cm}(Pattern match: \bl{$c\!::\!s$})
 | 
|  |   1092 | \end{center}\bigskip
 | 
|  |   1093 | 
 | 
|  |   1094 | 
 | 
|  |   1095 | \item A \alert{\bf language} is a set of strings, for example\medskip
 | 
|  |   1096 | \begin{center}
 | 
|  |   1097 | \bl{$\{[], hello, \textit{foobar}, a, abc\}$}
 | 
|  |   1098 | \end{center}\bigskip
 | 
|  |   1099 | 
 | 
|  |   1100 | \item \alert{\bf Concatenation} of strings and languages
 | 
|  |   1101 | 
 | 
|  |   1102 | \begin{center}
 | 
|  |   1103 | \begin{tabular}{rcl}
 | 
|  |   1104 | \bl{$\textit{foo}\;@\;bar$} & \bl{$=$} & \bl{$\textit{foobar}$}\medskip\\
 | 
|  |   1105 | \bl{$A\;@\;B$} & \bl{$\dn$} & \bl{$\{ s_1\,@\,s_2 \;\mid\; s_1 \in A \wedge s_2 \in B\}$}
 | 
|  |   1106 | \end{tabular}
 | 
|  |   1107 | \end{center}
 | 
|  |   1108 | 
 | 
|  |   1109 | %\item The \alert{\bf meaning} of a regular expression is a set of 
 | 
|  |   1110 | %  strings, or language.
 | 
|  |   1111 | \end{itemize}  
 | 
|  |   1112 | 
 | 
|  |   1113 | \only<2>{
 | 
|  |   1114 | \begin{textblock}{4}(10.5,8)
 | 
|  |   1115 | \small
 | 
|  |   1116 | Let
 | 
|  |   1117 | 
 | 
|  |   1118 | \bl{$A = \{foo, bar\}$} \bl{$B = \{a, b\}$}
 | 
|  |   1119 | \[
 | 
|  |   1120 | \bl{A \,@\, B = \{fooa, foob, bara, barb\}}
 | 
|  |   1121 | \]
 | 
|  |   1122 | \end{textblock}}  
 | 
|  |   1123 | 
 | 
|  |   1124 | \end{frame}
 | 
|  |   1125 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |   1126 | 
 | 
|  |   1127 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1128 | \begin{frame}[c]
 | 
|  |   1129 |   \frametitle{Two Corner Cases}
 | 
|  |   1130 |    
 | 
|  |   1131 |   \Large
 | 
|  |   1132 |   \begin{center}
 | 
|  |   1133 |   \bl{$A \,@\, \{[]\} = \;?$}\bigskip\bigskip\pause\\
 | 
|  |   1134 |   \bl{$A \,@\, \{\} = \;?$}
 | 
|  |   1135 |   \end{center}  
 | 
|  |   1136 |     
 | 
|  |   1137 |   \end{frame}
 | 
|  |   1138 |   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
 | 
|  |   1139 |   
 | 
|  |   1140 | 
 | 
|  |   1141 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1142 | \begin{frame}[c]
 | 
|  |   1143 | \frametitle{The Meaning of a Regex}
 | 
|  |   1144 | 
 | 
|  |   1145 |  ...all the strings a regular expression can match.   
 | 
|  |   1146 | 
 | 
|  |   1147 | \begin{center}
 | 
|  |   1148 |  \begin{tabular}{rcl}
 | 
|  |   1149 |  \bl{$L(\ZERO)$}  & \bl{$\dn$} & \bl{$\{\}$}\\
 | 
|  |   1150 |  \bl{$L(\ONE)$}     & \bl{$\dn$} & \bl{$\{[]\}$}\\
 | 
|  |   1151 |  \bl{$L(c)$}            & \bl{$\dn$} & \bl{$\{[c]\}$}\\
 | 
|  |   1152 |  \bl{$L(r_1 + r_2)$}    & \bl{$\dn$} & \bl{$L(r_1) \cup L(r_2)$}\\
 | 
|  |   1153 |  \bl{$L(r_1 \cdot r_2)$} & \bl{$\dn$} & \bl{$L(r_1) \,@\, L(r_2)$}\\
 | 
|  |   1154 |  \bl{$L(r^*)$}           & \bl{$\dn$} & \\
 | 
|  |   1155 |   \end{tabular}
 | 
|  |   1156 | \end{center}
 | 
|  |   1157 | 
 | 
|  |   1158 | \begin{textblock}{14}(1.5,13.5)\small
 | 
|  |   1159 | \bl{$L$} is a function from regular expressions to 
 | 
|  |   1160 | sets of strings (languages):\smallskip\\
 | 
|  |   1161 | \bl{\quad$L$ : Rexp $\Rightarrow$ Set$[$String$]$}
 | 
|  |   1162 | \end{textblock}
 | 
|  |   1163 | 
 | 
|  |   1164 | \end{frame}
 | 
|  |   1165 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1166 | 
 | 
|  |   1167 | 
 | 
|  |   1168 | 
 | 
|  |   1169 | 
 | 
|  |   1170 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1171 | \begin{frame}[c]
 | 
|  |   1172 |   \frametitle{The Power Operation}
 | 
|  |   1173 |   
 | 
|  |   1174 |   \begin{itemize}
 | 
|  |   1175 |   \item The \alert{\textbf{\boldmath$n$th Power}} of a language:
 | 
|  |   1176 |   
 | 
|  |   1177 |   \begin{center}
 | 
|  |   1178 |   \begin{tabular}{lcl}
 | 
|  |   1179 |   \bl{$A^0$}    & \bl{$\dn$} & \bl{$\{[]\}$}\\
 | 
|  |   1180 |   \bl{$A^{n+1}$} & \bl{$\dn$} & \bl{$A \,@\, A^n$}
 | 
|  |   1181 |   \end{tabular}
 | 
|  |   1182 |   \end{center}\bigskip
 | 
|  |   1183 |   
 | 
|  |   1184 |   \item[] For example
 | 
|  |   1185 |   
 | 
|  |   1186 |   \begin{center}
 | 
|  |   1187 |   \begin{tabular}{lcl@{\hspace{10mm}}l}
 | 
|  |   1188 |   \bl{$A^4$} & \bl{$=$} & \bl{$A \,@\, A \,@\, A \,@\, A$} & \bl{$(@\,\{[]\})$}\\
 | 
|  |   1189 |   \bl{$A^1$} & \bl{$=$} & \bl{$A$} & \bl{$(@\,\{[]\})$}\\
 | 
|  |   1190 |   \bl{$A^0$} & \bl{$=$} & \bl{$\{[]\}$}\\
 | 
|  |   1191 |   \end{tabular}
 | 
|  |   1192 |   \end{center}
 | 
|  |   1193 |   
 | 
|  |   1194 |   \end{itemize}  
 | 
|  |   1195 |   
 | 
|  |   1196 |   \end{frame}
 | 
|  |   1197 |   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1198 |   
 | 
|  |   1199 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1200 | \begin{frame}[c]
 | 
|  |   1201 | \frametitle{The Meaning of a Regex}
 | 
|  |   1202 | 
 | 
|  |   1203 | \begin{textblock}{15}(1,4)
 | 
|  |   1204 |  \begin{tabular}{rcl}
 | 
|  |   1205 |  \bl{$L(\ZERO)$}  & \bl{$\dn$} & \bl{$\{\}$}\\
 | 
|  |   1206 |  \bl{$L(\ONE)$}     & \bl{$\dn$} & \bl{$\{[]\}$}\\
 | 
|  |   1207 |  \bl{$L(c)$}            & \bl{$\dn$} & \bl{$\{[c]\}$}\\
 | 
|  |   1208 |  \bl{$L(r_1 + r_2)$}    & \bl{$\dn$} & \bl{$L(r_1) \cup L(r_2)$}\\
 | 
|  |   1209 |  \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) \}$}\\
 | 
|  |   1210 |  \bl{$L(r^*)$}           & \bl{$\dn$} & \onslide<2->{\bl{$\bigcup_{0 \le n} L(r)^n$}}\\
 | 
|  |   1211 |   \end{tabular}\bigskip
 | 
|  |   1212 |   
 | 
|  |   1213 | %\onslide<2->{
 | 
|  |   1214 | %\hspace{5mm}\bl{$L(r)^0 \;\dn\; \{[]\}$}\\
 | 
|  |   1215 | %\bl{$L(r)^{n+1} \;\dn\; L(r) \,@\, L(r)^n$}\hspace{9mm}\onslide<3->{\small\textcolor{gray}{(append on sets)}\\
 | 
|  |   1216 | %\small\hspace{5cm}\textcolor{gray}{$\{ s_1 @ s_2 \;|\; s_1\in L(r) \wedge s_2 \in L(r)^n \}$}}
 | 
|  |   1217 | %}  
 | 
|  |   1218 | \end{textblock}
 | 
|  |   1219 | 
 | 
|  |   1220 | \end{frame}
 | 
|  |   1221 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |   1222 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1223 | \begin{frame}[c]
 | 
|  |   1224 |   \frametitle{The Star Operation}
 | 
|  |   1225 |   
 | 
|  |   1226 |   \begin{itemize}
 | 
|  |   1227 |   \item The \alert{\bf Kleene Star} of a \underline{language}:
 | 
|  |   1228 |   \bigskip
 | 
|  |   1229 |   
 | 
|  |   1230 |   \begin{center}
 | 
|  |   1231 |   \begin{tabular}{c}
 | 
|  |   1232 |   \bl{$A\star \dn \bigcup_{0\le n} A^n$}
 | 
|  |   1233 |   \end{tabular}
 | 
|  |   1234 |   \end{center}\bigskip
 | 
|  |   1235 |   
 | 
|  |   1236 |   \item[] This expands to 
 | 
|  |   1237 |   
 | 
|  |   1238 |   \[
 | 
|  |   1239 |   \bl{A^0 \cup A^1 \cup A^2 \cup A^3 \cup A^4 \cup \ldots}
 | 
|  |   1240 |   \]
 | 
|  |   1241 |   
 | 
|  |   1242 |   or
 | 
|  |   1243 |   
 | 
|  |   1244 |   \small
 | 
|  |   1245 |   \[
 | 
|  |   1246 |   \bl{\{[]\} \;\cup\; A \;\cup\; A\,@\,A \;\cup\; 
 | 
|  |   1247 |     A\,@\,A\,@\,A \;\cup\; A\,@\,A\,@\,A\,@\,A \cup \ldots}
 | 
|  |   1248 |   \]
 | 
|  |   1249 |   
 | 
|  |   1250 |   \end{itemize}  
 | 
|  |   1251 |   
 | 
|  |   1252 |   \end{frame}
 | 
|  |   1253 |   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |   1254 | 
 | 
|  |   1255 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1256 | \begin{frame}[c]
 | 
|  |   1257 | \frametitle{The Meaning of a Regex}
 | 
|  |   1258 | 
 | 
|  |   1259 | \begin{textblock}{15}(1,4)
 | 
|  |   1260 |  \begin{tabular}{rcl}
 | 
|  |   1261 |  \bl{$L(\ZERO)$}  & \bl{$\dn$} & \bl{$\{\}$}\\
 | 
|  |   1262 |  \bl{$L(\ONE)$}     & \bl{$\dn$} & \bl{$\{[]\}$}\\
 | 
|  |   1263 |  \bl{$L(c)$}            & \bl{$\dn$} & \bl{$\{[c]\}$}\\
 | 
|  |   1264 |  \bl{$L(r_1 + r_2)$}    & \bl{$\dn$} & \bl{$L(r_1) \cup L(r_2)$}\\
 | 
|  |   1265 |  \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) \}$}\\
 | 
|  |   1266 |  \bl{$L(r^*)$}           & \bl{$\dn$} & \bl{$(L(r))\star$}\\
 | 
|  |   1267 |   \end{tabular}
 | 
|  |   1268 |   
 | 
|  |   1269 | \end{textblock}
 | 
|  |   1270 | 
 | 
|  |   1271 | \end{frame}
 | 
|  |   1272 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1273 | 
 | 
|  |   1274 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1275 | \begin{frame}[c]
 | 
|  |   1276 | \frametitle{The Meaning of Matching}
 | 
|  |   1277 | 
 | 
|  |   1278 | \begin{bubble}[10cm]
 | 
|  |   1279 | \large\bf 
 | 
|  |   1280 | A regular expression \bl{$r$} matches a string~\bl{$s$} 
 | 
|  |   1281 | provided
 | 
|  |   1282 | 
 | 
|  |   1283 | \begin{center}
 | 
|  |   1284 | \bl{$s \in L(r)$}\\ 
 | 
|  |   1285 | \end{center}
 | 
|  |   1286 | \end{bubble}\bigskip\bigskip
 | 
|  |   1287 | 
 | 
|  |   1288 | \ldots and the point of the next lecture is 
 | 
|  |   1289 | to decide this problem as fast as possible (unlike Python,
 | 
|  |   1290 | Ruby, Java)
 | 
|  |   1291 | 
 | 
|  |   1292 | \end{frame}
 | 
| 879 |   1293 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1294 | 
 | 
|  |   1295 | 
 | 
| 876 |   1296 | 
 | 
|  |   1297 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1298 | \begin{frame}[c]
 | 
|  |   1299 |   \frametitle{Questions}
 | 
|  |   1300 |   
 | 
|  |   1301 |   \begin{itemize}
 | 
|  |   1302 |   \item Say \bl{$A = \{[a],[b],[c],[d]\}$}.\bigskip
 | 
|  |   1303 |   
 | 
|  |   1304 |   \item[]
 | 
|  |   1305 |   How many strings are in \bl{$A^4$}\,?
 | 
|  |   1306 |   \bigskip\medskip\pause
 | 
|  |   1307 |   
 | 
|  |   1308 |   
 | 
|  |   1309 |  \item[]
 | 
|  |   1310 |   What if \bl{$A = \{[a],[b],[c],[]\}$};\\ 
 | 
|  |   1311 |   how many strings are then in \bl{$A^4$}\,?
 | 
|  |   1312 |   \end{itemize}  
 | 
|  |   1313 |   
 | 
|  |   1314 | \end{frame}
 | 
|  |   1315 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
 | 
|  |   1316 | 
 | 
|  |   1317 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
| 879 |   1318 | \begin{frame}[c]
 | 
|  |   1319 |   \frametitle{Questions}
 | 
|  |   1320 | 
 | 
|  |   1321 |   \begin{itemize}
 | 
|  |   1322 |   \item Assume a set $A$ contains 4 strings and a set $B$
 | 
|  |   1323 |   contains 7 strings. None of the strings is the empty
 | 
|  |   1324 |   string.
 | 
|  |   1325 | 
 | 
|  |   1326 |   \item How many strings are in $A \,@\, B$?
 | 
|  |   1327 |   \end{itemize}
 | 
|  |   1328 | 
 | 
|  |   1329 |   
 | 
|  |   1330 | \end{frame}
 | 
|  |   1331 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
 | 
|  |   1332 | 
 | 
|  |   1333 | 
 | 
|  |   1334 | 
 | 
|  |   1335 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
| 876 |   1336 | % \begin{frame}[c]
 | 
|  |   1337 | % \frametitle{Languages (Sets of Strings)}
 | 
|  |   1338 | 
 | 
|  |   1339 | % \begin{itemize}
 | 
|  |   1340 | 
 | 
|  |   1341 | % \item A \alert{\bf Language} is a set of strings, for example\medskip
 | 
|  |   1342 | % \begin{center}
 | 
|  |   1343 | % \bl{$\{[], hello, foobar, a, abc\}$}
 | 
|  |   1344 | % \end{center}\bigskip
 | 
|  |   1345 | 
 | 
|  |   1346 | % \item \alert{\bf Concatenation} for strings and languages
 | 
|  |   1347 | 
 | 
|  |   1348 | % \begin{center}
 | 
|  |   1349 | % \begin{tabular}{rcl}
 | 
|  |   1350 | % \bl{$foo\;@\;bar$} & \bl{$=$} & \bl{$foobar$}\medskip\\
 | 
|  |   1351 | % \bl{$A\;@\;B$}     & \bl{$\dn$} & \bl{$\{ s_1\,@\,s_2 \;\mid\; s_1 \in A \wedge s_2 \in B\}$}
 | 
|  |   1352 | % \end{tabular}
 | 
|  |   1353 | % \end{center}
 | 
|  |   1354 | % \bigskip
 | 
|  |   1355 | 
 | 
|  |   1356 | % \small
 | 
|  |   1357 | % \item [] For example \bl{$A = \{foo, bar\}$}, \bl{$B = \{a, b\}$}
 | 
|  |   1358 | 
 | 
|  |   1359 | % \[
 | 
|  |   1360 | % \bl{A \,@\, B = \{fooa, foob, bara, barb\}}
 | 
|  |   1361 | % \]
 | 
|  |   1362 | 
 | 
|  |   1363 | 
 | 
|  |   1364 | 
 | 
|  |   1365 | 
 | 
|  |   1366 | % \end{itemize}  
 | 
|  |   1367 | % \end{frame}
 | 
|  |   1368 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |   1369 | 
 | 
|  |   1370 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1371 | % \begin{frame}[c]
 | 
|  |   1372 | %   \frametitle{Two Corner Cases}
 | 
|  |   1373 |    
 | 
|  |   1374 | %   \Large
 | 
|  |   1375 | %   \begin{center}
 | 
|  |   1376 | %   \bl{$A \,@\, \{[]\} = \;?$}\bigskip\bigskip\pause\\
 | 
|  |   1377 | %   \bl{$A \,@\, \{\} = \;?$}
 | 
|  |   1378 | %   \end{center}  
 | 
|  |   1379 |     
 | 
|  |   1380 | %   \end{frame}
 | 
|  |   1381 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
 | 
|  |   1382 |   
 | 
|  |   1383 | 
 | 
|  |   1384 | 
 | 
|  |   1385 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1386 | % \begin{frame}[c]
 | 
|  |   1387 | % \frametitle{The Meaning of a Regex}
 | 
|  |   1388 | 
 | 
|  |   1389 | %  ...all the strings a regular expression can match.   
 | 
|  |   1390 | 
 | 
|  |   1391 | % \begin{center}
 | 
|  |   1392 | %  \begin{tabular}{rcl}
 | 
|  |   1393 | %  \bl{$L(\ZERO)$}  & \bl{$\dn$} & \bl{$\{\}$}\\
 | 
|  |   1394 | %  \bl{$L(\ONE)$}     & \bl{$\dn$} & \bl{$\{[]\}$}\\
 | 
|  |   1395 | %  \bl{$L(c)$}            & \bl{$\dn$} & \bl{$\{[c]\}$}\\
 | 
|  |   1396 | %  \bl{$L(r_1 + r_2)$}    & \bl{$\dn$} & \bl{$L(r_1) \cup L(r_2)$}\\
 | 
|  |   1397 | %  \bl{$L(r_1 \cdot r_2)$} & \bl{$\dn$} & \bl{$L(r_1) \,@\, L(r_2)$}\\
 | 
|  |   1398 | %  \bl{$L(r^*)$}           & \bl{$\dn$} & \\
 | 
|  |   1399 | %   \end{tabular}
 | 
|  |   1400 | % \end{center}
 | 
|  |   1401 | 
 | 
|  |   1402 | % \begin{textblock}{14}(1.5,13.5)\small
 | 
|  |   1403 | % \bl{$L$} is a function from regular expressions to 
 | 
|  |   1404 | % sets of strings (languages):\smallskip\\
 | 
|  |   1405 | % \bl{\quad$L$ : Rexp $\Rightarrow$ Set$[$String$]$}
 | 
|  |   1406 | % \end{textblock}
 | 
|  |   1407 | 
 | 
|  |   1408 | % \end{frame}
 | 
|  |   1409 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1410 | 
 | 
|  |   1411 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1412 | % \begin{frame}[c]
 | 
|  |   1413 | % \frametitle{The Power Operation}
 | 
|  |   1414 | 
 | 
|  |   1415 | % \begin{itemize}
 | 
|  |   1416 | % \item The \alert{\textbf{\boldmath$n$th Power}} of a language:
 | 
|  |   1417 | 
 | 
|  |   1418 | % \begin{center}
 | 
|  |   1419 | % \begin{tabular}{lcl}
 | 
|  |   1420 | % \bl{$A^0$}    & \bl{$\dn$} & \bl{$\{[]\}$}\\
 | 
|  |   1421 | % \bl{$A^{n+1}$} & \bl{$\dn$} & \bl{$A \,@\, A^n$}
 | 
|  |   1422 | % \end{tabular}
 | 
|  |   1423 | % \end{center}\bigskip
 | 
|  |   1424 | 
 | 
|  |   1425 | % \item[] For example
 | 
|  |   1426 | 
 | 
|  |   1427 | % \begin{center}
 | 
|  |   1428 | % \begin{tabular}{lcl@{\hspace{10mm}}l}
 | 
|  |   1429 | % \bl{$A^4$} & \bl{$=$} & \bl{$A \,@\, A \,@\, A \,@\, A$} & \bl{$(@\,\{[]\})$}\\
 | 
|  |   1430 | % \bl{$A^1$} & \bl{$=$} & \bl{$A$} & \bl{$(@\,\{[]\})$}\\
 | 
|  |   1431 | % \bl{$A^0$} & \bl{$=$} & \bl{$\{[]\}$}\\
 | 
|  |   1432 | % \end{tabular}
 | 
|  |   1433 | % \end{center}
 | 
|  |   1434 | 
 | 
|  |   1435 | % \end{itemize}  
 | 
|  |   1436 | 
 | 
|  |   1437 | % \end{frame}
 | 
|  |   1438 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 | 
|  |   1439 | 
 | 
|  |   1440 | 
 | 
|  |   1441 | 
 | 
|  |   1442 | 
 | 
|  |   1443 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1444 | % \begin{frame}[c]
 | 
|  |   1445 | % \frametitle{Written Exam}
 | 
|  |   1446 | 
 | 
|  |   1447 | % \begin{itemize}
 | 
|  |   1448 | % \item Accounts for 80\%.\bigskip
 | 
|  |   1449 | 
 | 
|  |   1450 | % \item The question ``\textit{Is this relevant for
 | 
|  |   1451 | %       the exam?}'' is very demotivating for the lecturer!\bigskip\\
 | 
|  |   1452 | 
 | 
|  |   1453 | % \item Deal: Whatever is in the homework (and is not marked
 | 
|  |   1454 | %       ``\textit{optional}'') is relevant for the exam.\bigskip
 | 
|  |   1455 |       
 | 
|  |   1456 | % \item Each lecture has also a handout. There are also handouts about
 | 
|  |   1457 | % notation and Scala.      
 | 
|  |   1458 | % \end{itemize}
 | 
|  |   1459 | 
 | 
|  |   1460 | % \end{frame}
 | 
|  |   1461 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |   1462 | 
 | 
|  |   1463 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1464 | % \begin{frame}[t]
 | 
|  |   1465 | % \frametitle{Coursework}
 | 
|  |   1466 | 
 | 
|  |   1467 | % \begin{itemize}
 | 
|  |   1468 | % \item Accounts for 20\%. Two strands. Choose \alert{\bf one}!\bigskip
 | 
|  |   1469 | % \end{itemize}
 | 
|  |   1470 | 
 | 
|  |   1471 | % \begin{columns}[t]
 | 
|  |   1472 | % \begin{column}{.5\textwidth}
 | 
|  |   1473 | % \underline{\bf Strand 1}\medskip
 | 
|  |   1474 | % \begin{itemize}
 | 
|  |   1475 | % \item 4 programming tasks:
 | 
|  |   1476 | % \begin{itemize}
 | 
|  |   1477 | % \item matcher (4\%, 11.10.) 
 | 
|  |   1478 | % \item lexer (5\%, 04.11.)
 | 
|  |   1479 | % \item parser (5\%, 22.11.)
 | 
|  |   1480 | % \item compiler (6\%, 13.12.)
 | 
|  |   1481 | % \end{itemize}
 | 
|  |   1482 | % \item in any lang.~you like,\\ but I want to see the\\ code
 | 
|  |   1483 | % \end{itemize}
 | 
|  |   1484 | % \end{column}
 | 
|  |   1485 | 
 | 
|  |   1486 | % \hspace{-45pt}\vrule{}\hspace{10pt}
 | 
|  |   1487 | % \begin{column}{.5\textwidth}
 | 
|  |   1488 | % \underline{\bf Strand 2}\smallskip\begin{itemize}
 | 
|  |   1489 | % \item one task: prove the correctness of a regular expression matcher in 
 | 
|  |   1490 | % the \underline{Isabelle} theorem prover
 | 
|  |   1491 | % \item 20\%, submission on~13.12.\hspace{-5mm}\mbox{}
 | 
|  |   1492 | % \end{itemize}
 | 
|  |   1493 | % \end{column}
 | 
|  |   1494 | % \end{columns}\medskip
 | 
|  |   1495 | 
 | 
|  |   1496 | % \small
 | 
|  |   1497 | % \begin{itemize}
 | 
|  |   1498 | % \item Solving more than one strand will {\bf not} give you more 
 | 
|  |   1499 | % marks.
 | 
|  |   1500 | 
 | 
|  |   1501 | % \end{itemize}
 | 
|  |   1502 | 
 | 
|  |   1503 | % \end{frame}
 | 
|  |   1504 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |   1505 | 
 | 
|  |   1506 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1507 | %\begin{frame}[c]
 | 
|  |   1508 | %\frametitle{Lecture Capture}
 | 
|  |   1509 | %
 | 
|  |   1510 | %\begin{itemize}
 | 
|  |   1511 | %\item Hope it works\ldots\pause actually no, it does not!\medskip\pause
 | 
|  |   1512 | %\item It is important to use lecture capture wisely\\ (it is only the ``baseline''):
 | 
|  |   1513 | %\begin{itemize}  
 | 
|  |   1514 | %\item Lecture recordings are a study and revision aid.
 | 
|  |   1515 | %\item Statistically, there is a clear and direct link between attendance and
 | 
|  |   1516 | %  attainment: students who do not attend lectures, do less well in exams.
 | 
|  |   1517 | %\end{itemize}
 | 
|  |   1518 | %
 | 
|  |   1519 | %\item Attending a lecture is more than watching it online -- if you do not
 | 
|  |   1520 | %attend, you miss out!  
 | 
|  |   1521 | %  
 | 
|  |   1522 | %\end{itemize}
 | 
|  |   1523 | %
 | 
|  |   1524 | %\end{frame}
 | 
|  |   1525 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |   1526 | 
 | 
|  |   1527 | 
 | 
|  |   1528 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1529 | \begin{frame}[c]
 | 
|  |   1530 | \frametitle{\begin{tabular}{c}\\[3cm]\alert{Questions?}\end{tabular}}
 | 
|  |   1531 | 
 | 
|  |   1532 | 
 | 
|  |   1533 | \begin{tabular}{lll}
 | 
| 879 |   1534 |   TAs: & Huang Linh   & (took the module last year)\\
 | 
|  |   1535 |        & Alfredo Musumeci \\
 | 
|  |   1536 |        & Issa Kabir \\
 | 
| 876 |   1537 | \end{tabular}  
 | 
|  |   1538 | \mbox{}
 | 
|  |   1539 | \end{frame}
 | 
|  |   1540 | 
 | 
|  |   1541 | \begin{frame}[c]
 | 
|  |   1542 | \end{frame}
 | 
|  |   1543 | 
 | 
|  |   1544 | \begin{frame}[c]
 | 
|  |   1545 | \end{frame}
 | 
|  |   1546 | 
 | 
|  |   1547 | \begin{frame}[c]
 | 
|  |   1548 | \end{frame}
 | 
|  |   1549 | 
 | 
|  |   1550 | \begin{frame}[c]
 | 
|  |   1551 | \end{frame}
 | 
|  |   1552 | 
 | 
|  |   1553 | \begin{frame}[c]
 | 
|  |   1554 | \end{frame}
 | 
|  |   1555 | 
 | 
|  |   1556 | \begin{frame}[c]
 | 
|  |   1557 | \end{frame}
 | 
|  |   1558 | 
 | 
|  |   1559 | \begin{frame}[c]
 | 
|  |   1560 | \end{frame}
 | 
|  |   1561 | 
 | 
|  |   1562 | \begin{frame}[c]
 | 
|  |   1563 | \end{frame}
 | 
|  |   1564 | 
 | 
|  |   1565 | \begin{frame}[c]
 | 
|  |   1566 | \end{frame}
 | 
|  |   1567 | 
 | 
|  |   1568 | \begin{frame}[c]
 | 
|  |   1569 | \end{frame}
 | 
|  |   1570 | 
 | 
|  |   1571 | \begin{frame}[c]
 | 
|  |   1572 | \end{frame}
 | 
|  |   1573 | 
 | 
|  |   1574 | \begin{frame}[c]
 | 
|  |   1575 | \end{frame}
 | 
|  |   1576 | 
 | 
|  |   1577 | \begin{frame}[c]
 | 
|  |   1578 | \end{frame}
 | 
|  |   1579 | 
 | 
|  |   1580 | \begin{frame}[c]
 | 
|  |   1581 | \end{frame}
 | 
|  |   1582 | 
 | 
|  |   1583 | 
 | 
|  |   1584 | \begin{frame}[c]
 | 
|  |   1585 | \begin{mybox3}{Coursework}
 | 
|  |   1586 |   Do we need to provide instructions on running the coursework files
 | 
|  |   1587 |   if we're using languages other than Scala? Thanks
 | 
|  |   1588 | \end{mybox3}\pause
 | 
|  |   1589 | 
 | 
|  |   1590 | \begin{mybox2}{Zip-File for Coursework}
 | 
|  |   1591 |   Please, please submit a zipfile that generates a subdirectory
 | 
|  |   1592 |   \begin{center}
 | 
|  |   1593 |   \texttt{NameFamilyName}  
 | 
|  |   1594 |   \end{center}  
 | 
|  |   1595 | \end{mybox2}
 | 
|  |   1596 | \end{frame}
 | 
|  |   1597 | 
 | 
|  |   1598 | 
 | 
|  |   1599 | \begin{frame}[c]
 | 
|  |   1600 | \begin{mybox3}{What is the trick?}\small
 | 
|  |   1601 |   What was the trick to improve the evil regular expressions matcher
 | 
|  |   1602 |   to have such good results compared to other programming languages?
 | 
|  |   1603 |   Is it working better on casual regular expressions (the ones that
 | 
|  |   1604 |   Python and Java handle pretty well), too? Or was it just optimised
 | 
|  |   1605 |   for these evil ones?
 | 
|  |   1606 | \end{mybox3}
 | 
|  |   1607 | \end{frame}
 | 
|  |   1608 | 
 | 
|  |   1609 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1610 | \begin{frame}[c]
 | 
|  |   1611 |   \frametitle{Thanks to Martin Mikusovic}
 | 
|  |   1612 | 
 | 
|  |   1613 | \bigskip    
 | 
|  |   1614 | \begin{center}
 | 
|  |   1615 | \begin{tikzpicture}
 | 
|  |   1616 |   \begin{axis}[
 | 
|  |   1617 |     xlabel={$n$},
 | 
|  |   1618 |     x label style={at={(1.05,0.0)}},
 | 
|  |   1619 |     ylabel={time in secs},
 | 
|  |   1620 |     enlargelimits=false,
 | 
|  |   1621 |     xtick={0,5,...,30},
 | 
|  |   1622 |     xmax=33,
 | 
|  |   1623 |     ymax=35,
 | 
|  |   1624 |     ytick={0,10,...,30},
 | 
|  |   1625 |     scaled ticks=false,
 | 
|  |   1626 |     axis lines=left,
 | 
|  |   1627 |     width=9cm,
 | 
|  |   1628 |     height=5.5cm, 
 | 
|  |   1629 |     legend entries={Java 8, Python, JavaScript, Swift},  
 | 
|  |   1630 |     legend pos=north west,
 | 
|  |   1631 |     legend cell align=left]
 | 
|  |   1632 | \addplot[blue,mark=*, mark options={fill=white}] table {re-python2.data};
 | 
|  |   1633 | \addplot[cyan,mark=*, mark options={fill=white}] table {re-java.data};
 | 
|  |   1634 | \addplot[red,mark=*, mark options={fill=white}] table {re-js.data};
 | 
|  |   1635 | \addplot[magenta,mark=*, mark options={fill=white}] table {re-swift.data};
 | 
|  |   1636 | \end{axis}
 | 
|  |   1637 | \end{tikzpicture}
 | 
|  |   1638 | \end{center}
 | 
|  |   1639 | 
 | 
|  |   1640 | Regex: \bl{$(a^*)^* \cdot b$}
 | 
|  |   1641 | 
 | 
|  |   1642 | Strings of the form \bl{$\underbrace{\,a\ldots a\,}_{n}$}
 | 
|  |   1643 | 
 | 
|  |   1644 | \end{frame}
 | 
|  |   1645 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1646 | 
 | 
|  |   1647 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1648 | \begin{frame}[c]
 | 
|  |   1649 | \frametitle{Same Example in Java 9+}
 | 
|  |   1650 | 
 | 
|  |   1651 | \begin{center}
 | 
|  |   1652 | \begin{tikzpicture}
 | 
|  |   1653 |   \begin{axis}[
 | 
|  |   1654 |     xlabel={$n$},
 | 
|  |   1655 |     x label style={at={(1.09,-0.15)}},
 | 
|  |   1656 |     ylabel={time in secs},
 | 
|  |   1657 |     scaled x ticks=false,
 | 
|  |   1658 |     enlargelimits=false,
 | 
|  |   1659 |     xtick distance=10000,
 | 
|  |   1660 |     xmax=44000, 
 | 
|  |   1661 |     ytick={0,10,...,30}, 
 | 
|  |   1662 |     ymax=35, 
 | 
|  |   1663 |     axis lines=left,
 | 
|  |   1664 |     width=9cm,
 | 
|  |   1665 |     height=5cm, 
 | 
|  |   1666 |     legend entries={Java \liningnums{9}+},
 | 
|  |   1667 |     legend pos=north west,
 | 
|  |   1668 |     legend cell align=left]
 | 
|  |   1669 | \addplot[blue,mark=square*,mark options={fill=white}] table {re-java9.data};
 | 
|  |   1670 | \end{axis}
 | 
|  |   1671 | \end{tikzpicture}
 | 
|  |   1672 | \end{center}
 | 
|  |   1673 | 
 | 
|  |   1674 | Regex: \bl{$(a^*)^* \cdot b$}
 | 
|  |   1675 | 
 | 
|  |   1676 | Strings of the form \bl{$\underbrace{\,a\ldots a\,}_{n}$}
 | 
|  |   1677 | 
 | 
|  |   1678 | \end{frame}
 | 
|  |   1679 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1680 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1681 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 | 
|  |   1682 | % Questions
 | 
|  |   1683 | 
 | 
|  |   1684 | 
 | 
|  |   1685 | 
 | 
|  |   1686 | 
 | 
|  |   1687 | \begin{frame}[c]
 | 
|  |   1688 | \end{frame}
 | 
|  |   1689 | 
 | 
|  |   1690 | \begin{frame}[c]
 | 
|  |   1691 | \end{frame}
 | 
|  |   1692 | 
 | 
|  |   1693 | \begin{frame}[c]
 | 
|  |   1694 | \end{frame}
 | 
|  |   1695 | 
 | 
|  |   1696 | \begin{frame}[c]
 | 
|  |   1697 | \end{frame}
 | 
|  |   1698 | 
 | 
| 879 |   1699 | \begin{frame}[c]
 | 
| 876 |   1700 | 
 | 
|  |   1701 | \end{frame}
 | 
|  |   1702 | 
 | 
|  |   1703 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 | 
|  |   1704 | \end{document}
 | 
|  |   1705 | 
 | 
|  |   1706 | %%% Local Variables:  
 | 
|  |   1707 | %%% mode: latex
 | 
|  |   1708 | %%% TeX-master: t
 | 
|  |   1709 | %%% End: 
 | 
|  |   1710 | 
 |