author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Sat, 12 Oct 2013 23:39:20 +0100 | |
changeset 142 | 1aa28135a2da |
parent 139 | 6e7c3db9023d |
child 144 | 0cb61bed557d |
permissions | -rw-r--r-- |
33 | 1 |
\documentclass[dvipsnames,14pt,t]{beamer} |
142
1aa28135a2da
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
139
diff
changeset
|
2 |
\usepackage{beamerthemeplaincu} |
1aa28135a2da
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
139
diff
changeset
|
3 |
%%%\usepackage[T1]{fontenc} |
33 | 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 |
|
27 |
||
28 |
\lstset{language=Java, |
|
29 |
basicstyle=\ttfamily, |
|
30 |
keywordstyle=\color{javapurple}\bfseries, |
|
31 |
stringstyle=\color{javagreen}, |
|
32 |
commentstyle=\color{javagreen}, |
|
33 |
morecomment=[s][\color{javadocblue}]{/**}{*/}, |
|
34 |
numbers=left, |
|
35 |
numberstyle=\tiny\color{black}, |
|
36 |
stepnumber=1, |
|
37 |
numbersep=10pt, |
|
38 |
tabsize=2, |
|
39 |
showspaces=false, |
|
40 |
showstringspaces=false} |
|
41 |
||
42 |
\lstdefinelanguage{scala}{ |
|
43 |
morekeywords={abstract,case,catch,class,def,% |
|
44 |
do,else,extends,false,final,finally,% |
|
45 |
for,if,implicit,import,match,mixin,% |
|
46 |
new,null,object,override,package,% |
|
47 |
private,protected,requires,return,sealed,% |
|
48 |
super,this,throw,trait,true,try,% |
|
49 |
type,val,var,while,with,yield}, |
|
50 |
otherkeywords={=>,<-,<\%,<:,>:,\#,@}, |
|
51 |
sensitive=true, |
|
52 |
morecomment=[l]{//}, |
|
53 |
morecomment=[n]{/*}{*/}, |
|
54 |
morestring=[b]", |
|
55 |
morestring=[b]', |
|
56 |
morestring=[b]""" |
|
57 |
} |
|
58 |
||
59 |
\lstset{language=Scala, |
|
60 |
basicstyle=\ttfamily, |
|
61 |
keywordstyle=\color{javapurple}\bfseries, |
|
62 |
stringstyle=\color{javagreen}, |
|
63 |
commentstyle=\color{javagreen}, |
|
64 |
morecomment=[s][\color{javadocblue}]{/**}{*/}, |
|
65 |
numbers=left, |
|
66 |
numberstyle=\tiny\color{black}, |
|
67 |
stepnumber=1, |
|
68 |
numbersep=10pt, |
|
69 |
tabsize=2, |
|
70 |
showspaces=false, |
|
71 |
showstringspaces=false} |
|
72 |
||
73 |
% beamer stuff |
|
142
1aa28135a2da
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
139
diff
changeset
|
74 |
\renewcommand{\slidecaption}{AFL 04, King's College London, 16.~October 2013} |
33 | 75 |
\newcommand{\bl}[1]{\textcolor{blue}{#1}} |
76 |
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions |
|
77 |
||
78 |
\begin{document} |
|
79 |
||
80 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
81 |
\mode<presentation>{ |
|
82 |
\begin{frame}<1>[t] |
|
83 |
\frametitle{% |
|
84 |
\begin{tabular}{@ {}c@ {}} |
|
85 |
\\[-3mm] |
|
86 |
\LARGE Automata and \\[-2mm] |
|
87 |
\LARGE Formal Languages (4)\\[3mm] |
|
88 |
\end{tabular}} |
|
89 |
||
90 |
\normalsize |
|
91 |
\begin{center} |
|
92 |
\begin{tabular}{ll} |
|
93 |
Email: & christian.urban at kcl.ac.uk\\ |
|
142
1aa28135a2da
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
139
diff
changeset
|
94 |
Office: & S1.27 (1st floor Strand Building)\\ |
33 | 95 |
Slides: & KEATS (also home work is there)\\ |
96 |
\end{tabular} |
|
97 |
\end{center} |
|
98 |
||
99 |
||
100 |
\end{frame}} |
|
101 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
102 |
||
139
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
103 |
|
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
104 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
105 |
\mode<presentation>{ |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
106 |
\begin{frame}<1-2>[c] |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
107 |
|
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
108 |
\begin{center} |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
109 |
\begin{tikzpicture}[>=stealth',very thick,auto, |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
110 |
every state/.style={minimum size=0pt,inner sep=2pt,draw=blue!50,very thick,fill=blue!20},] |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
111 |
\node[state,initial] (q_0) {$q_0$}; |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
112 |
\node[state] (q_1) [right=of q_0] {$q_1$}; |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
113 |
\node[state] (q_2) [below right=of q_0] {$q_2$}; |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
114 |
\node[state] (q_3) [right=of q_2] {$q_3$}; |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
115 |
\node[state, accepting] (q_4) [right=of q_1] {$q_4$}; |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
116 |
\path[->] (q_0) edge node [above] {\alert{$a$}} (q_1); |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
117 |
\path[->] (q_1) edge node [above] {\alert{$a$}} (q_4); |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
118 |
\path[->] (q_4) edge [loop right] node {\alert{$a, b$}} (); |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
119 |
\path[->] (q_3) edge node [right] {\alert{$a$}} (q_4); |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
120 |
\path[->] (q_2) edge node [above] {\alert{$a$}} (q_3); |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
121 |
\path[->] (q_1) edge node [right] {\alert{$b$}} (q_2); |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
122 |
\path[->] (q_0) edge node [above] {\alert{$b$}} (q_2); |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
123 |
\path[->] (q_2) edge [loop left] node {\alert{$b$}} (); |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
124 |
\path[->] (q_3) edge [bend left=95, looseness=1.3] node [below] {\alert{$b$}} (q_0); |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
125 |
\end{tikzpicture} |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
126 |
\end{center} |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
127 |
|
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
128 |
\mbox{}\\[-20mm]\mbox{} |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
129 |
|
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
130 |
\begin{center} |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
131 |
\begin{tikzpicture}[>=stealth',very thick,auto, |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
132 |
every state/.style={minimum size=0pt,inner sep=2pt,draw=blue!50,very thick,fill=blue!20},] |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
133 |
\node[state,initial] (q_02) {$q_{0, 2}$}; |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
134 |
\node[state] (q_13) [right=of q_02] {$q_{1, 3}$}; |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
135 |
\node[state, accepting] (q_4) [right=of q_13] {$q_{4\phantom{,0}}$}; |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
136 |
\path[->] (q_02) edge [bend left] node [above] {\alert{$a$}} (q_13); |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
137 |
\path[->] (q_13) edge [bend left] node [below] {\alert{$b$}} (q_02); |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
138 |
\path[->] (q_02) edge [loop below] node {\alert{$b$}} (); |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
139 |
\path[->] (q_13) edge node [above] {\alert{$a$}} (q_4); |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
140 |
\path[->] (q_4) edge [loop above] node {\alert{$a, b$}} (); |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
141 |
\end{tikzpicture}\\ |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
142 |
minimal automaton |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
143 |
\end{center} |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
144 |
|
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
145 |
\end{frame}} |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
146 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
147 |
|
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
148 |
|
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
149 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
150 |
\mode<presentation>{ |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
151 |
\begin{frame}[c] |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
152 |
|
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
153 |
\begin{enumerate} |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
154 |
\item Take all pairs \bl{(q, p)} with \bl{q $\not=$ p} |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
155 |
\item Mark all pairs that are accepting and non-accepting states |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
156 |
\item For all unmarked pairs \bl{(q, p)} and all characters \bl{c} tests wether |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
157 |
\begin{center} |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
158 |
\bl{($\delta$(q,c), $\delta$(p,c))} |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
159 |
\end{center} |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
160 |
are marked. If yes, then also mark \bl{(q, p)} |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
161 |
\item Repeat last step until no chance. |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
162 |
\item All unmarked pairs can be merged. |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
163 |
\end{enumerate} |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
164 |
|
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
165 |
\end{frame}} |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
166 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
167 |
|
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
168 |
|
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
169 |
|
6e7c3db9023d
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
170 |
|
33 | 171 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
172 |
\mode<presentation>{ |
|
173 |
\begin{frame}[c] |
|
174 |
\frametitle{\begin{tabular}{c}Last Week\end{tabular}} |
|
175 |
||
35 | 176 |
Last week I showed you\bigskip |
33 | 177 |
|
178 |
\begin{itemize} |
|
35 | 179 |
\item a tokenizer taking a list of regular expressions\bigskip |
33 | 180 |
|
181 |
\item tokenization identifies lexeme in an input stream of characters (or string) |
|
35 | 182 |
and cathegorizes them into tokens |
183 |
||
184 |
\end{itemize} |
|
185 |
||
186 |
\end{frame}} |
|
187 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
33 | 188 |
|
35 | 189 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
190 |
\mode<presentation>{ |
|
191 |
\begin{frame}[c] |
|
192 |
\frametitle{\begin{tabular}{c}Two Rules\end{tabular}} |
|
193 |
||
194 |
\begin{itemize} |
|
195 |
\item Longest match rule (maximal munch rule): The |
|
34 | 196 |
longest initial substring matched by any regular expression is taken |
35 | 197 |
as next token.\bigskip |
34 | 198 |
|
199 |
\item Rule priority: |
|
200 |
For a particular longest initial substring, the first regular |
|
201 |
expression that can match determines the token. |
|
202 |
||
33 | 203 |
\end{itemize} |
204 |
||
35 | 205 |
%\url{http://www.technologyreview.com/tr10/?year=2011} |
33 | 206 |
|
35 | 207 |
%finite deterministic automata/ nondeterministic automaton |
34 | 208 |
|
35 | 209 |
%\item problem with infix operations, for example i-12 |
34 | 210 |
|
211 |
||
33 | 212 |
\end{frame}} |
213 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
36 | 214 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
215 |
||
216 |
\mode<presentation>{ |
|
217 |
\begin{frame}[t] |
|
218 |
||
219 |
\begin{center} |
|
220 |
\texttt{"if true then then 42 else +"} |
|
221 |
\end{center} |
|
222 |
||
223 |
||
224 |
\begin{tabular}{@{}l} |
|
225 |
KEYWORD: \\ |
|
226 |
\hspace{5mm}\texttt{"if"}, \texttt{"then"}, \texttt{"else"},\\ |
|
227 |
WHITESPACE:\\ |
|
228 |
\hspace{5mm}\texttt{" "}, \texttt{"$\backslash$n"},\\ |
|
229 |
IDENT:\\ |
|
230 |
\hspace{5mm}LETTER $\cdot$ (LETTER + DIGIT + \texttt{"\_"})$^*$\\ |
|
231 |
NUM:\\ |
|
232 |
\hspace{5mm}(NONZERODIGIT $\cdot$ DIGIT$^*$) + \texttt{"0"}\\ |
|
233 |
OP:\\ |
|
234 |
\hspace{5mm}\texttt{"+"}\\ |
|
235 |
COMMENT:\\ |
|
236 |
\hspace{5mm}\texttt{"$\slash$*"} $\cdot$ (ALL$^*$ $\cdot$ \texttt{"*$\slash$"} $\cdot$ ALL$^*$) $\cdot$ \texttt{"*$\slash$"} |
|
237 |
\end{tabular} |
|
238 |
||
239 |
\end{frame}} |
|
240 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
33 | 241 |
|
242 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
243 |
\mode<presentation>{ |
|
35 | 244 |
\begin{frame}[t] |
33 | 245 |
|
246 |
\begin{center} |
|
35 | 247 |
\texttt{"if true then then 42 else +"} |
33 | 248 |
\end{center} |
249 |
||
35 | 250 |
\only<1>{ |
251 |
\small\begin{tabular}{l} |
|
252 |
KEYWORD(if),\\ |
|
253 |
WHITESPACE,\\ |
|
254 |
IDENT(true),\\ |
|
255 |
WHITESPACE,\\ |
|
256 |
KEYWORD(then),\\ |
|
257 |
WHITESPACE,\\ |
|
258 |
KEYWORD(then),\\ |
|
259 |
WHITESPACE,\\ |
|
260 |
NUM(42),\\ |
|
261 |
WHITESPACE,\\ |
|
262 |
KEYWORD(else),\\ |
|
263 |
WHITESPACE,\\ |
|
264 |
OP(+) |
|
265 |
\end{tabular}} |
|
266 |
||
267 |
\only<2>{ |
|
268 |
\small\begin{tabular}{l} |
|
269 |
KEYWORD(if),\\ |
|
270 |
IDENT(true),\\ |
|
271 |
KEYWORD(then),\\ |
|
272 |
KEYWORD(then),\\ |
|
273 |
NUM(42),\\ |
|
274 |
KEYWORD(else),\\ |
|
275 |
OP(+) |
|
276 |
\end{tabular}} |
|
33 | 277 |
|
278 |
\end{frame}} |
|
279 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
280 |
||
281 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
282 |
\mode<presentation>{ |
|
283 |
\begin{frame}[c] |
|
284 |
||
285 |
||
35 | 286 |
There is one small problem with the tokenizer. How should we |
287 |
tokenize: |
|
33 | 288 |
|
289 |
\begin{center} |
|
35 | 290 |
\texttt{"x - 3"} |
33 | 291 |
\end{center} |
292 |
||
36 | 293 |
\begin{tabular}{@{}l} |
294 |
OP:\\ |
|
295 |
\hspace{5mm}\texttt{"+"}, \texttt{"-"}\\ |
|
296 |
NUM:\\ |
|
297 |
\hspace{5mm}(NONZERODIGIT $\cdot$ DIGIT$^*$) + \texttt{"0"}\\ |
|
298 |
NUMBER:\\ |
|
299 |
\hspace{5mm}NUM + (\texttt{"-"} $\cdot$ NUM)\\ |
|
300 |
\end{tabular} |
|
301 |
||
302 |
||
33 | 303 |
\end{frame}} |
304 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
305 |
||
38 | 306 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
307 |
\mode<presentation>{ |
|
308 |
\begin{frame}[c] |
|
309 |
\frametitle{\begin{tabular}{c}Negation\end{tabular}} |
|
310 |
||
311 |
Assume you have an alphabet consisting of the letters \bl{a}, \bl{b} and \bl{c} only. |
|
312 |
Find a regular expression that matches all strings \emph{except} \bl{ab}, \bl{ac} and \bl{cba}. |
|
313 |
||
314 |
\end{frame}} |
|
315 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
316 |
||
317 |
||
33 | 318 |
|
319 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
320 |
\mode<presentation>{ |
|
321 |
\begin{frame}[c] |
|
36 | 322 |
\frametitle{\begin{tabular}{c}Deterministic Finite Automata\end{tabular}} |
35 | 323 |
|
324 |
A deterministic finite automaton consists of: |
|
325 |
||
326 |
\begin{itemize} |
|
327 |
\item a finite set of states |
|
328 |
\item one of these states is the start state |
|
329 |
\item some states are accepting states, and |
|
330 |
\item there is transition function\medskip |
|
331 |
||
332 |
\small |
|
333 |
which takes a state and a character as arguments and produces a new state\smallskip\\ |
|
334 |
this function might not always be defined everywhere |
|
335 |
\end{itemize} |
|
336 |
||
337 |
\begin{center} |
|
338 |
\bl{$A(Q, q_0, F, \delta)$} |
|
339 |
\end{center} |
|
340 |
\end{frame}} |
|
341 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
342 |
||
343 |
||
344 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
345 |
\mode<presentation>{ |
|
346 |
\begin{frame}[c] |
|
347 |
||
348 |
\begin{center} |
|
349 |
\includegraphics[scale=0.7]{pics/ch3.jpg} |
|
36 | 350 |
\end{center}\pause |
351 |
||
352 |
\begin{itemize} |
|
353 |
\item start can be an accepting state |
|
39 | 354 |
\item it is possible that there is no accepting state |
355 |
\item all states might be accepting (but does not necessarily mean all strings are accepted) |
|
36 | 356 |
\end{itemize} |
357 |
||
358 |
\end{frame}} |
|
359 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
360 |
||
361 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
362 |
\mode<presentation>{ |
|
363 |
\begin{frame}[c] |
|
364 |
||
365 |
\begin{center} |
|
366 |
\includegraphics[scale=0.7]{pics/ch3.jpg} |
|
367 |
\end{center} |
|
368 |
||
369 |
for this automaton \bl{$\delta$} is the function\\ |
|
370 |
||
371 |
\begin{center} |
|
372 |
\begin{tabular}{lll} |
|
373 |
\bl{(q$_0$, a) $\rightarrow$ q$_1$} & \bl{(q$_1$, a) $\rightarrow$ q$_4$} & \bl{(q$_4$, a) $\rightarrow$ q$_4$}\\ |
|
374 |
\bl{(q$_0$, b) $\rightarrow$ q$_2$} & \bl{(q$_1$, b) $\rightarrow$ q$_2$} & \bl{(q$_4$, b) $\rightarrow$ q$_4$}\\ |
|
375 |
\end{tabular}\ldots |
|
376 |
\end{center} |
|
377 |
||
378 |
\end{frame}} |
|
379 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
380 |
||
381 |
||
382 |
||
383 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
384 |
\mode<presentation>{ |
|
385 |
\begin{frame}[t] |
|
386 |
\frametitle{\begin{tabular}{c}Accepting a String\end{tabular}} |
|
387 |
||
388 |
Given |
|
389 |
||
390 |
\begin{center} |
|
391 |
\bl{$A(Q, q_0, F, \delta)$} |
|
392 |
\end{center} |
|
393 |
||
394 |
you can define |
|
395 |
||
396 |
\begin{center} |
|
397 |
\begin{tabular}{l} |
|
398 |
\bl{$\hat{\delta}(q, \texttt{""}) = q$}\\ |
|
399 |
\bl{$\hat{\delta}(q, c::s) = \hat{\delta}(\delta(q, c), s)$}\\ |
|
400 |
\end{tabular} |
|
401 |
\end{center}\pause |
|
402 |
||
403 |
Whether a string \bl{$s$} is accepted by \bl{$A$}? |
|
404 |
||
405 |
\begin{center} |
|
406 |
\hspace{5mm}\bl{$\hat{\delta}(q_0, s) \in F$} |
|
407 |
\end{center} |
|
408 |
\end{frame}} |
|
409 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
410 |
||
411 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
412 |
\mode<presentation>{ |
|
413 |
\begin{frame}[c] |
|
414 |
\frametitle{\begin{tabular}{c}Non-Deterministic\\[-1mm] Finite Automata\end{tabular}} |
|
415 |
||
416 |
A non-deterministic finite automaton consists again of: |
|
417 |
||
418 |
\begin{itemize} |
|
419 |
\item a finite set of states |
|
420 |
\item one of these states is the start state |
|
421 |
\item some states are accepting states, and |
|
422 |
\item there is transition \alert{relation}\medskip |
|
423 |
\end{itemize} |
|
424 |
||
425 |
||
426 |
\begin{center} |
|
427 |
\begin{tabular}{c} |
|
428 |
\bl{(q$_1$, a) $\rightarrow$ q$_2$}\\ |
|
429 |
\bl{(q$_1$, a) $\rightarrow$ q$_3$}\\ |
|
430 |
\end{tabular} |
|
431 |
\hspace{10mm} |
|
432 |
\begin{tabular}{c} |
|
433 |
\bl{(q$_1$, $\epsilon$) $\rightarrow$ q$_2$}\\ |
|
434 |
\end{tabular} |
|
35 | 435 |
\end{center} |
436 |
||
437 |
\end{frame}} |
|
438 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
33 | 439 |
|
35 | 440 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
441 |
\mode<presentation>{ |
|
36 | 442 |
\begin{frame}[c] |
443 |
||
444 |
\begin{center} |
|
445 |
\includegraphics[scale=0.7]{pics/ch5.jpg} |
|
446 |
\end{center} |
|
447 |
||
37 | 448 |
|
36 | 449 |
\end{frame}} |
450 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
451 |
||
452 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
453 |
\mode<presentation>{ |
|
454 |
\begin{frame}[c] |
|
35 | 455 |
|
456 |
\begin{center} |
|
36 | 457 |
\begin{tabular}[b]{ll} |
458 |
\bl{$\varnothing$} & \includegraphics[scale=0.7]{pics/NULL.jpg}\\\\ |
|
459 |
\bl{$\epsilon$} & \includegraphics[scale=0.7]{pics/epsilon.jpg}\\\\ |
|
460 |
\bl{c} & \includegraphics[scale=0.7]{pics/char.jpg}\\ |
|
461 |
\end{tabular} |
|
462 |
\end{center} |
|
463 |
||
464 |
\end{frame}} |
|
465 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
466 |
||
467 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
468 |
\mode<presentation>{ |
|
469 |
\begin{frame}[c] |
|
35 | 470 |
|
471 |
\begin{center} |
|
36 | 472 |
\begin{tabular}[t]{ll} |
473 |
\bl{r$_1$ $\cdot$ r$_2$} & \includegraphics[scale=0.6]{pics/seq.jpg}\\\\ |
|
35 | 474 |
\end{tabular} |
36 | 475 |
\end{center} |
476 |
||
477 |
\end{frame}} |
|
478 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
479 |
||
480 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
481 |
\mode<presentation>{ |
|
482 |
\begin{frame}[c] |
|
33 | 483 |
|
35 | 484 |
\begin{center} |
36 | 485 |
\begin{tabular}[t]{ll} |
486 |
\bl{r$_1$ + r$_2$} & \includegraphics[scale=0.7]{pics/alt.jpg}\\\\ |
|
487 |
\end{tabular} |
|
35 | 488 |
\end{center} |
36 | 489 |
|
35 | 490 |
\end{frame}} |
491 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
492 |
||
493 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
494 |
\mode<presentation>{ |
|
495 |
\begin{frame}[c] |
|
496 |
||
497 |
\begin{center} |
|
36 | 498 |
\begin{tabular}[b]{ll} |
499 |
\bl{r$^*$} & \includegraphics[scale=0.7]{pics/star.jpg}\\ |
|
500 |
\end{tabular} |
|
38 | 501 |
\end{center}\pause\bigskip |
502 |
||
503 |
Why can't we just have an epsilon transition from the accepting states to the starting state? |
|
36 | 504 |
|
505 |
\end{frame}} |
|
506 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
507 |
||
508 |
||
509 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
510 |
\mode<presentation>{ |
|
511 |
\begin{frame}[c] |
|
38 | 512 |
\frametitle{\begin{tabular}{c}Subset Construction\end{tabular}} |
36 | 513 |
|
38 | 514 |
|
515 |
\begin{textblock}{5}(1,2.5) |
|
36 | 516 |
\includegraphics[scale=0.5]{pics/ch5.jpg} |
37 | 517 |
\end{textblock} |
518 |
||
38 | 519 |
\begin{textblock}{11}(6.5,4.5) |
37 | 520 |
\begin{tabular}{r|cl} |
521 |
& a & b\\ |
|
522 |
\hline |
|
523 |
$\varnothing$ \onslide<2>{\textcolor{white}{*}} & $\varnothing$ & $\varnothing$\\ |
|
524 |
$\{0\}$ \onslide<2>{\textcolor{white}{*}} & $\{0,1,2\}$ & $\{2\}$\\ |
|
525 |
$\{1\}$ \onslide<2>{\textcolor{white}{*}} &$\{1\}$ & $\varnothing$\\ |
|
526 |
$\{2\}$ \onslide<2>{*} & $\varnothing$ &$\{2\}$\\ |
|
527 |
$\{0,1\}$ \onslide<2>{\textcolor{white}{*}} &$\{0,1,2\}$ &$\{2\}$\\ |
|
528 |
$\{0,2\}$ \onslide<2>{*}&$\{0,1,2\}$ &$\{2\}$\\ |
|
529 |
$\{1,2\}$ \onslide<2>{*}& $\{1\}$ & $\{2\}$\\ |
|
530 |
\onslide<2>{s:} $\{0,1,2\}$ \onslide<2>{*}&$\{0,1,2\}$ &$\{2\}$\\ |
|
531 |
\end{tabular} |
|
532 |
\end{textblock} |
|
533 |
||
36 | 534 |
|
535 |
\end{frame}} |
|
536 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
537 |
||
538 |
||
38 | 539 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
540 |
\mode<presentation>{ |
|
541 |
\begin{frame}[c] |
|
542 |
\frametitle{\begin{tabular}{c}Regular Languages\end{tabular}} |
|
543 |
||
544 |
A language is \alert{regular} iff there exists |
|
545 |
a regular expression that recognises all its strings.\bigskip\medskip |
|
546 |
||
547 |
or equivalently\bigskip\medskip |
|
548 |
||
549 |
A language is \alert{regular} iff there exists |
|
550 |
a deterministic finite automaton that recognises all its strings.\bigskip\pause |
|
551 |
||
552 |
Why is every finite set of strings a regular language? |
|
553 |
\end{frame}} |
|
554 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
555 |
||
36 | 556 |
|
557 |
||
558 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
559 |
\mode<presentation>{ |
|
560 |
\begin{frame}[c] |
|
561 |
||
562 |
\begin{center} |
|
38 | 563 |
\includegraphics[scale=0.5]{pics/ch3.jpg} |
564 |
\end{center} |
|
565 |
||
566 |
\begin{center} |
|
567 |
\includegraphics[scale=0.5]{pics/ch4.jpg}\\ |
|
568 |
minimal automaton |
|
35 | 569 |
\end{center} |
570 |
||
571 |
\end{frame}} |
|
572 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
573 |
||
39 | 574 |
|
575 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
576 |
\mode<presentation>{ |
|
577 |
\begin{frame}[c] |
|
578 |
||
579 |
\begin{enumerate} |
|
580 |
\item Take all pairs \bl{(q, p)} with \bl{q $\not=$ p} |
|
581 |
\item Mark all pairs that accepting and non-accepting states |
|
582 |
\item For all unmarked pairs \bl{(q, p)} and all characters \bl{c} tests wether |
|
583 |
\begin{center} |
|
584 |
\bl{($\delta$(q,c), $\delta$(p,c))} |
|
585 |
\end{center} |
|
41 | 586 |
are marked. If yes, then also mark \bl{(q, p)} |
39 | 587 |
\item Repeat last step until no chance. |
588 |
\item All unmarked pairs can be merged. |
|
589 |
\end{enumerate} |
|
590 |
||
591 |
\end{frame}} |
|
592 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
593 |
||
594 |
||
595 |
||
38 | 596 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
597 |
\mode<presentation>{ |
|
598 |
\begin{frame}[c] |
|
599 |
||
600 |
Given the function |
|
601 |
||
602 |
\begin{center} |
|
603 |
\bl{\begin{tabular}{r@{\hspace{1mm}}c@{\hspace{1mm}}l} |
|
604 |
$rev(\varnothing)$ & $\dn$ & $\varnothing$\\ |
|
605 |
$rev(\epsilon)$ & $\dn$ & $\epsilon$\\ |
|
606 |
$rev(c)$ & $\dn$ & $c$\\ |
|
607 |
$rev(r_1 + r_2)$ & $\dn$ & $rev(r_1) + rev(r_2)$\\ |
|
608 |
$rev(r_1 \cdot r_2)$ & $\dn$ & $rev(r_2) \cdot rev(r_1)$\\ |
|
609 |
$rev(r^*)$ & $\dn$ & $rev(r)^*$\\ |
|
610 |
\end{tabular}} |
|
611 |
\end{center} |
|
612 |
||
613 |
||
614 |
and the set |
|
615 |
||
616 |
\begin{center} |
|
617 |
\bl{$Rev\,A \dn \{s^{-1} \;|\; s \in A\}$} |
|
618 |
\end{center} |
|
619 |
||
620 |
prove whether |
|
621 |
||
622 |
\begin{center} |
|
623 |
\bl{$L(rev(r)) = Rev (L(r))$} |
|
624 |
\end{center} |
|
625 |
||
626 |
\end{frame}} |
|
627 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
35 | 628 |
|
629 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
630 |
\mode<presentation>{ |
|
631 |
\begin{frame}[c] |
|
33 | 632 |
|
38 | 633 |
\begin{itemize} |
634 |
\item The star-case in our proof about the matcher needs the following lemma |
|
635 |
\begin{center} |
|
636 |
\bl{Der\,c\,A$^*$ $=$ (Der c A)\,@\, A$^*$} |
|
637 |
\end{center} |
|
638 |
\end{itemize}\bigskip\bigskip |
|
33 | 639 |
|
38 | 640 |
\begin{itemize} |
641 |
\item If \bl{\texttt{""} $\in$ A}, then\\ \bl{Der\,c\,(A @ B) $=$ (Der\,c\,A) @ B $\cup$ (Der\,c\,B)}\medskip |
|
642 |
\item If \bl{\texttt{""} $\not\in$ A}, then\\ \bl{Der\,c\,(A @ B) $=$ (Der\,c\,A) @ B} |
|
643 |
||
644 |
\end{itemize} |
|
645 |
||
33 | 646 |
\end{frame}} |
647 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
648 |
||
649 |
||
650 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
651 |
\mode<presentation>{ |
|
652 |
\begin{frame}[c] |
|
653 |
||
654 |
\begin{itemize} |
|
35 | 655 |
\item Assuming you have the alphabet \bl{\{a, b, c\}}\bigskip |
656 |
\item Give a regular expression that can recognise all strings that have at least one \bl{b}. |
|
33 | 657 |
\end{itemize} |
658 |
||
659 |
\end{frame}} |
|
660 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
661 |
||
662 |
||
40 | 663 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
664 |
\mode<presentation>{ |
|
665 |
\begin{frame}[c] |
|
666 |
||
667 |
``I hate coding. I do not want to look at code.'' |
|
668 |
||
669 |
\end{frame}} |
|
670 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
671 |
||
33 | 672 |
|
673 |
||
674 |
\end{document} |
|
675 |
||
676 |
%%% Local Variables: |
|
677 |
%%% mode: latex |
|
678 |
%%% TeX-master: t |
|
679 |
%%% End: |
|
680 |