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