author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Tue, 08 Oct 2013 21:37:13 +0100 | |
changeset 134 | e3a8cf96f570 |
parent 133 | 09efdf5cf07c |
child 135 | 72b686e1c974 |
permissions | -rw-r--r-- |
25 | 1 |
\documentclass[dvipsnames,14pt,t]{beamer} |
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
2 |
\usepackage{beamerthemeplaincu} |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
3 |
%%\usepackage[T1]{fontenc} |
25 | 4 |
\usepackage[latin1]{inputenc} |
5 |
\usepackage{mathpartir} |
|
6 |
\usepackage[absolute,overlay]{textpos} |
|
7 |
\usepackage{ifthen} |
|
8 |
\usepackage{tikz} |
|
9 |
\usepackage{pgf} |
|
10 |
\usepackage{calc} |
|
11 |
\usepackage{ulem} |
|
12 |
\usepackage{courier} |
|
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 |
|
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
27 |
\makeatletter |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
28 |
\lst@CCPutMacro\lst@ProcessOther {"2D}{\lst@ttfamily{-{}}{-{}}} |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
29 |
\@empty\z@\@empty |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
30 |
\makeatother |
25 | 31 |
|
32 |
\lstset{language=Java, |
|
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
33 |
basicstyle=\consolas, |
25 | 34 |
keywordstyle=\color{javapurple}\bfseries, |
35 |
stringstyle=\color{javagreen}, |
|
36 |
commentstyle=\color{javagreen}, |
|
37 |
morecomment=[s][\color{javadocblue}]{/**}{*/}, |
|
38 |
numbers=left, |
|
39 |
numberstyle=\tiny\color{black}, |
|
40 |
stepnumber=1, |
|
41 |
numbersep=10pt, |
|
42 |
tabsize=2, |
|
43 |
showspaces=false, |
|
44 |
showstringspaces=false} |
|
45 |
||
46 |
\lstdefinelanguage{scala}{ |
|
47 |
morekeywords={abstract,case,catch,class,def,% |
|
48 |
do,else,extends,false,final,finally,% |
|
49 |
for,if,implicit,import,match,mixin,% |
|
50 |
new,null,object,override,package,% |
|
51 |
private,protected,requires,return,sealed,% |
|
52 |
super,this,throw,trait,true,try,% |
|
53 |
type,val,var,while,with,yield}, |
|
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
54 |
otherkeywords={=>,<-,<\%,<:,>:,\#,@,->}, |
25 | 55 |
sensitive=true, |
56 |
morecomment=[l]{//}, |
|
57 |
morecomment=[n]{/*}{*/}, |
|
58 |
morestring=[b]", |
|
59 |
morestring=[b]', |
|
60 |
morestring=[b]""" |
|
61 |
} |
|
62 |
||
63 |
\lstset{language=Scala, |
|
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
64 |
basicstyle=\consolas, |
25 | 65 |
keywordstyle=\color{javapurple}\bfseries, |
66 |
stringstyle=\color{javagreen}, |
|
67 |
commentstyle=\color{javagreen}, |
|
68 |
morecomment=[s][\color{javadocblue}]{/**}{*/}, |
|
69 |
numbers=left, |
|
70 |
numberstyle=\tiny\color{black}, |
|
71 |
stepnumber=1, |
|
72 |
numbersep=10pt, |
|
73 |
tabsize=2, |
|
74 |
showspaces=false, |
|
75 |
showstringspaces=false} |
|
76 |
||
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
77 |
|
25 | 78 |
% beamer stuff |
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
79 |
\renewcommand{\slidecaption}{AFL 03, King's College London, 9.~October 2013} |
25 | 80 |
\newcommand{\bl}[1]{\textcolor{blue}{#1}} |
81 |
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions |
|
82 |
||
83 |
\begin{document} |
|
84 |
||
85 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
86 |
\mode<presentation>{ |
|
87 |
\begin{frame}<1>[t] |
|
88 |
\frametitle{% |
|
89 |
\begin{tabular}{@ {}c@ {}} |
|
90 |
\\[-3mm] |
|
91 |
\LARGE Automata and \\[-2mm] |
|
92 |
\LARGE Formal Languages (3)\\[3mm] |
|
93 |
\end{tabular}} |
|
94 |
||
95 |
%\begin{center} |
|
96 |
%\includegraphics[scale=0.3]{pics/ante1.jpg}\hspace{5mm} |
|
97 |
%\includegraphics[scale=0.31]{pics/ante2.jpg}\\ |
|
98 |
%\footnotesize\textcolor{gray}{Antikythera automaton, 100 BC (Archimedes?)} |
|
99 |
%\end{center} |
|
100 |
||
101 |
\normalsize |
|
102 |
\begin{center} |
|
134
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
103 |
\begin{tabular}{lp{8cm}} |
25 | 104 |
Email: & christian.urban at kcl.ac.uk\\ |
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
105 |
Office: & S1.27 (1st floor Strand Building)\\ |
134
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
106 |
Slides: & KEATS (also home work and coursework is there)\\ |
25 | 107 |
\end{tabular} |
108 |
\end{center} |
|
109 |
||
110 |
||
111 |
\end{frame}} |
|
112 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
113 |
||
114 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
115 |
\mode<presentation>{ |
|
116 |
\begin{frame}[c] |
|
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
117 |
\frametitle{\begin{tabular}{c}Regular Expressions\end{tabular}} |
25 | 118 |
|
134
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
119 |
In programming languages they are often used to recognise:\medskip |
25 | 120 |
|
121 |
\begin{itemize} |
|
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
122 |
\item symbols, digits |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
123 |
\item identifiers |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
124 |
\item numbers (non-leading zeros) |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
125 |
\item keywords |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
126 |
\item comments |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
127 |
\end{itemize}\bigskip |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
128 |
|
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
129 |
|
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
130 |
\mbox{}\hfill\bl{\url{http://www.regexper.com}} |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
131 |
\end{frame}} |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
132 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
133 |
|
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
134 |
|
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
135 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
136 |
\mode<presentation>{ |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
137 |
\begin{frame}[c] |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
138 |
\frametitle{\begin{tabular}{c}Last Week\end{tabular}} |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
139 |
|
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
140 |
Last week I showed you a regular expression matcher |
134
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
141 |
which works provably correctly in all cases. |
25 | 142 |
|
143 |
\begin{center} |
|
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
144 |
\bl{$matcher\,r\,s$} \;\;if and only if \;\; \bl{$s \in L(r)$} |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
145 |
\end{center}\bigskip\bigskip |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
146 |
|
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
147 |
\small |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
148 |
\textcolor{gray}{\mbox{}\hfill{}by Janusz Brzozowski (1964)} |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
149 |
|
25 | 150 |
|
151 |
\end{frame}} |
|
152 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
153 |
||
154 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
155 |
\mode<presentation>{ |
|
156 |
\begin{frame}[c] |
|
157 |
\frametitle{\begin{tabular}{c}The Derivative of a Rexp\end{tabular}} |
|
158 |
||
159 |
\begin{center} |
|
160 |
\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {\hspace{-10mm}}l@ {}} |
|
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
161 |
\bl{$der\, c\, (\varnothing)$} & \bl{$\dn$} & \bl{$\varnothing$} & \\ |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
162 |
\bl{$der\, c\, (\epsilon)$} & \bl{$\dn$} & \bl{$\varnothing$} & \\ |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
163 |
\bl{$der\, c\, (d)$} & \bl{$\dn$} & \bl{if $c = d$ then $\epsilon$ else $\varnothing$} & \\ |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
164 |
\bl{$der\, c\, (r_1 + r_2)$} & \bl{$\dn$} & \bl{$der\, c\, r_1 + der\, c\, r_2$} & \\ |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
165 |
\bl{$der\, c\, (r_1 \cdot r_2)$} & \bl{$\dn$} & \bl{if $nullable (r_1)$}\\ |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
166 |
& & \bl{then $(der\,c\,r_1) \cdot r_2 + der\, c\, r_2$}\\ |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
167 |
& & \bl{else $(der\, c\, r_1) \cdot r_2$}\\ |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
168 |
\bl{$der\, c\, (r^*)$} & \bl{$\dn$} & \bl{$(der\,c\,r) \cdot (r^*)$} &\smallskip\\\pause |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
169 |
|
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
170 |
\bl{$der\!s\, []\, r$} & \bl{$\dn$} & \bl{$r$} & \\ |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
171 |
\bl{$der\!s\, (c\!::\!s)\, r$} & \bl{$\dn$} & \bl{$der\!s\,s\,(der\,c\,r)$} & \\ |
25 | 172 |
\end{tabular} |
173 |
\end{center} |
|
174 |
||
175 |
||
176 |
\end{frame}} |
|
177 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
178 |
||
179 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
180 |
\mode<presentation>{ |
|
181 |
\begin{frame}[c] |
|
182 |
||
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
183 |
|
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
184 |
To see what is going on, define |
25 | 185 |
|
186 |
\begin{center} |
|
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
187 |
\bl{$Der\,c\,A \dn \{ s \;|\; c\!::\!s \in A\}$ } |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
188 |
\end{center}\bigskip\bigskip |
25 | 189 |
|
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
190 |
\small |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
191 |
For \bl{$A = \{"f\!oo", "bar", "f\!rak"\}$} then |
25 | 192 |
|
193 |
\begin{center} |
|
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
194 |
\bl{\begin{tabular}{l@{\hspace{2mm}}c@{\hspace{2mm}}l} |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
195 |
$Der\,f\,A$ & $=$ & $\{"oo", "rak"\}$\\ |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
196 |
$Der\,b\,A$ & $=$ & $\{"ar"\}$\\ |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
197 |
$Der\,a\,A$ & $=$ & $\varnothing$\\ |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
198 |
\end{tabular}} |
25 | 199 |
\end{center} |
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
200 |
|
25 | 201 |
|
202 |
\end{frame}} |
|
203 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
204 |
||
205 |
||
206 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
207 |
\mode<presentation>{ |
|
208 |
\begin{frame}[c] |
|
209 |
\frametitle{\begin{tabular}{c}The Idea of the Algorithm\end{tabular}} |
|
210 |
||
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
211 |
If we want to recognise the string \bl{$"abc"$} with regular expression \bl{$r$} |
25 | 212 |
then\medskip |
213 |
||
214 |
\begin{enumerate} |
|
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
215 |
\item \bl{$Der\,a\,(L(r))$}\pause |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
216 |
\item \bl{$Der\,b\,(Der\,a\,(L(r)))$}\pause |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
217 |
\item \bl{$Der\,c\,(Der\,b\,(Der\,a\,(L(r))))$}\pause |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
218 |
\item finally we test whether the empty string is in this set\pause\medskip |
25 | 219 |
\end{enumerate} |
220 |
||
134
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
221 |
The matching algorithm works similarly, just over regular expression instead of sets. |
25 | 222 |
\end{frame}} |
223 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
224 |
||
225 |
||
226 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
227 |
\mode<presentation>{ |
|
228 |
\begin{frame}[c] |
|
229 |
||
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
230 |
Input: string \bl{$"abc"$} and regular expression \bl{$r$} |
25 | 231 |
|
232 |
\begin{enumerate} |
|
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
233 |
\item \bl{$der\,a\,r$} |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
234 |
\item \bl{$der\,b\,(der\,a\,r)$} |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
235 |
\item \bl{$der\,c\,(der\,b\,(der\,a\,r))$}\bigskip\pause |
134
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
236 |
\item finally check whether the last regular expression can match the empty string |
25 | 237 |
\end{enumerate} |
238 |
||
239 |
\end{frame}} |
|
240 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
241 |
||
242 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
243 |
\mode<presentation>{ |
|
244 |
\begin{frame}[c] |
|
245 |
||
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
246 |
We proved already |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
247 |
|
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
248 |
\begin{center} |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
249 |
\bl{$nullable(r)$} \;if and only if\; \bl{$"" \in L(r)$} |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
250 |
\end{center} |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
251 |
|
134
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
252 |
by induction on the regular expression.\bigskip\pause |
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
253 |
|
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
254 |
\begin{center} |
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
255 |
\huge\bf \alert{Any Questions?} |
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
256 |
\end{center} |
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
257 |
|
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
258 |
|
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
259 |
\end{frame}} |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
260 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
261 |
|
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
262 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
263 |
\mode<presentation>{ |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
264 |
\begin{frame}[c] |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
265 |
|
25 | 266 |
We need to prove |
267 |
||
268 |
\begin{center} |
|
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
269 |
\bl{$L(der\,c\,r) = Der\,c\,(L(r))$} |
25 | 270 |
\end{center} |
271 |
||
272 |
by induction on the regular expression. |
|
273 |
\end{frame}} |
|
274 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
275 |
||
276 |
||
277 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
278 |
\mode<presentation>{ |
|
279 |
\begin{frame}[c] |
|
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
280 |
\frametitle{\begin{tabular}{c}Proofs about Rexps\end{tabular}} |
25 | 281 |
|
282 |
\begin{itemize} |
|
283 |
\item \bl{$P$} holds for \bl{$\varnothing$}, \bl{$\epsilon$} and \bl{c}\bigskip |
|
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
284 |
\item \bl{$P$} holds for \bl{$r_1 + r_2$} under the assumption that \bl{$P$} already |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
285 |
holds for \bl{$r_1$} and \bl{$r_2$}.\bigskip |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
286 |
\item \bl{$P$} holds for \bl{$r_1 \cdot r_2$} under the assumption that \bl{$P$} already |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
287 |
holds for \bl{$r_1$} and \bl{$r_2$}.\bigskip |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
288 |
\item \bl{$P$} holds for \bl{$r^*$} under the assumption that \bl{$P$} already |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
289 |
holds for \bl{$r$}. |
25 | 290 |
\end{itemize} |
291 |
||
292 |
\end{frame}} |
|
293 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
294 |
||
295 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
296 |
\mode<presentation>{ |
|
297 |
\begin{frame}[c] |
|
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
298 |
\frametitle{\begin{tabular}{c}Proofs about Natural\\[-1mm] Numbers and Strings\end{tabular}} |
25 | 299 |
|
300 |
\begin{itemize} |
|
301 |
\item \bl{$P$} holds for \bl{$0$} and |
|
302 |
\item \bl{$P$} holds for \bl{$n + 1$} under the assumption that \bl{$P$} already |
|
303 |
holds for \bl{$n$} |
|
304 |
\end{itemize}\bigskip |
|
305 |
||
306 |
\begin{itemize} |
|
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
307 |
\item \bl{$P$} holds for \bl{$""$} and |
25 | 308 |
\item \bl{$P$} holds for \bl{$c\!::\!s$} under the assumption that \bl{$P$} already |
309 |
holds for \bl{$s$} |
|
310 |
\end{itemize} |
|
311 |
||
312 |
\end{frame}} |
|
313 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
314 |
||
315 |
||
316 |
||
317 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
318 |
\mode<presentation>{ |
|
319 |
\begin{frame}[c] |
|
320 |
\frametitle{\begin{tabular}{c}Languages\end{tabular}} |
|
321 |
||
322 |
A \alert{language} is a set of strings.\bigskip |
|
323 |
||
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
324 |
A \alert{regular expression} specifies a language.\bigskip |
25 | 325 |
|
326 |
A language is \alert{regular} iff there exists |
|
327 |
a regular expression that recognises all its strings.\bigskip\bigskip\pause |
|
328 |
||
134
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
329 |
\textcolor{gray}{not all languages are regular, e.g.~\bl{$a^nb^n$}.} |
25 | 330 |
\end{frame}} |
331 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
332 |
||
333 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
334 |
\mode<presentation>{ |
|
335 |
\begin{frame}[t] |
|
336 |
\frametitle{\begin{tabular}{c}Regular Expressions\end{tabular}} |
|
337 |
||
338 |
\begin{center} |
|
134
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
339 |
\begin{tabular}{@ {}rrl@ {\hspace{13mm}}l} |
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
340 |
\bl{$r$} & \bl{$::=$} & \bl{$\varnothing$} & null\\ |
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
341 |
& \bl{$\mid$} & \bl{$\epsilon$} & empty string / "" / $[]$\\ |
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
342 |
& \bl{$\mid$} & \bl{$c$} & character\\ |
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
343 |
& \bl{$\mid$} & \bl{$r_1 \cdot r_2$} & sequence\\ |
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
344 |
& \bl{$\mid$} & \bl{$r_1 + r_2$} & alternative / choice\\ |
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
345 |
& \bl{$\mid$} & \bl{$r^*$} & star (zero or more)\\ |
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
346 |
\end{tabular} |
25 | 347 |
\end{center} |
134
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
348 |
|
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
349 |
How about ranges \bl{$[a\mbox{-}z]$}, \bl{$r^+$} and \bl{$\sim{}r$}? Do they increase the |
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
350 |
set of languages we can recognise? |
25 | 351 |
|
352 |
\end{frame}} |
|
353 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
354 |
||
355 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
356 |
\mode<presentation>{ |
|
357 |
\begin{frame}[c] |
|
358 |
\frametitle{\begin{tabular}{c}Negation of Regular Expr's\end{tabular}} |
|
359 |
||
360 |
\begin{itemize} |
|
134
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
361 |
\item \bl{$\sim{}r$} \hspace{6mm} (everything that \bl{r} cannot recognise)\medskip |
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
362 |
\item \bl{$L(\sim{}r) \dn UNIV - L(r)$}\medskip |
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
363 |
\item \bl{$nullable (r) \dn not (nullable(r))$}\medskip |
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
364 |
\item \bl{$der\,c\,(\sim{}r) \dn \;\sim{}(der\,c\,r)$} |
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
365 |
\end{itemize}\bigskip\pause |
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
366 |
|
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
367 |
Used often for comments: |
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
368 |
|
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
369 |
\[ |
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
370 |
\bl{/ \cdot * \cdot (\sim{}([a\mbox{-}z]^* \cdot * \cdot / \cdot [a\mbox{-}z]^*)) \cdot * \cdot /} |
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
371 |
\] |
e3a8cf96f570
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
372 |
|
25 | 373 |
|
374 |
\end{frame}} |
|
375 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
376 |
||
377 |
||
378 |
||
379 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
380 |
\mode<presentation>{ |
|
381 |
\begin{frame}[c] |
|
382 |
\frametitle{\begin{tabular}{c}Regular Exp's for Lexing\end{tabular}} |
|
383 |
||
384 |
Lexing separates strings into ``words'' / components. |
|
385 |
||
386 |
\begin{itemize} |
|
387 |
\item Identifiers (non-empty strings of letters or digits, starting with a letter) |
|
388 |
\item Numbers (non-empty sequences of digits omitting leading zeros) |
|
389 |
\item Keywords (else, if, while, \ldots) |
|
390 |
\item White space (a non-empty sequence of blanks, newlines and tabs) |
|
391 |
\item Comments |
|
392 |
\end{itemize} |
|
393 |
||
394 |
\end{frame}} |
|
395 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
396 |
||
397 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
398 |
\mode<presentation>{ |
|
399 |
\begin{frame}[c] |
|
400 |
\frametitle{\begin{tabular}{c}Automata\end{tabular}} |
|
401 |
||
402 |
A deterministic finite automaton consists of: |
|
403 |
||
404 |
\begin{itemize} |
|
405 |
\item a set of states |
|
406 |
\item one of these states is the start state |
|
407 |
\item some states are accepting states, and |
|
408 |
\item there is transition function\medskip |
|
409 |
||
410 |
\small |
|
411 |
which takes a state as argument and a character and produces a new state\smallskip\\ |
|
412 |
this function might not always be defined |
|
413 |
\end{itemize} |
|
414 |
||
415 |
\end{frame}} |
|
416 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
133
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
417 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
418 |
\mode<presentation>{ |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
419 |
\begin{frame}[c] |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
420 |
\frametitle{\begin{tabular}{c}Automata\end{tabular}} |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
421 |
|
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
422 |
A deterministic finite automaton consists of: |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
423 |
|
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
424 |
\begin{itemize} |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
425 |
\item a set of states |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
426 |
\item one of these states is the start state |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
427 |
\item some states are accepting states, and |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
428 |
\item there is transition function\medskip |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
429 |
|
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
430 |
\small |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
431 |
which takes a state as argument and a character and produces a new state\smallskip\\ |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
432 |
this function might not always be defined |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
433 |
\end{itemize} |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
434 |
|
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
435 |
\end{frame}} |
09efdf5cf07c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
436 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
25 | 437 |
|
438 |
||
439 |
\end{document} |
|
440 |
||
441 |
%%% Local Variables: |
|
442 |
%%% mode: latex |
|
443 |
%%% TeX-master: t |
|
444 |
%%% End: |
|
445 |