\documentclass[dvipsnames,14pt,t,xelatex]{beamer}
\usepackage{../slides}
\usepackage{../graphics}
\usepackage{../langs}
\usepackage{../data}
\hfuzz=220pt
%\setmonofont[Scale=.88]{Consolas}
%\newfontfamily{\consolas}{Consolas}
\lstset{language=Scala,
style=mystyle,
numbersep=0pt,
numbers=none,
xleftmargin=0mm}
\newcommand{\bl}[1]{\textcolor{blue}{#1}}
% beamer stuff
\renewcommand{\slidecaption}{AFL 01, King's College London}
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[t]
\frametitle{%
\begin{tabular}{@ {}c@ {}}
\\[-3mm]
\LARGE Automata and \\[-2mm]
\LARGE Formal Languages (1)\\[-3mm]
\end{tabular}}
\begin{center}
\includegraphics[scale=0.3]{pics/ante1.jpg}\hspace{5mm}
\includegraphics[scale=0.31]{pics/ante2.jpg}\\
\footnotesize\textcolor{gray}{Antikythera automaton, 100 BC (Archimedes?)}
\end{center}
\normalsize
\begin{center}
\begin{tabular}{ll}
Email: & christian.urban at kcl.ac.uk\\
Office: & S1.27 (1st floor Strand Building)\\
Slides: & KEATS
\end{tabular}
\end{center}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[c]
\begin{textblock}{1}(2,5)
\begin{tabular}{c}
\includegraphics[scale=0.15]{pics/servers.png}\\[-2mm]
\small Server
\end{tabular}
\end{textblock}
\begin{textblock}{1}(5.6,4)
\begin{tikzpicture}[scale=1.1]
\draw[white] (0,1) node (X) {};
\draw[white] (2,1) node (Y) {};
\draw[white] (0,0) node (X1) {};
\draw[white] (2,0) node (Y1) {};
\draw[white] (0,-1) node (X2) {};
\draw[white] (2,-1) node (Y2) {};
\draw[red, <-, line width = 2mm] (X) -- (Y);
\node [inner sep=5pt,label=above:\textcolor{black}{GET request}] at ($ (X)!.5!(Y) $) {};
\draw[red, ->, line width = 2mm] (X1) -- (Y1);
\node [inner sep=5pt,label=above:\textcolor{black}{webpage}] at ($ (X1)!.5!(Y1) $) {};
\draw[red, <-, line width = 2mm] (X2) -- (Y2);
\node [inner sep=7pt,label=above:\textcolor{black}{POST data}] at ($ (X2)!.5!(Y2) $) {};
\end{tikzpicture}
\end{textblock}
\begin{textblock}{1}(9,5.5)
\begin{tabular}{c}
\includegraphics[scale=0.15]{pics/laptop.png}\\[-2mm]
\small Browser
\end{tabular}
\end{textblock}
\only<2>{
\begin{textblock}{10}(2,13.5)
\begin{itemize}
\item programming languages, compilers
\end{itemize}
\end{textblock}}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[c]
transforming strings into structured data\\[10mm]
{\LARGE\bf Lexing}\medskip\\
\hspace{5mm}(recognising ``words'')\\[6mm]
{\LARGE\bf Parsing}\medskip\\
\hspace{5mm}(recognising ``sentences'')
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[c]
The subject is quite old:
\begin{itemize}
\item Turing Machines, 1936
\item first compiler for COBOL, 1957 (Grace Hopper)
\item but surprisingly research papers are still published now
\end{itemize}
\begin{flushright}
\includegraphics[scale=0.3]{pics/hopper.jpg}\\
\footnotesize\textcolor{gray}{Grace Hopper}
\end{flushright}
{\footnotesize\textcolor{gray}{(she made it to David Letterman's Tonight Show, \url{http://www.youtube.com/watch?v=aZOxtURhfEU})}}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\mode<presentation>{
\begin{frame}[c]
\frametitle{\begin{tabular}{c}This Course\end{tabular}}
\begin{itemize}
\item the ultimate goal is to implement a small compiler (a really small one for the JVM)\bigskip
\end{itemize}
Let's start with:
\begin{itemize}
\item a web-crawler
\item an email harvester
\item a web-scraper
\end{itemize}
\begin{textblock}{6}(10,7)
\begin{tikzpicture}[scale=0.38]
\begin{axis}[axis x line=bottom, axis y line=left, ylabel=secs,
xlabel=n,
enlargelimits=0.05,
ybar interval=0.7, legend style=small]
\addplot file {interpreted2.data};
\addplot file {compiled2.data};
%\legend{interpreted, compiled}
\end{axis}
\end{tikzpicture}
\end{textblock}
\end{frame}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[t]
\frametitle{A Web-Crawler}
\mbox{}\\[10mm]
\begin{enumerate}
\item given an URL, read the corresponding webpage
\item extract all links from it
\item call the web-crawler again for all these links
\end{enumerate}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\mode<presentation>{
\begin{frame}[t]
\frametitle{A Web-Crawler}
\mbox{}\\[10mm]
\begin{enumerate}
\item given an URL, read the corresponding webpage
\item if not possible print, out a problem
\item if possible, extract all links from it
\item call the web-crawler again for all these links
\end{enumerate}\bigskip\pause
\small (we need a bound for the number of recursive calls)
\small (the purpose is to check all links on my own webpage)
\end{frame}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[c]
\frametitle{Scala}
\small A simple Scala function for reading webpages:
\smallskip
\footnotesize
\lstinputlisting{../progs/app0.scala}
\medskip\pause
\lstinline{get_page("""http://www.inf.kcl.ac.uk/staff/urbanc/""")}
\bigskip\medskip\pause
\small A slightly more complicated version for handling errors properly:
\smallskip
\footnotesize
\lstinputlisting{../progs/app1.scala}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[c]
\frametitle{Why Scala?}
\begin{textblock}{6}(1,3)
\begin{tabular}{l}
\mbox{}\hspace{-1mm}\includegraphics[scale=0.36]{pics/twitter.png}\\[-1mm]
\includegraphics[scale=0.30]{pics/linked.png}\\
\includegraphics[scale=0.30]{pics/guardian.jpg}\\[-3mm]
\mbox{}\hspace{-2mm}\includegraphics[scale=0.38]{pics/morgan.png}\\[-3mm]
\includegraphics[scale=0.30]{pics/suisse.png}\\
\includegraphics[scale=0.20]{pics/edf.png}\\[-1mm]
\includegraphics[scale=0.08]{pics/novell.png}\\[-1mm]
\includegraphics[scale=0.30]{pics/foursquare.png}\\
\includegraphics[scale=0.30]{pics/hsbc.png}\\
{\large\bf ...}
\end{tabular}
\end{textblock}
\only<2->{
\begin{textblock}{6}(6,3)
\includegraphics[scale=0.35]{pics/jobgraph.png}\\
\end{textblock}}
\only<3->{
\begin{textblock}{6}(7.3,9.2)
\begin{tabular}{l}
\footnotesize 2013: 1$\%$\\[-2mm]
\footnotesize 2014: 3$\%$\\[-2mm]
\footnotesize 2015: 9$\%$\\[-2mm]
\footnotesize 2016: 27$\%$\\[-2mm]
\footnotesize 2017: 81$\%$\\[-2mm]
\footnotesize 2018: 243$\%$ \raisebox{-1mm}{\includegraphics[scale=0.02]{pics/smiley.jpg}}
\end{tabular}
\end{textblock}}
\only<3->{
\begin{textblock}{6}(6,9.5)
\footnotesize 5 yrs $\begin{cases}\mbox{}\\[1.4cm]\end{cases}$
\end{textblock}}
\only<4->{
\begin{textblock}{11}(5,14.1)
\textcolor{gray}{
\footnotesize {\bf in London today:} 1 Scala job for every 30 Java jobs;\\[-2mm]
Scala programmers seem to get up to 20\% better salary}
\end{textblock}}
\only<5->{
\begin{textblock}{1}(3,6)
\begin{bubble}[8.5cm]
\normalsize
Scala is a functional and object-oriented programming
language; compiles to the JVM; does not need null-pointer
exceptions; a course on Coursera\\
\mbox{}\hfill\url{http://www.scala-lang.org}
\end{bubble}
\end{textblock}}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[t]
\frametitle{A Regular Expression}
\begin{itemize}
\item \ldots{} is a pattern or template for specifying strings
\end{itemize}\bigskip
\begin{center}
\only<1>{\scode{"https?://[^"]*"}}%
\only<2>{\scode{""""https?://[^"]*"""".r}}
\end{center}\bigskip\bigskip
matches for example\smallskip\\
\hspace{2mm}\code{"http://www.foobar.com"}\\
\hspace{2mm}\code{"https://www.tls.org"}\\
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[t]
\frametitle{Finding Operations}
{\bf\code{rexp.findAllIn(string)}}\medskip
returns a list of all (sub)strings that match the
regular expression
\bigskip\bigskip
{\bf\code{rexp.findFirstIn(string)}}\medskip
returns either
\begin{itemize}
\item \code{None} if no (sub)string matches or
\item \code{Some(s)} with the first (sub)string
\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[c]
\footnotesize
\lstinputlisting{../progs/app2.scala}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[c]
\small
A version that only crawls links in ``my'' domain:
\footnotesize
\lstinputlisting{../progs/app3.scala}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[c]
\lstset{xleftmargin=-4mm}
\small
A little email harvester:
\footnotesize
\lstinputlisting{../progs/app4.scala}\bigskip
\tiny
\url{http://net.tutsplus.com/tutorials/other/8-regular-expressions-you-should-know/}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[t]
\frametitle{\begin{tabular}{c}Regular Expressions\end{tabular}}
Their inductive definition:\medskip
\begin{textblock}{6}(2,5)
\begin{tabular}{rrl@ {\hspace{13mm}}l}
\bl{$r$} & \bl{$::=$} & \bl{$\varnothing$} & null\\
& \bl{$\mid$} & \bl{$\epsilon$} & empty string / \pcode{""} / \pcode{[]}\\
& \bl{$\mid$} & \bl{$c$} & character\\
& \bl{$\mid$} & \bl{$r_1 \cdot r_2$} & sequence\\
& \bl{$\mid$} & \bl{$r_1 + r_2$} & alternative / choice\\
& \bl{$\mid$} & \bl{$r^*$} & star (zero or more)\\
\end{tabular}
\end{textblock}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[t]
\frametitle{Regular Expressions}
\small
In Scala:\bigskip
\footnotesize
\lstinputlisting{../progs/app51.scala}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\mode<presentation>{
\begin{frame}[c]
\frametitle{\begin{tabular}{c}The Meaning of a\\[-2mm]
Regular Expression\end{tabular}}
\begin{textblock}{15}(1,4)
\begin{tabular}{rcl}
\bl{$L(\varnothing)$} & \bl{$\dn$} & \bl{$\varnothing$}\\
\bl{$L(\epsilon)$} & \bl{$\dn$} & \bl{$\{[]\}$}\\
\bl{$L(c)$} & \bl{$\dn$} & \bl{$\{[c]\}$}\\
\bl{$L(r_1 + r_2)$} & \bl{$\dn$} & \bl{$L(r_1) \cup L(r_2)$}\\
\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) \}$}\\
\bl{$L(r^*)$} & \bl{$\dn$} & \onslide<4->{\bl{$\bigcup_{n \ge 0} L(r)^n$}}\\
\end{tabular}\bigskip
\onslide<2->{
\hspace{5mm}\bl{$L(r)^0 \;\dn\; \{[]\}$}\\
\bl{$L(r)^{n+1} \;\dn\; L(r) \,@\, L(r)^n$}\hspace{9mm}\onslide<3->{\small\textcolor{gray}{(append on sets)}\\
\small\hspace{5cm}\textcolor{gray}{$\{ s_1 @ s_2 \;|\; s_1\in L(r) \wedge s_2 \in L(r)^n \}$}}
}
\end{textblock}
\end{frame}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[c]
\frametitle{The Meaning of Matching}
\begin{bubble}[10cm]
\large
A regular expression \bl{$r$} matches a string \bl{$s$}
provided
\begin{center}
\bl{$s \in L(r)$}\\
\end{center}
\end{bubble}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\mode<presentation>{
\begin{frame}[c]
\frametitle{\begin{tabular}{c}This Course\end{tabular}}
We will have a look at:
\begin{itemize}
\item regular expressions / regular expression matching
\item derivatives
\item automata
\item parsing
\item grammars
\item a small interpreter / compiler
\end{itemize}
\end{frame}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[c]
\frametitle{Written Exam}
\begin{itemize}
\item Accounts for 75\%.\bigskip
\item You will understand the question ``Is this relevant for
the exam?'' is very demotivating for the lecturer!\bigskip\\
\item Deal: Whatever is in the homework (and is not marked
``optional'') is relevant for the exam.
\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[t]
\frametitle{Coursework}
\begin{itemize}
\item Accounts for 25\%. Two strands. Choose \alert{\bf one}!\bigskip
\end{itemize}
\begin{columns}[t]
\begin{column}{.5\textwidth}
\underline{\bf Strand 1}\medskip
\begin{itemize}
\item four programming subtasks:
\begin{itemize}
\item matcher (5\%, 13.10.)
\item lexer (5\%, 03.11.)
\item parser (5\%, 27.11.)
\item compiler (10\%, 12.12.)
\end{itemize}
\end{itemize}
\end{column}
\hspace{-45pt}\vrule{}\hspace{10pt}
\begin{column}{.5\textwidth}
\underline{\bf Strand 2}\smallskip
\begin{itemize}
\item one task: prove the correctness of a regular expression matcher in
the Isabelle theorem prover
\item 25\%, submission 12.12.
\end{itemize}
\end{column}
\end{columns}\medskip
\small
\begin{itemize}
\item Solving more than one strand will {\bf not} give you more
marks.\\[-2mm]
\item The exam will contain in much, much smaller form
elements from both (but will also be in lectures and HW).
\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End: