| author | Christian Urban <christian.urban@kcl.ac.uk> | 
| Tue, 15 Sep 2020 23:13:45 +0100 | |
| changeset 756 | cb2918e02806 | 
| parent 754 | 05a51fa5f7bb | 
| child 757 | b0ff6121cb9a | 
| permissions | -rw-r--r-- | 
| 631 | 1 | % !TEX program = xelatex | 
| 743 | 2 | \documentclass[dvipsnames,14pt,t,xelatex,aspectratio=169,xcolor={table}]{beamer}
 | 
| 252 
e8ef8f38ca84
added style files
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
215diff
changeset | 3 | \usepackage{../slides}
 | 
| 
e8ef8f38ca84
added style files
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
215diff
changeset | 4 | \usepackage{../graphics}
 | 
| 215 
828303e8e4af
updated slides
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
98diff
changeset | 5 | \usepackage{../langs}
 | 
| 
828303e8e4af
updated slides
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
98diff
changeset | 6 | \usepackage{../data}
 | 
| 0 | 7 | |
| 754 | 8 | \usepackage{tcolorbox}
 | 
| 9 | \newtcolorbox{mybox}{colback=red!5!white,colframe=red!75!black}
 | |
| 10 | \newtcolorbox{mybox2}[1]{colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries,title=#1}
 | |
| 11 | \newtcolorbox{mybox3}[1]{colback=Cyan!5!white,colframe=Cyan!75!black,fonttitle=\bfseries,title=#1}
 | |
| 12 | ||
| 743 | 13 | |
| 14 | ||
| 252 
e8ef8f38ca84
added style files
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
215diff
changeset | 15 | \hfuzz=220pt | 
| 
e8ef8f38ca84
added style files
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
215diff
changeset | 16 | |
| 254 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 17 | \lstset{language=Scala,
 | 
| 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 18 | style=mystyle, | 
| 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 19 | numbersep=0pt, | 
| 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 20 | numbers=none, | 
| 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 21 | xleftmargin=0mm} | 
| 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 22 | |
| 253 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 23 | \newcommand{\bl}[1]{\textcolor{blue}{#1}}     
 | 
| 559 | 24 | |
| 0 | 25 | % beamer stuff | 
| 428 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 26 | \renewcommand{\slidecaption}{CFL 01, King's College London}
 | 
| 0 | 27 | |
| 721 
e712943cff71
added slides from Rochester
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
637diff
changeset | 28 | %% https://cs.rit.edu/~hh/teaching/_media/cc18/lectures/lect1/main.pdf | 
| 
e712943cff71
added slides from Rochester
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
637diff
changeset | 29 | %% https://cs.rit.edu/~hh/teaching/_media/cc18/lectures/lect2/main.pdf | 
| 
e712943cff71
added slides from Rochester
 Christian Urban <christian.urban@kcl.ac.uk> parents: 
637diff
changeset | 30 | %% https://cs.rit.edu/~hh/teaching/_media/cc18/lectures/lect3/main.pdf | 
| 0 | 31 | |
| 32 | \begin{document}
 | |
| 33 | ||
| 754 | 34 | \begin{frame}[t]
 | 
| 35 | \begin{mybox}
 | |
| 36 | A physical explanation the \emph{dynamic matrix}\\
 | |
| 37 | lots of text | |
| 38 | \end{mybox}
 | |
| 743 | 39 | |
| 40 | ||
| 754 | 41 | \begin{mybox2}{Test}
 | 
| 42 | A physical explanation the \emph{dynamic matrix}\\
 | |
| 43 | lots of text | |
| 44 | \end{mybox2}
 | |
| 45 | ||
| 46 | \begin{mybox3}{Test}
 | |
| 47 | A physical explanation the \emph{dynamic matrix}\\
 | |
| 48 | lots of text | |
| 49 | \end{mybox3}
 | |
| 50 | \end{frame}
 | |
| 51 | ||
| 0 | 52 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 253 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 53 | \begin{frame}[t]
 | 
| 510 | 54 | \frametitle{%  
 | 
| 0 | 55 |   \begin{tabular}{@ {}c@ {}}
 | 
| 1 | 56 | \\[-3mm] | 
| 428 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 57 | \LARGE Compilers and \\[-1mm] | 
| 743 | 58 | \LARGE Formal Languages\\[-3mm] | 
| 0 | 59 |   \end{tabular}}
 | 
| 60 | ||
| 61 |   \begin{center}
 | |
| 507 | 62 |   %\includegraphics[scale=0.3]{pics/ante1.jpg}\hspace{5mm}
 | 
| 63 |   %\includegraphics[scale=0.31]{pics/ante2.jpg}\\
 | |
| 64 |   %\footnotesize\textcolor{gray}{Antikythera automaton, 100 BC (Archimedes?)}
 | |
| 0 | 65 |   \end{center}
 | 
| 66 | ||
| 510 | 67 | \normalsize | 
| 0 | 68 |   \begin{center}
 | 
| 69 |   \begin{tabular}{ll}
 | |
| 70 | Email: & christian.urban at kcl.ac.uk\\ | |
| 743 | 71 | %Office Hours: & Thursdays 12 -- 14\\ | 
| 72 | %Location: & N7.07 (North Wing, Bush House)\\ | |
| 631 | 73 | Slides \& Progs: & KEATS\\ | 
| 0 | 74 |   \end{tabular}
 | 
| 75 |   \end{center}
 | |
| 76 | ||
| 743 | 77 |   \begin{center}
 | 
| 78 |     \begin{tikzpicture}
 | |
| 79 | \node[drop shadow,fill=white,inner sep=0pt] | |
| 80 |       {\footnotesize\rowcolors{1}{capri!10}{white}
 | |
| 81 |         \begin{tabular}{|p{4.8cm}|p{4.8cm}|}\hline
 | |
| 82 |           \cellcolor{blue!50}
 | |
| 83 | 1 Introduction, Languages & 6 While-Language \\ | |
| 84 | 2 Regular Expressions, Derivatives & 7 Compilation, JVM \\ | |
| 85 | 3 Automata, Regular Languages & 8 Compiling Functional Languages \\ | |
| 86 | 4 Lexing, Tokenising & 9 Optimisations \\ | |
| 87 | 5 Grammars, Parsing & 10 LLVM \\ \hline | |
| 88 |         \end{tabular}%
 | |
| 89 | }; | |
| 90 |     \end{tikzpicture}
 | |
| 91 |   \end{center}
 | |
| 92 | ||
| 253 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 93 | \end{frame}
 | 
| 559 | 94 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 0 | 95 | |
| 96 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 756 | 97 | \begin{frame}<1-12>[c]
 | 
| 744 | 98 | \frametitle{The Goal of this Module\ldots}
 | 
| 99 | ||
| 100 | \begin{center}
 | |
| 101 |   \begin{tikzpicture}[scale=1,
 | |
| 102 |                       node/.style={
 | |
| 103 | rectangle,rounded corners=3mm, | |
| 104 | very thick,draw=black!50,minimum height=18mm, minimum width=20mm, | |
| 105 | top color=white,bottom color=black!20,drop shadow}] | |
| 106 | ||
| 107 |   \node at (3.05, 1.8) {\Large\bf \ldots{} you write a compiler};
 | |
| 108 | ||
| 109 |   \node (0) at (-2.3,0) {};  
 | |
| 110 | \node [above=5mm of 0] | |
| 111 |   {\makebox[0mm]{\footnotesize
 | |
| 112 |       \begin{tabular}{@{}l@{}}input\\[-1mm]program\end{tabular}}}; 
 | |
| 113 | ||
| 114 |   \node (A) at (0,0)  [node] {};
 | |
| 115 |   \node [below right] at (A.north west) {lexer};
 | |
| 116 | ||
| 117 |   \node (B) at (3,0)  [node] {};
 | |
| 118 |   \node [below right=1mm] at (B.north west) {\mbox{}\hspace{-1mm}parser};
 | |
| 119 | ||
| 120 |   \node (C) at (6,0)  [node] {};
 | |
| 121 |   \node [below right] at (C.north west) {\mbox{}\hspace{-1mm}code gen};
 | |
| 122 | ||
| 123 |   \node (1) at (8.4,0) {};
 | |
| 124 | \node [above=5mm of 1] | |
| 125 |   {\makebox[0mm]{\footnotesize
 | |
| 126 |       \begin{tabular}{@{}r@{}}binary\\[-1mm]code\end{tabular}}};
 | |
| 127 | ||
| 128 | \draw [->,line width=4mm] (0) -- (A); | |
| 129 | \draw [->,line width=4mm] (A) -- (B); | |
| 130 | \draw [->,line width=4mm] (B) -- (C); | |
| 131 | \draw [->,line width=4mm] (C) -- (1); | |
| 132 |   \end{tikzpicture}
 | |
| 133 |   \end{center}
 | |
| 134 | ||
| 135 | \only<2,3,4>{
 | |
| 136 | \begin{textblock}{1}(1,2.1)
 | |
| 137 | \begin{bubble}[9.8cm]
 | |
| 138 | \normalsize | |
| 139 | lexer input: a string\smallskip\\ | |
| 140 | \hspace{5mm}\code{"read(n);"}\medskip\\
 | |
| 141 | lexer output: a sequence of tokens\smallskip\\ | |
| 142 | \hspace{5mm}\code{key(read) lpar id(n) rpar semi}
 | |
| 143 | \end{bubble}
 | |
| 144 | \end{textblock}} 
 | |
| 145 | ||
| 146 | \only<3,4>{
 | |
| 147 | \begin{textblock}{1}(6,7.8)
 | |
| 148 | \begin{tabular}{c}
 | |
| 149 | \includegraphics[scale=0.2]{../pics/rosetta.jpg}\\[-2mm]
 | |
| 150 | \footnotesize lexing $\Rightarrow$ recognising words (Stone of Rosetta) | |
| 151 | \end{tabular}
 | |
| 152 | \end{textblock}}
 | |
| 153 | ||
| 154 | \only<4>{
 | |
| 155 | \begin{textblock}{1}(0.5,12)\small
 | |
| 156 | \begin{tabular}{l@{}c@{}l}
 | |
| 157 |   \pcode{if}    & $\;\Rightarrow\;$ & keyword\\
 | |
| 158 |   \pcode{iffoo} & $\;\Rightarrow\;$ & identifier\\
 | |
| 159 | \end{tabular}  
 | |
| 160 | \end{textblock}}
 | |
| 161 | ||
| 162 | \only<6>{
 | |
| 163 | \begin{textblock}{1}(1,1.5)
 | |
| 164 | \begin{bubble}[8.5cm]
 | |
| 165 | \normalsize | |
| 166 | parser input: a sequence of tokens\smallskip\\ | |
| 167 | ||
| 168 | {\small\hspace{5mm}\code{key(read) lpar id(n) rpar semi}}\smallskip\\
 | |
| 169 | ||
| 170 | parser output: an abstract syntax tree\smallskip\\ | |
| 171 | \footnotesize | |
| 172 | \hspace{2cm}\begin{tikzpicture}
 | |
| 173 |   \node {\code{read}}
 | |
| 174 |     child {node {\code{lpar}}}
 | |
| 175 |     child {node {\code{n}}}
 | |
| 176 |     child {node {\code{rpar}}};
 | |
| 177 | \end{tikzpicture}
 | |
| 178 | \end{bubble}
 | |
| 179 | \end{textblock}}
 | |
| 180 | ||
| 181 | \only<8,9>{
 | |
| 182 | \begin{textblock}{1}(1,1.5)
 | |
| 183 | \begin{bubble}[4cm]
 | |
| 184 | \normalsize | |
| 185 | code generation:\smallskip\\ | |
| 186 | \hspace{5mm}\code{istore 2}\\ 
 | |
| 187 | \hspace{5mm}\code{iload 2}\\ 
 | |
| 188 | \hspace{5mm}\code{ldc 10}\\
 | |
| 189 | \hspace{5mm}\code{isub}\\
 | |
| 190 | \hspace{5mm}\code{ifeq Label2}\\ 
 | |
| 191 | \hspace{5mm}\code{iload 2}\\
 | |
| 192 | \hspace{5mm}\code{...}\\
 | |
| 193 | \end{bubble}
 | |
| 194 | \end{textblock}}
 | |
| 195 | ||
| 196 | \only<9>{
 | |
| 197 | \begin{textblock}{6}(8.4,7)
 | |
| 198 | \begin{bubble}[5cm]
 | |
| 199 | \mbox{\begin{tikzpicture}[scale=0.58,rounded corners=0mm]
 | |
| 200 | \begin{axis}[axis x line=bottom, axis y line=left, ylabel=secs,
 | |
| 201 | xlabel=n, | |
| 202 | enlargelimits=0.05, | |
| 203 | ybar interval=0.7, legend style=small] | |
| 204 | \addplot file {interpreted2.data};
 | |
| 205 | \addplot file {compiled2.data};
 | |
| 206 | %\legend{interpreted, compiled}
 | |
| 207 | \end{axis}
 | |
| 208 | \end{tikzpicture}}
 | |
| 209 | \end{bubble}
 | |
| 210 | \end{textblock}}
 | |
| 211 | ||
| 212 | \only<10>{
 | |
| 213 | \begin{textblock}{6}(1,3)
 | |
| 214 |   \begin{bubble}[11cm]
 | |
| 756 | 215 |     Compiler explorers, e.g.: \url{https://gcc.godbolt.org} \;\video{https://youtu.be/ysaBmhMEyUg}
 | 
| 744 | 216 |   \begin{tikzpicture}[]
 | 
| 217 |   \node (0) at (-2.3,0) {\includegraphics[scale=0.3]{pics/csource.png}};
 | |
| 218 |   \node (1) [right=35mm] at (0) {\includegraphics[scale=0.3]{pics/cassmbl.png}}; 
 | |
| 219 | \draw [->,line width=4mm, red] (0) -- (1); | |
| 756 | 220 |   \node (2) [below=20mm] at (0) {\LARGE\bf source};
 | 
| 221 |   \node (3) [right=40mm] at (2) {\LARGE\bf binary};
 | |
| 222 | \draw [->,line width=1mm] (2) -- (3); | |
| 223 | \end{tikzpicture}
 | |
| 224 | \end{bubble}
 | |
| 225 | ||
| 226 | \end{textblock}}
 | |
| 227 | \only<11>{
 | |
| 228 | \begin{textblock}{6}(1,3)
 | |
| 229 |   \begin{bubble}[11cm]
 | |
| 230 |     Compiler explorer for Java: \url{https://javap.yawk.at} 
 | |
| 231 |   \begin{tikzpicture}[]
 | |
| 232 |   \node (0) at (-2.3,0) {\includegraphics[scale=0.4]{pics/jsource.png}};
 | |
| 233 |   \node (1) [right=35mm] at (0) {\includegraphics[scale=0.4]{pics/jassmbl.png}}; 
 | |
| 234 | \draw [->,line width=4mm, red] (0) -- (1); | |
| 235 |   \node (2) [below=20mm] at (0) {\LARGE\bf source};
 | |
| 236 |   \node (3) [right=40mm] at (2) {\LARGE\bf byte code};
 | |
| 744 | 237 | \draw [->,line width=1mm] (2) -- (3); | 
| 238 | \end{tikzpicture}
 | |
| 239 | \end{bubble}
 | |
| 240 | \end{textblock}}
 | |
| 241 | ||
| 242 | ||
| 243 | \end{frame}
 | |
| 244 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 245 | ||
| 246 | ||
| 247 | ||
| 248 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 559 | 249 | \begin{frame}[t]
 | 
| 250 | \frametitle{Why Study Compilers?}
 | |
| 0 | 251 | |
| 743 | 252 | |
| 253 | John Regehr {\small(Univ.~Utah, LLVM compiler hacker)}
 | |
| 254 | \here{https://blog.regehr.org/archives/1419}
 | |
| 255 | \smallskip\\ | |
| 255 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 256 | |
| 559 | 257 | \begin{bubble}[10.5cm]
 | 
| 258 |   \bf ``\ldots{}It’s effectively a perpetual
 | |
| 259 | employment act for solid compiler hackers.'' | |
| 260 | \end{bubble}
 | |
| 0 | 261 | |
| 559 | 262 | \onslide<1->{
 | 
| 263 | \only<2>{
 | |
| 264 | \begin{itemize}
 | |
| 265 | \item {\bf Hardware is getting weirder
 | |
| 631 | 266 | rather than getting clocked faster.} | 
| 0 | 267 | |
| 559 | 268 | \begin{itemize}
 | 
| 631 | 269 | \item[] ``Almost all processors are multicores nowadays and it looks | 
| 270 | like there is increasing asymmetry in resources across cores. | |
| 271 | Processors come with vector units, crypto accelerators etc. We have | |
| 272 | DSPs, GPUs, ARM big.little, and Xeon Phi. This is only scratching the | |
| 273 | surface.'' | |
| 559 | 274 | \end{itemize}  
 | 
| 275 | \end{itemize}}
 | |
| 255 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 276 | \only<3>{
 | 
| 559 | 277 | \begin{itemize}
 | 
| 278 | \item {\bf We’re getting tired of low-level languages and
 | |
| 631 | 279 | their associated security disasters.} | 
| 559 | 280 | |
| 281 | \begin{itemize}
 | |
| 631 | 282 | \item [] ``We want to write new code, to whatever extent possible, in | 
| 283 | safer, higher-level languages. Compilers are caught right in the | |
| 284 | middle of these opposing trends: one of their main jobs is to help | |
| 285 | bridge the large and growing gap between increasingly high-level | |
| 286 | languages and increasingly wacky platforms.'' | |
| 559 | 287 | \end{itemize}  
 | 
| 288 | \end{itemize}}}
 | |
| 1 | 289 | |
| 253 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 290 | \end{frame}
 | 
| 0 | 291 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 1 | 292 | |
| 631 | 293 | |
| 294 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 295 | \begin{frame}[c]
 | |
| 744 | 296 | \frametitle{Why Bother with Compilers?}
 | 
| 631 | 297 | |
| 745 | 298 | \textbf{Boeing 777's}: First flight in 1994. They want to achieve
 | 
| 299 | triple redundancy for potential hardware faults. | |
| 300 | \here{http://www.citemaster.net/get/db3a81c6-548e-11e5-9d2e-00163e009cc7/R8.pdf}\bigskip
 | |
| 631 | 301 | |
| 302 | They compile 1 Ada program to\medskip | |
| 303 | ||
| 304 | \begin{itemize}
 | |
| 305 | \item Intel 80486 | |
| 306 | \item Motorola 68040 (old Macintosh's) | |
| 307 | \item AMD 29050 (RISC chips used often in laser printers) | |
| 308 | \end{itemize}\medskip\medskip
 | |
| 309 | ||
| 310 | using 3 independent compilers.\bigskip\pause | |
| 311 | ||
| 312 | \small Airbus uses C and static analysers. Recently started using CompCert. | |
| 745 | 313 | |
| 314 | \only<1->{%
 | |
| 315 | \begin{textblock}{6}(8,4.5)
 | |
| 316 | \includegraphics[scale=0.28]{../pics/777.png}
 | |
| 317 | \end{textblock}}
 | |
| 318 | ||
| 631 | 319 | \end{frame}
 | 
| 756 | 320 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 321 | ||
| 322 | ||
| 323 | ||
| 324 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 325 | \begin{frame}[c]
 | |
| 326 | \frametitle{What Do Compilers Do?}
 | |
| 327 | ||
| 328 | Remember BF*** from PEP? | |
| 329 | ||
| 330 | \begin{center}
 | |
| 331 | \begin{tabular}{rcl}
 | |
| 332 | \bl{\texttt{>}} & $\Rightarrow$ & move one cell right\\
 | |
| 333 | \bl{\texttt{<}} & $\Rightarrow$ & move one cell left\\
 | |
| 334 | \bl{\texttt{+}} & $\Rightarrow$ & increase cell by one\\
 | |
| 335 | \bl{\texttt{-}} & $\Rightarrow$ & decrease cell by one\\
 | |
| 336 | \bl{\texttt{.}} & $\Rightarrow$ & print current cell\\
 | |
| 337 | \bl{\texttt{,}} & $\Rightarrow$ & input current cell\\
 | |
| 338 | \bl{\texttt{[}} & $\Rightarrow$ & loop begin\\
 | |
| 339 | \bl{\texttt{]}} & $\Rightarrow$ & loop end\medskip\\
 | |
| 340 | & $\Rightarrow$ & everything else is a comment\\ | |
| 341 | \end{tabular}  
 | |
| 342 | \end{center}  
 | |
| 343 | ||
| 344 | \end{frame}
 | |
| 345 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 346 | ||
| 347 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 348 | \begin{frame}[c]
 | |
| 349 |   \frametitle{A ``Compiler'' for BF*** to C}
 | |
| 350 | ||
| 351 |   \begin{center}
 | |
| 352 |   \begin{tabular}{rcl}
 | |
| 353 |   \bl{\texttt{>}} & $\Rightarrow$ & \texttt{ptr++}\\
 | |
| 354 |   \bl{\texttt{<}} & $\Rightarrow$ & \texttt{ptr--}\\
 | |
| 355 |   \bl{\texttt{+}} & $\Rightarrow$ & \texttt{(*ptr)++}\\
 | |
| 356 |   \bl{\texttt{-}} & $\Rightarrow$ & \texttt{(*ptr)--}\\
 | |
| 357 |   \bl{\texttt{.}} & $\Rightarrow$ & \texttt{putchar(*ptr)}\\
 | |
| 358 |   \bl{\texttt{,}} & $\Rightarrow$ & \texttt{*ptr = getchar()}\\
 | |
| 359 |   \bl{\texttt{[}} & $\Rightarrow$ & \texttt{while(*ptr)\{}\\
 | |
| 360 |   \bl{\texttt{]}} & $\Rightarrow$ & \texttt{\}}\medskip\\
 | |
| 361 | & $\Rightarrow$ & ignore everything else\\ | |
| 362 |   \end{tabular}  
 | |
| 363 |   \end{center}\bigskip  
 | |
| 364 | ||
| 365 |   \texttt{char field[30000]\\ char *ptr = \&field[15000]}
 | |
| 366 | ||
| 367 | \end{frame}
 | |
| 368 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 369 | ||
| 370 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 371 | \begin{frame}[c]
 | |
| 372 |   \frametitle{A ``Compiler'' for BF*** to C}
 | |
| 373 | ||
| 374 |   \begin{center}
 | |
| 375 |   \begin{tabular}{rcl}
 | |
| 376 |   \bl{\texttt{>\ldots>}} & $\Rightarrow$ & \texttt{ptr += n}\\
 | |
| 377 |   \bl{\texttt{<\ldots<}} & $\Rightarrow$ & \texttt{ptr -= n}\\
 | |
| 378 |   \bl{\texttt{+\ldots+}} & $\Rightarrow$ & \texttt{(*ptr) += n}\\
 | |
| 379 |   \bl{\texttt{-\ldots-}} & $\Rightarrow$ & \texttt{(*ptr) -= n}\\
 | |
| 380 |   \bl{\texttt{.}} & $\Rightarrow$ & \texttt{putchar(*ptr)}\\
 | |
| 381 |   \bl{\texttt{,}} & $\Rightarrow$ & \texttt{*ptr = getchar()}\\
 | |
| 382 |   \bl{\texttt{[}} & $\Rightarrow$ & \texttt{while(*ptr)\{}\\
 | |
| 383 |   \bl{\texttt{]}} & $\Rightarrow$ & \texttt{\}}\medskip\\
 | |
| 384 | & $\Rightarrow$ & ignore everything else\\ | |
| 385 |   \end{tabular}  
 | |
| 386 |   \end{center}\bigskip  
 | |
| 387 | ||
| 388 |   \texttt{char field[30000]\\ char *ptr = \&field[15000]}
 | |
| 389 | ||
| 390 | \end{frame}
 | |
| 391 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 392 | ||
| 393 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 394 | \begin{frame}[c]
 | |
| 395 |   \frametitle{Recap}
 | |
| 396 | ||
| 397 |   \begin{itemize}
 | |
| 398 |   \item interpreter \bl{\texttt{bfi.sc}} \\$\Rightarrow$ 11 mins\pause
 | |
| 399 |   \item simple compiler \bl{\texttt{bfi0.sc}}, no optimisations  \\$\Rightarrow$ 20 secs\pause
 | |
| 400 |   \item ``advanced'' compiler \bl{\texttt{bfi1.sc}}, no optimisations  \\$\Rightarrow$ 5 secs\bigskip\pause
 | |
| 401 | ||
| 402 |   \item simple compiler \bl{\texttt{bfi0.sc}},
 | |
| 403 |     \alert{\textbf{full optimisations}}  \\$\Rightarrow$ 7 secs  
 | |
| 404 |   \end{itemize}\bigskip\pause
 | |
| 405 | ||
| 406 |   \hspace{4cm}all programs on KEATS
 | |
| 407 | ||
| 408 | \end{frame}
 | |
| 409 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 410 | ||
| 411 | ||
| 412 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 413 | \begin{frame}[t]
 | |
| 414 | \frametitle{A Brief Compiler History}
 | |
| 415 | ||
| 416 | \bigskip | |
| 417 | \begin{itemize}
 | |
| 418 | \item Turing Machines, 1936 (a tape as memory) | |
| 419 | \item Regular Expressions, 1956\\ | |
| 420 | \item The first compiler for COBOL, 1957\\ (Grace Hopper)\medskip | |
| 421 | \item But surprisingly research papers are still published nowadays\\ | |
| 422 | \item ``Parsing: The Solved Problem That Isn't'' | |
| 423 |   \here{https://tratt.net/laurie/blog/entries/parsing_the_solved_problem_that_isnt.html}
 | |
| 424 | \end{itemize}
 | |
| 425 | ||
| 426 | ||
| 427 | \begin{textblock}{8.5}(5,7.6)
 | |
| 428 | \begin{flushright}
 | |
| 429 | \includegraphics[scale=0.3]{pics/hopper.jpg}\\
 | |
| 430 | \footnotesize\textcolor{gray}{Grace Hopper}\smallskip\\
 | |
| 431 | ||
| 432 | {\small\textcolor{gray}{(she made it to David Letterman's Tonight Show
 | |
| 433 |  \here{https://youtu.be/3N_ywhx6_K0?t=31})}}
 | |
| 434 | \end{flushright}
 | |
| 435 | \end{textblock}
 | |
| 436 | ||
| 437 | \end{frame}
 | |
| 438 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 439 | ||
| 440 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 441 | \begin{frame}[c]
 | |
| 442 | \frametitle{Lectures 1 - 5}
 | |
| 443 | ||
| 444 | transforming strings into structured data\\[10mm] | |
| 445 | ||
| 446 | {\LARGE\bf Lexing} {\hfill{}based on regular expressions}\medskip\\
 | |
| 447 | \hspace{5mm}(recognising ``words'')\\[6mm]
 | |
| 448 | ||
| 449 | {\LARGE\bf Parsing}\medskip\\
 | |
| 450 | \hspace{5mm}(recognising ``sentences'')
 | |
| 451 | ||
| 452 | \begin{textblock}{1}(10,9.1)
 | |
| 453 | \begin{tabular}{c}
 | |
| 454 | \includegraphics[scale=0.1]{../pics/rosetta.jpg}\\[-2mm]
 | |
| 455 | \footnotesize Stone of Rosetta | |
| 456 | \end{tabular}
 | |
| 457 | \end{textblock}
 | |
| 458 | ||
| 459 | \end{frame}
 | |
| 460 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 461 | ||
| 462 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 463 | \begin{frame}[c]
 | |
| 464 |   \frametitle{Lectures 5 - 10}
 | |
| 465 | ||
| 466 | code generation for a small imperative and a small functional language\\[10mm] | |
| 467 | ||
| 468 |   {\LARGE\bf Interpreters}\medskip\\
 | |
| 469 |   \hspace{5mm}(directly runs a program)\\[6mm]
 | |
| 470 | ||
| 471 |   {\LARGE\bf Compilers}\medskip\\
 | |
| 472 |   \hspace{5mm}(generate JVM code and LLVM-IR code)
 | |
| 473 | ||
| 474 |   \begin{textblock}{1}(8.8,8.1)
 | |
| 475 |   \begin{tabular}{c@{}c}
 | |
| 476 |     \includegraphics[scale=0.4]{../pics/javaduke.png} &
 | |
| 477 |     \includegraphics[scale=0.23]{../pics/llvmlogo.png}
 | |
| 478 |   \end{tabular}
 | |
| 479 |   \end{textblock}
 | |
| 480 | ||
| 481 |   \end{frame}
 | |
| 482 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 483 | ||
| 484 | ||
| 485 | ||
| 486 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 487 | \begin{frame}[t]
 | |
| 488 | \frametitle{Familiar Regular Expr.}
 | |
| 489 | \small | |
| 490 | \begin{center}
 | |
| 491 | \texttt{[a-z0-9\_$\backslash{}$.-]+ @ [a-z0-9$\backslash{}$.-]+ . [a-z$\backslash{}$.]\{2,6\}}
 | |
| 492 | \end{center}\smallskip
 | |
| 493 | ||
| 494 | \begin{center}
 | |
| 495 | \begin{tabular}{@{}lp{8.5cm}@{}}
 | |
| 496 | \pcode{re*} & matches 0 or more times\\
 | |
| 497 | \pcode{re+} & matches 1 or more times\\
 | |
| 498 | \pcode{re?} & matches 0 or 1 times\\
 | |
| 499 | \pcode{re\{n\}}	& matches exactly \pcode{n} number of times\\
 | |
| 500 | \pcode{re\{n,m\}} & matches at least \pcode{n} and at most {\tt m} times\\
 | |
| 501 | \pcode{[...]} & matches any single character inside the brackets\\
 | |
| 502 | \pcode{[^...]} & matches any single character not inside the 
 | |
| 503 | brackets\\ | |
| 504 | \pcode{a-z A-Z} & character ranges\\
 | |
| 505 | \pcode{\\d} & matches digits; equivalent to \pcode{[0-9]}\\
 | |
| 506 | \pcode{.} & matches every character except newline\\
 | |
| 507 | \pcode{(re)}	& groups regular expressions and remembers 
 | |
| 508 | the matched text | |
| 509 | \end{tabular}
 | |
| 510 | \end{center}
 | |
| 511 | ||
| 512 | ||
| 513 | \end{frame}
 | |
| 514 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 515 | ||
| 631 | 516 | |
| 517 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 255 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 518 | \begin{frame}[c]
 | 
| 745 | 519 | \frametitle{Why Bother with Regexes?}
 | 
| 255 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 520 | |
| 745 | 521 | \begin{columns}[t,onlytextwidth]
 | 
| 522 | \begin{column}{1.8cm}
 | |
| 523 | \mbox{}   
 | |
| 524 | \end{column}    
 | |
| 525 | \begin{column}{.5\textwidth}
 | |
| 526 | \small{}Ruby, Python, Java 8\medskip\\
 | |
| 428 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 527 | \begin{tikzpicture}\footnotesize
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 528 | \begin{axis}[
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 529 |     xlabel={$n$},
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 530 |     x label style={at={(1.05,0.0)}},
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 531 |     ylabel={time in secs},
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 532 | enlargelimits=false, | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 533 |     xtick={0,5,...,30},
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 534 | xmax=33, | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 535 | ymax=35, | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 536 |     ytick={0,5,...,30},
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 537 | scaled ticks=false, | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 538 | axis lines=left, | 
| 745 | 539 | width=\textwidth, | 
| 428 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 540 | height=4cm, | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 541 |     legend entries={Python,Ruby},  
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 542 | legend pos=north west, | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 543 | legend cell align=left] | 
| 559 | 544 | \addplot[blue,mark=*, mark options={fill=white}] table {re-python.data};
 | 
| 545 | \addplot[brown,mark=triangle*, mark options={fill=white}] table {re-ruby.data};
 | |
| 428 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 546 | \end{axis}
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 547 | \end{tikzpicture}
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 548 | \begin{tikzpicture}\footnotesize
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 549 | \begin{axis}[
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 550 |     xlabel={$n$},
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 551 |     x label style={at={(1.05,0.0)}},
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 552 |     ylabel={time in secs},
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 553 | enlargelimits=false, | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 554 |     xtick={0,5,...,30},
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 555 | xmax=33, | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 556 | ymax=35, | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 557 |     ytick={0,5,...,30},
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 558 | scaled ticks=false, | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 559 | axis lines=left, | 
| 745 | 560 | width=\textwidth, | 
| 428 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 561 | height=4cm, | 
| 631 | 562 |     legend entries={Python, Java 8, JavaScript},  
 | 
| 428 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 563 | legend pos=north west, | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 564 | legend cell align=left] | 
| 559 | 565 | \addplot[blue,mark=*, mark options={fill=white}] table {re-python2.data};   
 | 
| 428 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 566 | \addplot[cyan,mark=*, mark options={fill=white}] table {re-java.data};
 | 
| 631 | 567 | \addplot[red,mark=*, mark options={fill=white}] table {re-js.data};
 | 
| 428 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 568 | \end{axis}
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 569 | \end{tikzpicture}
 | 
| 745 | 570 | % | 
| 428 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 571 | \end{column}
 | 
| 745 | 572 | \begin{column}{.5\textwidth}
 | 
| 573 | \small{}Us (after next lecture)\medskip\\
 | |
| 428 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 574 | \begin{tikzpicture}\footnotesize
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 575 | \begin{axis}[
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 576 |     xlabel={$n$},
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 577 |     x label style={at={(1.07,0.0)}},
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 578 |     ylabel={time in secs},
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 579 | enlargelimits=false, | 
| 442 
84d6714840c9
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
437diff
changeset | 580 |     xtick={0,5000,...,10000},
 | 
| 
84d6714840c9
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
437diff
changeset | 581 | xmax=11000, | 
| 428 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 582 | ymax=35, | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 583 |     ytick={0,5,...,30},
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 584 | scaled ticks=false, | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 585 | axis lines=left, | 
| 745 | 586 | width=\textwidth, | 
| 428 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 587 | height=4cm] | 
| 437 
fe387fcbf2ee
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
428diff
changeset | 588 | \addplot[green,mark=square*,mark options={fill=white}] table {re2.data};
 | 
| 428 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 589 | \addplot[black,mark=square*,mark options={fill=white}] table {re3.data};
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 590 | \end{axis}
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 591 | \end{tikzpicture}
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 592 | \begin{tikzpicture}\footnotesize
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 593 | \begin{axis}[
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 594 |     xlabel={$n$},
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 595 |     x label style={at={(1.07,0.0)}},
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 596 |     ylabel={time in secs},
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 597 | enlargelimits=false, | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 598 | ymax=35, | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 599 |     ytick={0,5,...,30},
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 600 | scaled ticks=false, | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 601 | axis lines=left, | 
| 745 | 602 | width=\textwidth, | 
| 428 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 603 | height=4cm] | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 604 | \addplot[black,mark=square*,mark options={fill=white}] table {re3a.data};
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 605 | \end{axis}
 | 
| 255 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 606 | \end{tikzpicture}
 | 
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 607 | \end{column}
 | 
| 745 | 608 | \end{columns}
 | 
| 609 | \medskip | |
| 610 | ||
| 611 | \begin{textblock}{3}(-0.1,3.3)
 | |
| 612 | \small\hfill\bl{\texttt{[a?]\{n\}[a]\{n\}}}:
 | |
| 613 | \end{textblock}
 | |
| 255 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 614 | |
| 745 | 615 | \begin{textblock}{3}(-0.1,8.7)  
 | 
| 616 | \small\hfill\bl{\texttt{(a*)*b}}:
 | |
| 617 | \end{textblock}
 | |
| 618 | ||
| 619 | \begin{textblock}{3}(0.3,13)
 | |
| 620 | \small{}matching with strings
 | |
| 621 | \bl{$\underbrace{\texttt{a}...\texttt{a}}_n$}  
 | |
| 622 | \end{textblock}
 | |
| 623 | ||
| 510 | 624 | \end{frame} 
 | 
| 255 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 625 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 631 | 626 | |
| 627 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 628 | \begin{frame}[c,fragile]
 | |
| 629 |   \frametitle{Incidents}
 | |
| 630 | ||
| 631 |   \begin{itemize}
 | |
| 632 |   \item a global outage on 2 July 2019 at \textbf{Cloudflare} 
 | |
| 633 | (first one for six years)\medskip | |
| 634 | ||
| 635 |   \begin{center}\small\color{blue}
 | |
| 636 |   \begin{verbatim}  
 | |
| 637 | (?:(?:\"|'|\]|\}|\\|\d|(?:nan|infinity|true|false| | |
| 638 | null|undefined|symbol|math)|\`|\-|\+)+[)]*;?((?:\s | |
| 639 |   |-|~|!|{}|\|\||\+)*.*(?:.*=.*)))  
 | |
| 640 |   \end{verbatim}
 | |
| 641 |   \end{center}\bigskip\bigskip\bigskip\bigskip\bigskip\bigskip\bigskip    
 | |
| 642 | ||
| 643 |   \item on 20 July 2016 the \textbf{Stack Exchange} webpage went down
 | |
| 745 | 644 | because of an evil regular expression | 
| 645 |     \here{https://stackstatus.net/post/147710624694/outage-postmortem-july-20-2016}    
 | |
| 631 | 646 |   \end{itemize}
 | 
| 647 | ||
| 745 | 648 |   \begin{textblock}{6}(6,7.6)
 | 
| 728 | 649 |     \includegraphics[scale=0.14]{../pics/cloudflare.png}\\
 | 
| 631 | 650 | \footnotesize | 
| 745 | 651 | It serves more web traffic than Twitter, Amazon, Apple, | 
| 652 | Instagram, Bing \& Wikipedia combined. | |
| 653 |     \here{https://blog.cloudflare.com/details-of-the-cloudflare-outage-on-july-2-2019/}
 | |
| 631 | 654 |     \end{textblock}
 | 
| 655 | ||
| 656 |   \end{frame}
 | |
| 657 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 658 | ||
| 560 | 659 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 660 | \begin{frame}[c]
 | |
| 661 | \frametitle{Evil Regular Expressions}
 | |
| 662 | ||
| 663 | \begin{itemize}
 | |
| 664 | \item \alert{R}egular \alert{e}xpression \alert{D}enial \alert{o}f \alert{S}ervice (ReDoS)\medskip
 | |
| 745 | 665 | \item Some evil regular expressions:\medskip | 
| 560 | 666 | \begin{itemize}
 | 
| 745 | 667 | \item \bl{\texttt{[a?]\{n\}\;[a]\{n\}}}
 | 
| 668 | \item \bl{\texttt{(a*)*\;b}}  
 | |
| 669 | \item \bl{\texttt{([a-z]+)*}} 
 | |
| 670 | \item \bl{\texttt{(a + aa)*}}
 | |
| 671 | \item \bl{\texttt{(a + a?)*}}
 | |
| 560 | 672 | \end{itemize}
 | 
| 673 | ||
| 674 | \item sometimes also called \alert{catastrophic backtracking}
 | |
| 675 | \item this is a problem for \alert{N}etwork \alert{I}ntrusion
 | |
| 631 | 676 |   \alert{D}etection systems, Cloudflare, StackExchange, Atom editor
 | 
| 560 | 677 | \item \url{https://vimeo.com/112065252}  
 | 
| 678 | \end{itemize}
 | |
| 679 | ||
| 680 | \end{frame}
 | |
| 681 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 428 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 682 | |
| 255 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 683 | |
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 684 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 631 | 685 | %\begin{frame}[c]
 | 
| 686 | %\frametitle{Today}
 | |
| 687 | % | |
| 688 | %\begin{itemize}
 | |
| 689 | %\item While the ultimate goal is to implement a small compiler for the JVM | |
| 690 | % \ldots\bigskip | |
| 691 | %\end{itemize}
 | |
| 692 | % | |
| 693 | %Let's start with: | |
| 694 | % | |
| 695 | %\begin{itemize}
 | |
| 696 | %\item a web-crawler | |
| 697 | %\item an email harvester | |
| 559 | 698 | %\item \textcolor{gray}{(a web-scraper)}
 | 
| 631 | 699 | %\end{itemize}
 | 
| 700 | % | |
| 701 | %\end{frame}
 | |
| 255 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 702 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 0 | 703 | |
| 2 | 704 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 631 | 705 | %\begin{frame}[t]
 | 
| 706 | %\frametitle{A Web-Crawler}
 | |
| 707 | % | |
| 708 | %\mbox{}\\[10mm]
 | |
| 709 | % | |
| 710 | %\begin{enumerate}
 | |
| 711 | %\item given an URL, read the corresponding webpage | |
| 712 | %\item extract all links from it | |
| 713 | %\item call the web-crawler again for all these links | |
| 714 | %\end{enumerate}
 | |
| 715 | % | |
| 716 | %\end{frame}
 | |
| 2 | 717 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 718 | ||
| 719 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 631 | 720 | %\begin{frame}[t]
 | 
| 721 | %\frametitle{A Web-Crawler}
 | |
| 722 | % | |
| 723 | %\mbox{}\\[10mm]
 | |
| 724 | % | |
| 725 | % | |
| 726 | %\begin{enumerate}
 | |
| 727 | %\item given an URL, read the corresponding webpage | |
| 728 | %\item if not possible print, out a problem | |
| 729 | %\item if possible, extract all links from it | |
| 730 | %\item call the web-crawler again for all these links | |
| 731 | %\end{enumerate}\bigskip\pause
 | |
| 732 | % | |
| 733 | %\small (we need a bound for the number of recursive calls) | |
| 734 | % | |
| 735 | %\small (the purpose is to check all links on my own webpage) | |
| 736 | %\end{frame}
 | |
| 2 | 737 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 738 | ||
| 255 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 739 | |
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 740 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 631 | 741 | %\begin{frame}[c]
 | 
| 742 | % | |
| 743 | %\begin{textblock}{1}(2,5)
 | |
| 744 | %\begin{tabular}{c}
 | |
| 745 | %\includegraphics[scale=0.15]{pics/servers.png}\\[-2mm]
 | |
| 746 | %\small Server | |
| 747 | %\end{tabular}
 | |
| 748 | %\end{textblock}
 | |
| 749 | % | |
| 750 | %\begin{textblock}{1}(5.6,4)
 | |
| 751 | %  \begin{tikzpicture}[scale=1.1]
 | |
| 752 | %  \draw[white] (0,1) node (X) {};
 | |
| 753 | %  \draw[white] (2,1) node (Y) {};
 | |
| 754 | %   \draw[white] (0,0) node (X1) {};
 | |
| 755 | %  \draw[white] (2,0) node (Y1) {};
 | |
| 756 | %   \draw[white] (0,-1) node (X2) {};
 | |
| 757 | %  \draw[white] (2,-1) node (Y2) {};
 | |
| 758 | % \draw[red, <-, line width = 2mm] (X) -- (Y); | |
| 759 | %  \node [inner sep=5pt,label=above:\textcolor{black}{GET request}] at ($ (X)!.5!(Y) $) {};
 | |
| 760 | % \draw[red, ->, line width = 2mm] (X1) -- (Y1); | |
| 761 | %  \node [inner sep=5pt,label=above:\textcolor{black}{webpage}] at ($ (X1)!.5!(Y1) $) {};
 | |
| 762 | % \draw[red, <-, line width = 2mm] (X2) -- (Y2); | |
| 763 | %  \node [inner sep=7pt,label=above:\textcolor{black}{POST data}] at ($ (X2)!.5!(Y2) $) {};
 | |
| 764 | %  \end{tikzpicture}
 | |
| 765 | %\end{textblock}
 | |
| 766 | % | |
| 767 | % | |
| 768 | %\begin{textblock}{1}(9,5.5)
 | |
| 769 | %\begin{tabular}{c}
 | |
| 770 | %\includegraphics[scale=0.15]{pics/laptop.png}\\[-2mm]
 | |
| 771 | %\small Browser | |
| 772 | %\end{tabular}
 | |
| 773 | %\end{textblock}
 | |
| 774 | %\end{frame}
 | |
| 775 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 255 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 776 | |
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 777 | |
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 778 | |
| 0 | 779 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 631 | 780 | %\begin{frame}[c]
 | 
| 781 | %\frametitle{Scala}
 | |
| 782 | % | |
| 783 | %\small A simple Scala function for reading webpages: | |
| 784 | %\bigskip | |
| 785 | % | |
| 786 | %\footnotesize | |
| 787 | %\lstinputlisting{../progs/app0.scala}
 | |
| 788 | %\medskip\pause | |
| 789 | % | |
| 790 | %\lstinline{get_page("""https://nms.kcl.ac.uk/christian.urban/""")}
 | |
| 791 | %\bigskip\medskip\pause | |
| 792 | % | |
| 793 | % | |
| 794 | %\small A slightly more complicated version for handling errors: | |
| 795 | %\smallskip | |
| 796 | % | |
| 797 | %\footnotesize | |
| 798 | %\lstinputlisting[xleftmargin=-4mm]{../progs/app1.scala}
 | |
| 799 | % | |
| 800 | % | |
| 801 | %\end{frame}
 | |
| 0 | 802 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 803 | ||
| 98 
1f3d89fe9820
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
97diff
changeset | 804 | |
| 
1f3d89fe9820
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
97diff
changeset | 805 | |
| 
1f3d89fe9820
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
97diff
changeset | 806 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 3 | 807 | \begin{frame}[t]
 | 
| 253 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 808 | \frametitle{A Regular Expression}
 | 
| 3 | 809 | |
| 810 | \begin{itemize}
 | |
| 811 | \item \ldots{} is a pattern or template for specifying strings
 | |
| 812 | \end{itemize}\bigskip
 | |
| 813 | ||
| 814 | \begin{center}  
 | |
| 254 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 815 | \only<1>{\scode{"https?://[^"]*"}}%
 | 
| 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 816 | \only<2>{\scode{""""https?://[^"]*"""".r}}
 | 
| 3 | 817 | \end{center}\bigskip\bigskip
 | 
| 818 | ||
| 254 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 819 | matches for example\smallskip\\ | 
| 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 820 | \hspace{2mm}\code{"http://www.foobar.com"}\\
 | 
| 559 | 821 | \hspace{2mm}\code{"https://www.tls.org"}\smallskip\\
 | 
| 822 | ||
| 823 | but not\smallskip\\ | |
| 824 | \hspace{2mm}\code{"http://www."foo"bar.com"}\\
 | |
| 3 | 825 | |
| 253 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 826 | \end{frame}
 | 
| 3 | 827 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 828 | ||
| 829 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 632 | 830 | %\begin{frame}[c]
 | 
| 831 | %\frametitle{Finding Operations in Scala}
 | |
| 832 | % | |
| 833 | %{\bf\code{rexp.findAllIn(string)}}\medskip
 | |
| 834 | % | |
| 835 | %returns a list of all (sub)strings that match the | |
| 836 | %regular expression | |
| 837 | %\bigskip\bigskip | |
| 838 | % | |
| 839 | % | |
| 840 | %{\bf\code{rexp.findFirstIn(string)}}\medskip
 | |
| 841 | % | |
| 842 | %returns either | |
| 843 | % | |
| 844 | %\begin{itemize}
 | |
| 845 | %\item \code{None} if no (sub)string matches or 
 | |
| 846 | %\item \code{Some(s)} with the first (sub)string
 | |
| 847 | %\end{itemize}
 | |
| 848 | % | |
| 849 | %\end{frame}
 | |
| 0 | 850 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 851 | ||
| 852 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 631 | 853 | %\begin{frame}[c]
 | 
| 854 | % | |
| 855 | %\footnotesize | |
| 856 | %\lstinputlisting{../progs/app2.scala}
 | |
| 857 | % | |
| 858 | %\end{frame}
 | |
| 254 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 859 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 0 | 860 | |
| 254 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 861 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 631 | 862 | %\begin{frame}[c]
 | 
| 863 | % | |
| 864 | %\small | |
| 865 | %A version that only crawls links in ``my'' domain:\bigskip | |
| 866 | % | |
| 867 | %\footnotesize | |
| 868 | %\lstinputlisting{../progs/app3.scala}
 | |
| 869 | % | |
| 870 | %\end{frame}
 | |
| 0 | 871 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 872 | ||
| 873 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 631 | 874 | %\begin{frame}[c]
 | 
| 875 | %\lstset{xleftmargin=-4mm}
 | |
| 876 | %\small | |
| 877 | %A little email harvester: | |
| 878 | % | |
| 879 | %\footnotesize | |
| 880 | %\lstinputlisting{../progs/app4.scala}\bigskip
 | |
| 881 | % | |
| 882 | %\tiny | |
| 883 | %\url{http://net.tutsplus.com/tutorials/other/8-regular-expressions-you-should-know/}
 | |
| 884 | % | |
| 885 | %\end{frame}
 | |
| 3 | 886 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 887 | ||
| 888 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 14 | 889 | \begin{frame}[t]
 | 
| 506 | 890 | \frametitle{Regular Expressions}
 | 
| 0 | 891 | |
| 330 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 892 | Their inductive definition: | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 893 | |
| 14 | 894 | |
| 330 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 895 | \begin{textblock}{6}(2,7.5)
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 896 |   \begin{tabular}{@ {}rrl@ {\hspace{13mm}}l}
 | 
| 512 | 897 |   \bl{$r$} & \bl{$::=$}  & \bl{$\ZERO$}  & nothing\\
 | 
| 428 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 898 |          & \bl{$\mid$} & \bl{$\ONE$}       & empty string / \pcode{""} / $[]$\\
 | 
| 330 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 899 |          & \bl{$\mid$} & \bl{$c$}                         & character\\
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 900 |          & \bl{$\mid$} & \bl{$r_1 + r_2$}  & alternative / choice\\
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 901 |          & \bl{$\mid$} & \bl{$r_1 \cdot r_2$} & sequence\\
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 902 |          & \bl{$\mid$} & \bl{$r^*$}            & star (zero or more)\\
 | 
| 3 | 903 |   \end{tabular}
 | 
| 904 |   \end{textblock}
 | |
| 905 | ||
| 330 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 906 | |
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 907 | \only<2->{\footnotesize
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 908 | \begin{textblock}{9}(2,0.5)
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 909 | \begin{bubble}[9.8cm]
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 910 | \lstinputlisting{../progs/app01.scala}
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 911 | \end{bubble}
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 912 | \end{textblock}}
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 913 | |
| 254 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 914 | \end{frame}
 | 
| 3 | 915 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 916 | ||
| 917 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 506 | 918 | %\begin{frame}[t]
 | 
| 919 | %\frametitle{Regular Expressions}
 | |
| 920 | % | |
| 921 | %\small | |
| 922 | %In Scala:\bigskip | |
| 923 | % | |
| 924 | %\footnotesize | |
| 925 | %\lstinputlisting{../progs/app51.scala}
 | |
| 926 | % | |
| 927 | % | |
| 928 | %\end{frame}
 | |
| 0 | 929 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 930 | ||
| 931 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 255 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 932 | \begin{frame}[t]
 | 
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 933 | \frametitle{Strings}
 | 
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 934 | |
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 935 | \ldots are lists of characters. For example \code{"hello"}
 | 
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 936 | |
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 937 | \begin{center}
 | 
| 330 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 938 | \bl{$[h, e, l, l, o]$} or just \bl{$hello$}
 | 
| 255 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 939 | \end{center}
 | 
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 940 | |
| 330 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 941 | the empty string: \bl{$[]$} or \bl{\pcode{""}}\bigskip\\
 | 
| 255 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 942 | |
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 943 | the concatenation of two strings: | 
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 944 | |
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 945 | \begin{center}
 | 
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 946 | \bl{$s_1 \,@\, s_2$}
 | 
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 947 | \end{center}
 | 
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 948 | |
| 631 | 949 | \bl{\textit{foo $@$ bar = foobar}}\\
 | 
| 950 | \bl{\textit{baz $@\, []$ = baz}}
 | |
| 255 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 951 | |
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 952 | \end{frame}
 | 
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 953 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 954 | |
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 955 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 330 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 956 | \begin{frame}[c]
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 957 | \frametitle{Languages, Strings}
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 958 | |
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 959 | \begin{itemize}
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 960 | \item \alert{\bf Strings} are lists of characters, for example
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 961 | \begin{center}
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 962 | \bl{$[]$},\;\bl{$abc$}  \hspace{2cm}(Pattern match: \bl{$c\!::\!s$})
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 963 | \end{center}\bigskip
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 964 | |
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 965 | |
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 966 | \item A \alert{\bf language} is a set of strings, for example\medskip
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 967 | \begin{center}
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 968 | \bl{$\{[], hello, \textit{foobar}, a, abc\}$}
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 969 | \end{center}\bigskip
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 970 | |
| 332 
4755ad4b457b
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
331diff
changeset | 971 | \item \alert{\bf Concatenation} of strings and languages
 | 
| 330 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 972 | |
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 973 | \begin{center}
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 974 | \begin{tabular}{rcl}
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 975 | \bl{$\textit{foo}\;@\;bar$} & \bl{$=$} & \bl{$\textit{foobar}$}\medskip\\
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 976 | \bl{$A\;@\;B$} & \bl{$\dn$} & \bl{$\{ s_1\,@\,s_2 \;\mid\; s_1 \in A \wedge s_2 \in B\}$}
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 977 | \end{tabular}
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 978 | \end{center}
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 979 | |
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 980 | %\item The \alert{\bf meaning} of a regular expression is a set of 
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 981 | % strings, or language. | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 982 | \end{itemize}  
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 983 | |
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 984 | \end{frame}
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 985 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 986 | |
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 987 | |
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 988 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 0 | 989 | \begin{frame}[c]
 | 
| 745 | 990 | \frametitle{The Meaning of a Regex}
 | 
| 0 | 991 | |
| 4 | 992 | \begin{textblock}{15}(1,4)
 | 
| 254 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 993 |  \begin{tabular}{rcl}
 | 
| 428 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 994 |  \bl{$L(\ZERO)$}  & \bl{$\dn$} & \bl{$\{\}$}\\
 | 
| 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 995 |  \bl{$L(\ONE)$}     & \bl{$\dn$} & \bl{$\{[]\}$}\\
 | 
| 254 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 996 |  \bl{$L(c)$}            & \bl{$\dn$} & \bl{$\{[c]\}$}\\
 | 
| 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 997 |  \bl{$L(r_1 + r_2)$}    & \bl{$\dn$} & \bl{$L(r_1) \cup L(r_2)$}\\
 | 
| 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 998 |  \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) \}$}\\
 | 
| 428 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 999 |  \bl{$L(r^*)$}           & \bl{$\dn$} & \onslide<4->{\bl{$\bigcup_{0 \le n} L(r)^n$}}\\
 | 
| 4 | 1000 |   \end{tabular}\bigskip
 | 
| 3 | 1001 | |
| 4 | 1002 | \onslide<2->{
 | 
| 254 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 1003 | \hspace{5mm}\bl{$L(r)^0 \;\dn\; \{[]\}$}\\
 | 
| 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 1004 | \bl{$L(r)^{n+1} \;\dn\; L(r) \,@\, L(r)^n$}\hspace{9mm}\onslide<3->{\small\textcolor{gray}{(append on sets)}\\
 | 
| 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 1005 | \small\hspace{5cm}\textcolor{gray}{$\{ s_1 @ s_2 \;|\; s_1\in L(r) \wedge s_2 \in L(r)^n \}$}}
 | 
| 4 | 1006 | } | 
| 1007 |     \end{textblock}
 | |
| 1008 | ||
| 745 | 1009 | \end{frame}
 | 
| 0 | 1010 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 1011 | ||
| 5 | 1012 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 1013 | \begin{frame}[c]
 | |
| 254 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 1014 | \frametitle{The Meaning of Matching}
 | 
| 5 | 1015 | |
| 254 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 1016 | \begin{bubble}[10cm]
 | 
| 559 | 1017 | \large\bf | 
| 507 | 1018 | A regular expression \bl{$r$} matches a string~\bl{$s$} 
 | 
| 254 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 1019 | provided | 
| 5 | 1020 | |
| 1021 | \begin{center}
 | |
| 254 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 1022 | \bl{$s \in L(r)$}\\ 
 | 
| 5 | 1023 | \end{center}
 | 
| 330 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 1024 | \end{bubble}\bigskip\bigskip
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 1025 | |
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 1026 | \ldots and the point of the next lecture is | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 1027 | to decide this problem as fast as possible (unlike Python, | 
| 428 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 1028 | Ruby, Java) | 
| 5 | 1029 | |
| 254 
dcd4688690ce
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
253diff
changeset | 1030 | \end{frame}
 | 
| 5 | 1031 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 1032 | ||
| 631 | 1033 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 1034 | \begin{frame}[c]
 | |
| 1035 |   \frametitle{The Power Operation}
 | |
| 1036 | ||
| 1037 |   \begin{itemize}
 | |
| 1038 |   \item The \alert{\textbf{\boldmath$n$th Power}} of a language:
 | |
| 1039 | ||
| 1040 |   \begin{center}
 | |
| 1041 |   \begin{tabular}{lcl}
 | |
| 1042 |   \bl{$A^0$}    & \bl{$\dn$} & \bl{$\{[]\}$}\\
 | |
| 1043 |   \bl{$A^{n+1}$} & \bl{$\dn$} & \bl{$A \,@\, A^n$}
 | |
| 1044 |   \end{tabular}
 | |
| 1045 |   \end{center}\bigskip
 | |
| 1046 | ||
| 1047 | \item[] For example | |
| 1048 | ||
| 1049 |   \begin{center}
 | |
| 1050 |   \begin{tabular}{lcl@{\hspace{10mm}}l}
 | |
| 1051 |   \bl{$A^4$} & \bl{$=$} & \bl{$A \,@\, A \,@\, A \,@\, A$} & \bl{$(@\,\{[]\})$}\\
 | |
| 1052 |   \bl{$A^1$} & \bl{$=$} & \bl{$A$} & \bl{$(@\,\{[]\})$}\\
 | |
| 1053 |   \bl{$A^0$} & \bl{$=$} & \bl{$\{[]\}$}\\
 | |
| 1054 |   \end{tabular}
 | |
| 1055 |   \end{center}
 | |
| 1056 | ||
| 1057 |   \end{itemize}  
 | |
| 1058 | ||
| 1059 |   \end{frame}
 | |
| 1060 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 1061 | ||
| 1062 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 1063 | \begin{frame}[c]
 | |
| 1064 |   \frametitle{Questions}
 | |
| 1065 | ||
| 1066 |   \begin{itemize}
 | |
| 1067 |   \item Say \bl{$A = \{[a],[b],[c],[d]\}$}.\bigskip
 | |
| 1068 | ||
| 1069 | \item[] | |
| 1070 |   How many strings are in \bl{$A^4$}\,?
 | |
| 1071 | \bigskip\medskip\pause | |
| 1072 | ||
| 1073 | ||
| 1074 | \item[] | |
| 1075 |   What if \bl{$A = \{[a],[b],[c],[]\}$};\\ 
 | |
| 1076 |   how many strings are then in \bl{$A^4$}\,?
 | |
| 1077 |   \end{itemize}  
 | |
| 1078 | ||
| 1079 | \end{frame}
 | |
| 1080 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 1081 | ||
| 1082 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 1083 | \begin{frame}[c]
 | |
| 743 | 1084 | \frametitle{Languages (Sets of Strings)}
 | 
| 1085 | ||
| 1086 | \begin{itemize}
 | |
| 1087 | ||
| 1088 | \item A \alert{\bf Language} is a set of strings, for example\medskip
 | |
| 1089 | \begin{center}
 | |
| 1090 | \bl{$\{[], hello, foobar, a, abc\}$}
 | |
| 1091 | \end{center}\bigskip
 | |
| 1092 | ||
| 1093 | \item \alert{\bf Concatenation} for strings and languages
 | |
| 1094 | ||
| 1095 | \begin{center}
 | |
| 1096 | \begin{tabular}{rcl}
 | |
| 1097 | \bl{$foo\;@\;bar$} & \bl{$=$} & \bl{$foobar$}\medskip\\
 | |
| 1098 | \bl{$A\;@\;B$}     & \bl{$\dn$} & \bl{$\{ s_1\,@\,s_2 \;\mid\; s_1 \in A \wedge s_2 \in B\}$}
 | |
| 1099 | \end{tabular}
 | |
| 1100 | \end{center}
 | |
| 1101 | \bigskip | |
| 1102 | ||
| 1103 | \small | |
| 1104 | \item [] For example \bl{$A = \{foo, bar\}$}, \bl{$B = \{a, b\}$}
 | |
| 1105 | ||
| 1106 | \[ | |
| 1107 | \bl{A \,@\, B = \{fooa, foob, bara, barb\}}
 | |
| 1108 | \] | |
| 1109 | ||
| 1110 | \end{itemize}  
 | |
| 1111 | \end{frame}
 | |
| 1112 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 1113 | ||
| 1114 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 1115 | \begin{frame}[c]
 | |
| 1116 |   \frametitle{Two Corner Cases}
 | |
| 1117 | ||
| 1118 | \Large | |
| 1119 |   \begin{center}
 | |
| 1120 |   \bl{$A \,@\, \{[]\} = \;?$}\bigskip\bigskip\pause\\
 | |
| 1121 |   \bl{$A \,@\, \{\} = \;?$}
 | |
| 1122 |   \end{center}  
 | |
| 1123 | ||
| 1124 |   \end{frame}
 | |
| 1125 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 1126 | ||
| 1127 | ||
| 1128 | ||
| 1129 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 1130 | \begin{frame}[c]
 | |
| 745 | 1131 | \frametitle{The Meaning of a Regex}
 | 
| 743 | 1132 | |
| 1133 | ...all the strings a regular expression can match. | |
| 1134 | ||
| 1135 | \begin{center}
 | |
| 1136 |  \begin{tabular}{rcl}
 | |
| 1137 |  \bl{$L(\ZERO)$}  & \bl{$\dn$} & \bl{$\{\}$}\\
 | |
| 1138 |  \bl{$L(\ONE)$}     & \bl{$\dn$} & \bl{$\{[]\}$}\\
 | |
| 1139 |  \bl{$L(c)$}            & \bl{$\dn$} & \bl{$\{[c]\}$}\\
 | |
| 1140 |  \bl{$L(r_1 + r_2)$}    & \bl{$\dn$} & \bl{$L(r_1) \cup L(r_2)$}\\
 | |
| 1141 |  \bl{$L(r_1 \cdot r_2)$} & \bl{$\dn$} & \bl{$L(r_1) \,@\, L(r_2)$}\\
 | |
| 1142 |  \bl{$L(r^*)$}           & \bl{$\dn$} & \\
 | |
| 1143 |   \end{tabular}
 | |
| 1144 | \end{center}
 | |
| 1145 | ||
| 1146 | \begin{textblock}{14}(1.5,13.5)\small
 | |
| 1147 | \bl{$L$} is a function from regular expressions to 
 | |
| 1148 | sets of strings (languages):\smallskip\\ | |
| 1149 | \bl{\quad$L$ : Rexp $\Rightarrow$ Set$[$String$]$}
 | |
| 1150 | \end{textblock}
 | |
| 1151 | ||
| 1152 | \end{frame}
 | |
| 1153 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 1154 | ||
| 1155 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 1156 | \begin{frame}[c]
 | |
| 1157 | \frametitle{The Power Operation}
 | |
| 1158 | ||
| 1159 | \begin{itemize}
 | |
| 1160 | \item The \alert{\textbf{\boldmath$n$th Power}} of a language:
 | |
| 1161 | ||
| 1162 | \begin{center}
 | |
| 1163 | \begin{tabular}{lcl}
 | |
| 1164 | \bl{$A^0$}    & \bl{$\dn$} & \bl{$\{[]\}$}\\
 | |
| 1165 | \bl{$A^{n+1}$} & \bl{$\dn$} & \bl{$A \,@\, A^n$}
 | |
| 1166 | \end{tabular}
 | |
| 1167 | \end{center}\bigskip
 | |
| 1168 | ||
| 1169 | \item[] For example | |
| 1170 | ||
| 1171 | \begin{center}
 | |
| 1172 | \begin{tabular}{lcl@{\hspace{10mm}}l}
 | |
| 1173 | \bl{$A^4$} & \bl{$=$} & \bl{$A \,@\, A \,@\, A \,@\, A$} & \bl{$(@\,\{[]\})$}\\
 | |
| 1174 | \bl{$A^1$} & \bl{$=$} & \bl{$A$} & \bl{$(@\,\{[]\})$}\\
 | |
| 1175 | \bl{$A^0$} & \bl{$=$} & \bl{$\{[]\}$}\\
 | |
| 1176 | \end{tabular}
 | |
| 1177 | \end{center}
 | |
| 1178 | ||
| 1179 | \end{itemize}  
 | |
| 1180 | ||
| 1181 | \end{frame}
 | |
| 1182 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 1183 | ||
| 1184 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 1185 | \begin{frame}[c]
 | |
| 631 | 1186 |   \frametitle{The Star Operation}
 | 
| 1187 | ||
| 1188 |   \begin{itemize}
 | |
| 1189 |   \item The \alert{\bf Kleene Star} of a \underline{language}:
 | |
| 1190 | \bigskip | |
| 1191 | ||
| 1192 |   \begin{center}
 | |
| 1193 |   \begin{tabular}{c}
 | |
| 1194 |   \bl{$A\star \dn \bigcup_{0\le n} A^n$}
 | |
| 1195 |   \end{tabular}
 | |
| 1196 |   \end{center}\bigskip
 | |
| 1197 | ||
| 1198 | \item[] This expands to | |
| 1199 | ||
| 1200 | \[ | |
| 1201 |   \bl{A^0 \cup A^1 \cup A^2 \cup A^3 \cup A^4 \cup \ldots}
 | |
| 1202 | \] | |
| 1203 | ||
| 1204 | or | |
| 1205 | ||
| 1206 | \small | |
| 1207 | \[ | |
| 1208 |   \bl{\{[]\} \;\cup\; A \;\cup\; A\,@\,A \;\cup\; 
 | |
| 1209 | A\,@\,A\,@\,A \;\cup\; A\,@\,A\,@\,A\,@\,A \cup \ldots} | |
| 1210 | \] | |
| 1211 | ||
| 1212 |   \end{itemize}  
 | |
| 1213 | ||
| 1214 |   \end{frame}
 | |
| 1215 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 1216 | ||
| 1217 | ||
| 0 | 1218 | |
| 1219 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 1220 | \begin{frame}[c]
 | |
| 253 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1221 | \frametitle{Written Exam}
 | 
| 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1222 | |
| 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1223 | \begin{itemize}
 | 
| 428 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 1224 | \item Accounts for 80\%.\bigskip | 
| 253 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1225 | |
| 559 | 1226 | \item The question ``\textit{Is this relevant for
 | 
| 330 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 1227 | the exam?}'' is very demotivating for the lecturer!\bigskip\\ | 
| 253 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1228 | |
| 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1229 | \item Deal: Whatever is in the homework (and is not marked | 
| 330 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 1230 |       ``\textit{optional}'') is relevant for the exam.\bigskip
 | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 1231 | |
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 1232 | \item Each lecture has also a handout. There are also handouts about | 
| 
0806e45d873c
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
328diff
changeset | 1233 | notation and Scala. | 
| 253 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1234 | \end{itemize}
 | 
| 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1235 | |
| 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1236 | \end{frame}
 | 
| 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1237 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1238 | |
| 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1239 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1240 | \begin{frame}[t]
 | 
| 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1241 | \frametitle{Coursework}
 | 
| 0 | 1242 | |
| 1243 | \begin{itemize}
 | |
| 428 
a47c4227a0c6
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
334diff
changeset | 1244 | \item Accounts for 20\%. Two strands. Choose \alert{\bf one}!\bigskip
 | 
| 0 | 1245 | \end{itemize}
 | 
| 1246 | ||
| 255 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 1247 | \begin{columns}[t]
 | 
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 1248 | \begin{column}{.5\textwidth}
 | 
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 1249 | \underline{\bf Strand 1}\medskip
 | 
| 253 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1250 | \begin{itemize}
 | 
| 631 | 1251 | \item 4 programming tasks: | 
| 253 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1252 | \begin{itemize}
 | 
| 631 | 1253 | \item matcher (4\%, 11.10.) | 
| 1254 | \item lexer (5\%, 04.11.) | |
| 1255 | \item parser (5\%, 22.11.) | |
| 1256 | \item compiler (6\%, 13.12.) | |
| 253 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1257 | \end{itemize}
 | 
| 631 | 1258 | \item in any lang.~you like,\\ but I want to see the\\ code | 
| 253 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1259 | \end{itemize}
 | 
| 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1260 | \end{column}
 | 
| 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1261 | |
| 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1262 | \hspace{-45pt}\vrule{}\hspace{10pt}
 | 
| 255 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 1263 | \begin{column}{.5\textwidth}
 | 
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 1264 | \underline{\bf Strand 2}\smallskip\begin{itemize}
 | 
| 253 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1265 | \item one task: prove the correctness of a regular expression matcher in | 
| 559 | 1266 | the \underline{Isabelle} theorem prover
 | 
| 631 | 1267 | \item 20\%, submission on~13.12.\hspace{-5mm}\mbox{}
 | 
| 253 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1268 | \end{itemize}
 | 
| 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1269 | \end{column}
 | 
| 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1270 | \end{columns}\medskip
 | 
| 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1271 | |
| 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1272 | \small | 
| 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1273 | \begin{itemize}
 | 
| 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1274 | \item Solving more than one strand will {\bf not} give you more 
 | 
| 506 | 1275 | marks. | 
| 1276 | ||
| 253 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1277 | \end{itemize}
 | 
| 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1278 | |
| 
75c469893514
added coursework
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
252diff
changeset | 1279 | \end{frame}
 | 
| 0 | 1280 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 1281 | ||
| 255 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 1282 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 745 | 1283 | %\begin{frame}[c]
 | 
| 1284 | %\frametitle{Lecture Capture}
 | |
| 1285 | % | |
| 1286 | %\begin{itemize}
 | |
| 1287 | %\item Hope it works\ldots\pause actually no, it does not!\medskip\pause | |
| 1288 | %\item It is important to use lecture capture wisely\\ (it is only the ``baseline''): | |
| 1289 | %\begin{itemize}  
 | |
| 1290 | %\item Lecture recordings are a study and revision aid. | |
| 1291 | %\item Statistically, there is a clear and direct link between attendance and | |
| 1292 | % attainment: students who do not attend lectures, do less well in exams. | |
| 1293 | %\end{itemize}
 | |
| 1294 | % | |
| 1295 | %\item Attending a lecture is more than watching it online -- if you do not | |
| 1296 | %attend, you miss out! | |
| 1297 | % | |
| 1298 | %\end{itemize}
 | |
| 1299 | % | |
| 1300 | %\end{frame}
 | |
| 506 | 1301 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 1302 | ||
| 1303 | ||
| 1304 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 1305 | \begin{frame}[c]
 | |
| 255 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 1306 | \frametitle{\begin{tabular}{c}\\[3cm]\alert{Questions?}\end{tabular}}
 | 
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 1307 | |
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 1308 | \mbox{}
 | 
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 1309 | \end{frame}
 | 
| 
96a99237fa42
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
254diff
changeset | 1310 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 0 | 1311 | \end{document}
 | 
| 1312 | ||
| 1313 | %%% Local Variables: | |
| 1314 | %%% mode: latex | |
| 1315 | %%% TeX-master: t | |
| 1316 | %%% End: | |
| 1317 |