author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Tue, 24 Sep 2013 23:16:00 +0100 | |
changeset 97 | 60a3ba90dd53 |
parent 95 | dbe49327b6c5 |
child 98 | 1f3d89fe9820 |
permissions | -rw-r--r-- |
95
dbe49327b6c5
added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
1 |
\documentclass[dvipsnames,14pt,t,xelatex]{beamer} |
dbe49327b6c5
added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
2 |
\usepackage{beamerthemeplaincu} |
dbe49327b6c5
added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
3 |
\usepackage{fontenc,xltxtra,xunicode} |
dbe49327b6c5
added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
4 |
\defaultfontfeatures{Mapping=tex-text} |
0 | 5 |
\usepackage{mathpartir} |
6 |
\usepackage[absolute,overlay]{textpos} |
|
7 |
\usepackage{ifthen} |
|
8 |
\usepackage{tikz} |
|
9 |
\usepackage{pgf} |
|
10 |
\usepackage{calc} |
|
11 |
\usepackage{ulem} |
|
95
dbe49327b6c5
added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
12 |
%%\usepackage{courier} |
0 | 13 |
\usepackage{listings} |
14 |
\renewcommand{\uline}[1]{#1} |
|
15 |
\usetikzlibrary{arrows} |
|
16 |
\usetikzlibrary{automata} |
|
17 |
\usetikzlibrary{shapes} |
|
18 |
\usetikzlibrary{shadows} |
|
19 |
\usetikzlibrary{positioning} |
|
20 |
\usetikzlibrary{calc} |
|
21 |
\usepackage{graphicx} |
|
22 |
||
23 |
\definecolor{javared}{rgb}{0.6,0,0} % for strings |
|
24 |
\definecolor{javagreen}{rgb}{0.25,0.5,0.35} % comments |
|
25 |
\definecolor{javapurple}{rgb}{0.5,0,0.35} % keywords |
|
26 |
\definecolor{javadocblue}{rgb}{0.25,0.35,0.75} % javadoc |
|
27 |
||
95
dbe49327b6c5
added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
28 |
\makeatletter |
dbe49327b6c5
added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
29 |
\lst@CCPutMacro\lst@ProcessOther {"2D}{\lst@ttfamily{-{}}{-{}}} |
dbe49327b6c5
added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
30 |
\@empty\z@\@empty |
dbe49327b6c5
added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
31 |
\makeatother |
dbe49327b6c5
added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
32 |
|
0 | 33 |
\lstset{language=Java, |
34 |
basicstyle=\ttfamily, |
|
35 |
keywordstyle=\color{javapurple}\bfseries, |
|
36 |
stringstyle=\color{javagreen}, |
|
37 |
commentstyle=\color{javagreen}, |
|
38 |
morecomment=[s][\color{javadocblue}]{/**}{*/}, |
|
39 |
numbers=left, |
|
40 |
numberstyle=\tiny\color{black}, |
|
41 |
stepnumber=1, |
|
42 |
numbersep=10pt, |
|
43 |
tabsize=2, |
|
44 |
showspaces=false, |
|
45 |
showstringspaces=false} |
|
46 |
||
47 |
\lstdefinelanguage{scala}{ |
|
48 |
morekeywords={abstract,case,catch,class,def,% |
|
49 |
do,else,extends,false,final,finally,% |
|
50 |
for,if,implicit,import,match,mixin,% |
|
51 |
new,null,object,override,package,% |
|
52 |
private,protected,requires,return,sealed,% |
|
53 |
super,this,throw,trait,true,try,% |
|
54 |
type,val,var,while,with,yield}, |
|
55 |
otherkeywords={=>,<-,<\%,<:,>:,\#,@}, |
|
56 |
sensitive=true, |
|
57 |
morecomment=[l]{//}, |
|
58 |
morecomment=[n]{/*}{*/}, |
|
59 |
morestring=[b]", |
|
60 |
morestring=[b]', |
|
61 |
morestring=[b]""" |
|
62 |
} |
|
63 |
||
64 |
\lstset{language=Scala, |
|
65 |
basicstyle=\ttfamily, |
|
66 |
keywordstyle=\color{javapurple}\bfseries, |
|
67 |
stringstyle=\color{javagreen}, |
|
68 |
commentstyle=\color{javagreen}, |
|
69 |
morecomment=[s][\color{javadocblue}]{/**}{*/}, |
|
70 |
numbers=left, |
|
71 |
numberstyle=\tiny\color{black}, |
|
72 |
stepnumber=1, |
|
73 |
numbersep=10pt, |
|
74 |
tabsize=2, |
|
75 |
showspaces=false, |
|
76 |
showstringspaces=false} |
|
77 |
||
78 |
% beamer stuff |
|
97
60a3ba90dd53
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
95
diff
changeset
|
79 |
\renewcommand{\slidecaption}{AFL 01, King's College London, 25.~September 2013} |
0 | 80 |
|
81 |
||
82 |
\begin{document} |
|
83 |
||
84 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
85 |
\mode<presentation>{ |
|
86 |
\begin{frame}<1>[t] |
|
87 |
\frametitle{% |
|
88 |
\begin{tabular}{@ {}c@ {}} |
|
1 | 89 |
\\[-3mm] |
90 |
\LARGE Automata and \\[-2mm] |
|
91 |
\LARGE Formal Languages (1)\\[-3mm] |
|
0 | 92 |
\end{tabular}} |
93 |
||
94 |
\begin{center} |
|
1 | 95 |
\includegraphics[scale=0.3]{pics/ante1.jpg}\hspace{5mm} |
96 |
\includegraphics[scale=0.31]{pics/ante2.jpg}\\ |
|
97 |
\footnotesize\textcolor{gray}{Antikythera automaton, 100 BC (Archimedes?)} |
|
0 | 98 |
\end{center} |
99 |
||
100 |
\normalsize |
|
101 |
\begin{center} |
|
102 |
\begin{tabular}{ll} |
|
103 |
Email: & christian.urban at kcl.ac.uk\\ |
|
95
dbe49327b6c5
added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
104 |
Office: & S1.27 (1st floor Strand Building)\\ |
0 | 105 |
Slides: & KEATS |
106 |
\end{tabular} |
|
107 |
\end{center} |
|
108 |
||
109 |
||
110 |
\end{frame}} |
|
111 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
112 |
||
113 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
114 |
\mode<presentation>{ |
|
115 |
\begin{frame}[c] |
|
116 |
||
1 | 117 |
\begin{textblock}{1}(2,5) |
0 | 118 |
\begin{tabular}{c} |
1 | 119 |
\includegraphics[scale=0.15]{pics/servers.png}\\[-2mm] |
120 |
\small Server |
|
0 | 121 |
\end{tabular} |
122 |
\end{textblock} |
|
123 |
||
1 | 124 |
\begin{textblock}{1}(5.6,4) |
125 |
\begin{tikzpicture}[scale=1.1] |
|
126 |
\draw[white] (0,1) node (X) {}; |
|
127 |
\draw[white] (2,1) node (Y) {}; |
|
128 |
\draw[white] (0,0) node (X1) {}; |
|
129 |
\draw[white] (2,0) node (Y1) {}; |
|
130 |
\draw[white] (0,-1) node (X2) {}; |
|
131 |
\draw[white] (2,-1) node (Y2) {}; |
|
132 |
\draw[red, <-, line width = 2mm] (X) -- (Y); |
|
133 |
\node [inner sep=5pt,label=above:\textcolor{black}{GET request}] at ($ (X)!.5!(Y) $) {}; |
|
134 |
\draw[red, ->, line width = 2mm] (X1) -- (Y1); |
|
135 |
\node [inner sep=5pt,label=above:\textcolor{black}{webpage}] at ($ (X1)!.5!(Y1) $) {}; |
|
136 |
\draw[red, <-, line width = 2mm] (X2) -- (Y2); |
|
137 |
\node [inner sep=7pt,label=above:\textcolor{black}{POST data}] at ($ (X2)!.5!(Y2) $) {}; |
|
0 | 138 |
\end{tikzpicture} |
139 |
\end{textblock} |
|
140 |
||
141 |
||
1 | 142 |
\begin{textblock}{1}(9,5.5) |
0 | 143 |
\begin{tabular}{c} |
1 | 144 |
\includegraphics[scale=0.15]{pics/laptop.png}\\[-2mm] |
145 |
\small Browser |
|
0 | 146 |
\end{tabular} |
147 |
\end{textblock} |
|
148 |
||
1 | 149 |
\only<2>{ |
150 |
\begin{textblock}{10}(2,13.5) |
|
0 | 151 |
\begin{itemize} |
1 | 152 |
\item programming languages, compilers |
0 | 153 |
\end{itemize} |
1 | 154 |
\end{textblock}} |
0 | 155 |
|
156 |
||
157 |
\end{frame}} |
|
158 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
159 |
||
160 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
161 |
\mode<presentation>{ |
|
162 |
\begin{frame}[c] |
|
1 | 163 |
|
164 |
transforming strings into structured data\\[10mm] |
|
0 | 165 |
|
1 | 166 |
{\LARGE\bf Lexing}\medskip\\ |
167 |
\hspace{5mm}(recognising ``words'')\\[6mm] |
|
0 | 168 |
|
1 | 169 |
{\LARGE\bf Parsing}\medskip\\ |
170 |
\hspace{5mm}(recognising ``sentences'') |
|
171 |
||
0 | 172 |
\end{frame}} |
1 | 173 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
174 |
||
0 | 175 |
|
176 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
177 |
\mode<presentation>{ |
|
178 |
\begin{frame}[c] |
|
179 |
||
1 | 180 |
The subject is quite old: |
0 | 181 |
|
182 |
\begin{itemize} |
|
1 | 183 |
\item Turing Machines, 1936 |
184 |
\item first compiler for COBOL, 1957 (Grace Hopper) |
|
185 |
\item but surprisingly research papers are still published now |
|
0 | 186 |
\end{itemize} |
187 |
||
1 | 188 |
\begin{flushright} |
189 |
\includegraphics[scale=0.3]{pics/hopper.jpg}\\ |
|
190 |
\footnotesize\textcolor{gray}{Grace Hopper} |
|
191 |
\end{flushright} |
|
192 |
||
193 |
{\footnotesize\textcolor{gray}{(she made it to David Letterman's Tonight Show, \url{http://www.youtube.com/watch?v=aZOxtURhfEU})}} |
|
0 | 194 |
|
1 | 195 |
\end{frame}} |
196 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
197 |
||
198 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
199 |
\mode<presentation>{ |
|
200 |
\begin{frame}[c] |
|
201 |
\frametitle{\begin{tabular}{c}This Course\end{tabular}} |
|
0 | 202 |
|
1 | 203 |
\begin{itemize} |
97
60a3ba90dd53
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
95
diff
changeset
|
204 |
\item the ultimate goal is to implement a small compiler (a really small one for the JVM)\bigskip |
1 | 205 |
\end{itemize} |
206 |
||
207 |
Let's start with: |
|
208 |
||
209 |
\begin{itemize} |
|
210 |
\item a web-crawler |
|
211 |
\item an email harvester |
|
212 |
\item a web-scraper |
|
213 |
\end{itemize} |
|
214 |
||
215 |
\end{frame}} |
|
216 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
0 | 217 |
|
2 | 218 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
219 |
\mode<presentation>{ |
|
3 | 220 |
\begin{frame}[t] |
13 | 221 |
\frametitle{\begin{tabular}{c}A Web-Crawler\end{tabular}} |
2 | 222 |
|
3 | 223 |
\mbox{}\\[10mm] |
224 |
||
2 | 225 |
\begin{enumerate} |
226 |
\item given an URL, read the corresponding webpage |
|
227 |
\item extract all links from it |
|
228 |
\item call the web-crawler again for all these links |
|
229 |
\end{enumerate} |
|
230 |
||
231 |
\end{frame}} |
|
232 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
233 |
||
234 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
235 |
\mode<presentation>{ |
|
3 | 236 |
\begin{frame}[t] |
13 | 237 |
\frametitle{\begin{tabular}{c}A Web-Crawler\end{tabular}} |
2 | 238 |
|
3 | 239 |
\mbox{}\\[10mm] |
240 |
||
241 |
||
2 | 242 |
\begin{enumerate} |
243 |
\item given an URL, read the corresponding webpage |
|
244 |
\item if not possible print, out a problem |
|
245 |
\item if possible, extract all links from it |
|
246 |
\item call the web-crawler again for all these links |
|
247 |
\end{enumerate}\bigskip\pause |
|
248 |
||
3 | 249 |
\small (we need a bound for the number of recursive calls) |
2 | 250 |
|
251 |
\small (the purpose is to check all links on my own webpage) |
|
252 |
\end{frame}} |
|
253 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
254 |
||
0 | 255 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
256 |
\mode<presentation>{ |
|
257 |
\begin{frame}[c] |
|
1 | 258 |
\frametitle{\begin{tabular}{c}Scala\end{tabular}} |
259 |
||
97
60a3ba90dd53
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
95
diff
changeset
|
260 |
\small a simple Scala function for reading webpages\\[-3mm] |
0 | 261 |
|
97
60a3ba90dd53
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
95
diff
changeset
|
262 |
{\lstset{language=Scala}\texttt{\lstinputlisting{../progs/app0.scala}}}\pause |
60a3ba90dd53
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
95
diff
changeset
|
263 |
{\lstset{language=Scala}\texttt{\lstinline{get_page("""http://www.inf.kcl.ac.uk/staff/urbanc/""")}}}\pause\bigskip |
0 | 264 |
|
3 | 265 |
|
97
60a3ba90dd53
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
95
diff
changeset
|
266 |
\small slightly more complicated for handling errors properly:\\[-3mm] |
2 | 267 |
|
97
60a3ba90dd53
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
95
diff
changeset
|
268 |
\small |
60a3ba90dd53
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
95
diff
changeset
|
269 |
{\lstset{language=Scala}\texttt{\lstinputlisting{../progs/app1.scala}}} |
1 | 270 |
|
0 | 271 |
|
272 |
\end{frame}} |
|
273 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
274 |
||
275 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
276 |
\mode<presentation>{ |
|
3 | 277 |
\begin{frame}[t] |
278 |
\frametitle{\begin{tabular}{c}A Regular Expression\end{tabular}} |
|
279 |
||
280 |
\begin{itemize} |
|
281 |
\item \ldots{} is a pattern or template for specifying strings |
|
282 |
\end{itemize}\bigskip |
|
283 |
||
284 |
\begin{center} |
|
285 |
\only<1>{{\lstset{language=Scala}\fontsize{18}{19}\selectfont\bf |
|
286 |
\texttt{"https?://[$\hat{\hspace{2mm}}$"]*"}}}% |
|
287 |
\only<2>{{\lstset{language=Scala}\fontsize{18}{19}\selectfont\bf |
|
288 |
\texttt{"""\textbackslash{}"https?://[$\hat{\hspace{2mm}}$\textbackslash{}"]*\textbackslash{}"""".r}}} |
|
289 |
\end{center}\bigskip\bigskip |
|
290 |
||
291 |
matches for example\\ |
|
292 |
\;{\lstset{language=Scala}\fontsize{12}{14}\selectfont\bf |
|
293 |
\texttt{"http://www.foobar.com"}}\\ |
|
294 |
\;{\lstset{language=Scala}\fontsize{12}{14}\selectfont\bf |
|
295 |
\texttt{"https://www.tls.org"}}\\ |
|
296 |
||
297 |
\end{frame}} |
|
298 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
299 |
||
300 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
301 |
\mode<presentation>{ |
|
0 | 302 |
\begin{frame}[c] |
303 |
||
3 | 304 |
{\lstset{language=Scala}\fontsize{18}{19}\selectfont\bf |
305 |
\texttt{rexp.findAllIn(string)}}\medskip |
|
306 |
||
307 |
returns a list of all (sub)strings that match the regular expression\bigskip\bigskip |
|
308 |
||
309 |
{\lstset{language=Scala}\fontsize{18}{19}\selectfont\bf |
|
310 |
\texttt{rexp.findFirstIn(string)}}\medskip |
|
311 |
||
312 |
returns either {\bf\texttt{None}} if no (sub)string matches |
|
313 |
or {\bf\texttt{Some(s)}} with the first (sub)string |
|
0 | 314 |
|
315 |
\end{frame}} |
|
316 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
317 |
||
318 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
319 |
\mode<presentation>{ |
|
320 |
\begin{frame}[c] |
|
321 |
||
97
60a3ba90dd53
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
95
diff
changeset
|
322 |
\small |
60a3ba90dd53
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
95
diff
changeset
|
323 |
{\lstset{language=Scala}\texttt{\lstinputlisting{../progs/app2.scala}}}\medskip |
0 | 324 |
|
97
60a3ba90dd53
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
95
diff
changeset
|
325 |
{\lstset{language=Scala}\texttt{crawl(some\_start\_URL, 2)}}\ |
0 | 326 |
|
327 |
\end{frame}} |
|
328 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
329 |
||
330 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
331 |
\mode<presentation>{ |
|
3 | 332 |
\begin{frame}[c] |
0 | 333 |
|
3 | 334 |
\footnotesize |
335 |
a version that only ``crawls'' links in my domain: |
|
0 | 336 |
|
97
60a3ba90dd53
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
95
diff
changeset
|
337 |
\small |
60a3ba90dd53
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
95
diff
changeset
|
338 |
{\lstset{language=Scala}\texttt{\lstinputlisting{../progs/app3.scala}}} |
0 | 339 |
|
340 |
||
341 |
\end{frame}} |
|
342 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
343 |
||
344 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
345 |
\mode<presentation>{ |
|
346 |
\begin{frame}[c] |
|
3 | 347 |
|
348 |
\footnotesize |
|
349 |
a little email ``harvester'': |
|
350 |
||
97
60a3ba90dd53
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
95
diff
changeset
|
351 |
\small |
60a3ba90dd53
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
95
diff
changeset
|
352 |
{\lstset{language=Scala}\texttt{\lstinputlisting{../progs/app4.scala}}}\bigskip |
3 | 353 |
|
354 |
\tiny |
|
355 |
\textcolor{gray}{\url{http://net.tutsplus.com/tutorials/other/8-regular-expressions-you-should-know/}} |
|
356 |
||
357 |
\end{frame}} |
|
358 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
359 |
||
360 |
\newcommand{\bl}[1]{\textcolor{blue}{#1}} |
|
361 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
362 |
\mode<presentation>{ |
|
14 | 363 |
\begin{frame}[t] |
3 | 364 |
\frametitle{\begin{tabular}{c}Regular Expressions\end{tabular}} |
0 | 365 |
|
14 | 366 |
Their inductive definition:\medskip |
367 |
||
368 |
\begin{textblock}{6}(2,5) |
|
3 | 369 |
\begin{tabular}{@ {}rrl@ {\hspace{13mm}}l} |
370 |
\bl{r} & \bl{$::=$} & \bl{$\varnothing$} & null\\ |
|
5 | 371 |
& \bl{$\mid$} & \bl{$\epsilon$} & empty string / "" / []\\ |
3 | 372 |
& \bl{$\mid$} & \bl{c} & character\\ |
373 |
& \bl{$\mid$} & \bl{r$_1$ $\cdot$ r$_2$} & sequence\\ |
|
374 |
& \bl{$\mid$} & \bl{r$_1$ + r$_2$} & alternative / choice\\ |
|
375 |
& \bl{$\mid$} & \bl{r$^*$} & star (zero or more)\\ |
|
376 |
\end{tabular} |
|
377 |
\end{textblock} |
|
378 |
||
379 |
\end{frame}} |
|
380 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
381 |
||
382 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
383 |
\mode<presentation>{ |
|
384 |
\begin{frame}[t] |
|
385 |
\frametitle{\begin{tabular}{c}Regular Expressions\end{tabular}} |
|
386 |
||
14 | 387 |
\small |
388 |
In Scala: |
|
389 |
||
390 |
||
3 | 391 |
{\lstset{language=Scala}\fontsize{8}{10}\selectfont |
95
dbe49327b6c5
added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
392 |
\texttt{\lstinputlisting{../progs/app51.scala}}} |
0 | 393 |
|
394 |
||
395 |
\end{frame}} |
|
396 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
397 |
||
3 | 398 |
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions |
0 | 399 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
400 |
\mode<presentation>{ |
|
401 |
\begin{frame}[c] |
|
3 | 402 |
\frametitle{\begin{tabular}{c}The Meaning of a\\[-2mm] Regular Expression\end{tabular}} |
0 | 403 |
|
4 | 404 |
\begin{textblock}{15}(1,4) |
3 | 405 |
\begin{tabular}{@ {}rcl} |
406 |
\bl{$L$($\varnothing$)} & \bl{$\dn$} & \bl{$\varnothing$}\\ |
|
407 |
\bl{$L$($\epsilon$)} & \bl{$\dn$} & \bl{$\{$""$\}$}\\ |
|
408 |
\bl{$L$(c)} & \bl{$\dn$} & \bl{$\{$"c"$\}$}\\ |
|
409 |
\bl{$L$(r$_1$ + r$_2$)} & \bl{$\dn$} & \bl{$L$(r$_1$) $\cup$ $L$(r$_2$)}\\ |
|
4 | 410 |
\bl{$L$(r$_1$ $\cdot$ r$_2$)} & \bl{$\dn$} & \bl{$\{$ s$_1$ @ s$_2$ $|$ s$_1$ $\in$ $L$(r$_1$) $\wedge$ s$_2$ $\in$ |
411 |
$L$(r$_2$) $\}$}\\ |
|
5 | 412 |
\bl{$L$(r$^*$)} & \bl{$\dn$} & \onslide<4->{\bl{$\bigcup_{n \ge 0}$ $L$(r)$^n$}}\\ |
4 | 413 |
\end{tabular}\bigskip |
3 | 414 |
|
4 | 415 |
\onslide<2->{ |
416 |
\hspace{5mm}\bl{$L$(r)$^0$ $\;\dn\;$ $\{$""$\}$}\\ |
|
5 | 417 |
\bl{$L$(r)$^{n+1}$ $\;\dn\;$ $L$(r) @ $L$(r)$^n$}\hspace{9mm}\onslide<3->{\small\textcolor{gray}{(append on sets)}\\ |
418 |
\small\hspace{5cm}\textcolor{gray}{$\{$ s$_1$ @ s$_2$ $|$ s$_1$ $\in$ $L$(r) $\wedge$ s$_2$ $\in$ |
|
419 |
$L$(r)$^n$ $\}$}} |
|
4 | 420 |
} |
421 |
\end{textblock} |
|
422 |
||
0 | 423 |
\end{frame}} |
424 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
425 |
||
5 | 426 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
427 |
\mode<presentation>{ |
|
428 |
\begin{frame}[c] |
|
8 | 429 |
\frametitle{\begin{tabular}{c}The Meaning of Matching\end{tabular}} |
5 | 430 |
|
431 |
\large |
|
432 |
a regular expression \bl{r} matches a string \bl{s} is defined as |
|
433 |
||
434 |
\begin{center} |
|
435 |
\bl{s $\in$ $L$(r)}\\ |
|
436 |
\end{center} |
|
437 |
||
438 |
\end{frame}} |
|
439 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
440 |
||
3 | 441 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
442 |
\mode<presentation>{ |
|
443 |
\begin{frame}[c] |
|
444 |
\frametitle{\begin{tabular}{c}This Course\end{tabular}} |
|
445 |
||
7 | 446 |
We will have a look at: |
3 | 447 |
|
448 |
\begin{itemize} |
|
7 | 449 |
\item regular expressions / regular expression matching |
97
60a3ba90dd53
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
95
diff
changeset
|
450 |
\item derivatives |
3 | 451 |
\item automata |
452 |
\item parsing |
|
453 |
\item grammars |
|
97
60a3ba90dd53
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
95
diff
changeset
|
454 |
\item a small interpreter / compiler |
3 | 455 |
\end{itemize} |
456 |
||
457 |
\end{frame}} |
|
458 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
459 |
||
0 | 460 |
|
461 |
||
462 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
463 |
\mode<presentation>{ |
|
464 |
\begin{frame}[c] |
|
1 | 465 |
\frametitle{\begin{tabular}{c}Exam\end{tabular}} |
0 | 466 |
|
467 |
\begin{itemize} |
|
7 | 468 |
\item The question ``Is this relevant for the exam?'' is not appreciated!\bigskip\\ |
0 | 469 |
|
14 | 470 |
Whatever is in the homework sheets (and is not marked ``optional'') is relevant for the |
471 |
exam.\\ No code needs to be written in the exam. |
|
0 | 472 |
\end{itemize} |
473 |
||
474 |
\end{frame}} |
|
475 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
476 |
||
477 |
||
478 |
\end{document} |
|
479 |
||
480 |
%%% Local Variables: |
|
481 |
%%% mode: latex |
|
482 |
%%% TeX-master: t |
|
483 |
%%% End: |
|
484 |