49
|
1 |
\documentclass[dvipsnames,14pt,t]{beamer}
|
|
2 |
\usepackage{beamerthemeplainculight}
|
|
3 |
\usepackage[T1]{fontenc}
|
|
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 |
\usetikzlibrary{plotmarks}
|
|
22 |
\usepackage{graphicx}
|
|
23 |
|
|
24 |
\definecolor{javared}{rgb}{0.6,0,0} % for strings
|
|
25 |
\definecolor{javagreen}{rgb}{0.25,0.5,0.35} % comments
|
|
26 |
\definecolor{javapurple}{rgb}{0.5,0,0.35} % keywords
|
|
27 |
\definecolor{javadocblue}{rgb}{0.25,0.35,0.75} % javadoc
|
|
28 |
|
|
29 |
\lstset{language=Java,
|
|
30 |
basicstyle=\ttfamily,
|
|
31 |
keywordstyle=\color{javapurple}\bfseries,
|
|
32 |
stringstyle=\color{javagreen},
|
|
33 |
commentstyle=\color{javagreen},
|
|
34 |
morecomment=[s][\color{javadocblue}]{/**}{*/},
|
|
35 |
numbers=left,
|
|
36 |
numberstyle=\tiny\color{black},
|
|
37 |
stepnumber=1,
|
|
38 |
numbersep=10pt,
|
|
39 |
tabsize=2,
|
|
40 |
showspaces=false,
|
|
41 |
showstringspaces=false}
|
|
42 |
|
|
43 |
\lstdefinelanguage{scala}{
|
|
44 |
morekeywords={abstract,case,catch,class,def,%
|
|
45 |
do,else,extends,false,final,finally,%
|
|
46 |
for,if,implicit,import,match,mixin,%
|
|
47 |
new,null,object,override,package,%
|
|
48 |
private,protected,requires,return,sealed,%
|
|
49 |
super,this,throw,trait,true,try,%
|
|
50 |
type,val,var,while,with,yield},
|
|
51 |
otherkeywords={=>,<-,<\%,<:,>:,\#,@},
|
|
52 |
sensitive=true,
|
|
53 |
morecomment=[l]{//},
|
|
54 |
morecomment=[n]{/*}{*/},
|
|
55 |
morestring=[b]",
|
|
56 |
morestring=[b]',
|
|
57 |
morestring=[b]"""
|
|
58 |
}
|
|
59 |
|
|
60 |
\lstset{language=Scala,
|
|
61 |
basicstyle=\ttfamily,
|
|
62 |
keywordstyle=\color{javapurple}\bfseries,
|
|
63 |
stringstyle=\color{javagreen},
|
|
64 |
commentstyle=\color{javagreen},
|
|
65 |
morecomment=[s][\color{javadocblue}]{/**}{*/},
|
|
66 |
numbers=left,
|
|
67 |
numberstyle=\tiny\color{black},
|
|
68 |
stepnumber=1,
|
|
69 |
numbersep=10pt,
|
|
70 |
tabsize=2,
|
|
71 |
showspaces=false,
|
|
72 |
showstringspaces=false}
|
|
73 |
|
|
74 |
% beamer stuff
|
|
75 |
\renewcommand{\slidecaption}{AFL 06, King's College London, 31.~October 2012}
|
|
76 |
\newcommand{\bl}[1]{\textcolor{blue}{#1}}
|
|
77 |
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions
|
|
78 |
|
|
79 |
|
|
80 |
% The data files, written on the first run.
|
|
81 |
\begin{filecontents}{re-python.data}
|
|
82 |
1 0.029
|
|
83 |
5 0.029
|
|
84 |
10 0.029
|
|
85 |
15 0.032
|
|
86 |
16 0.042
|
|
87 |
17 0.042
|
|
88 |
18 0.055
|
|
89 |
19 0.084
|
|
90 |
20 0.136
|
|
91 |
21 0.248
|
|
92 |
22 0.464
|
|
93 |
23 0.899
|
|
94 |
24 1.773
|
|
95 |
25 3.505
|
|
96 |
26 6.993
|
|
97 |
27 14.503
|
|
98 |
28 29.307
|
|
99 |
#29 58.886
|
|
100 |
\end{filecontents}
|
|
101 |
|
|
102 |
\begin{filecontents}{re1.data}
|
|
103 |
1 0.00179
|
|
104 |
2 0.00011
|
|
105 |
3 0.00014
|
|
106 |
4 0.00026
|
|
107 |
5 0.00050
|
|
108 |
6 0.00095
|
|
109 |
7 0.00190
|
|
110 |
8 0.00287
|
|
111 |
9 0.00779
|
|
112 |
10 0.01399
|
|
113 |
11 0.01894
|
|
114 |
12 0.03666
|
|
115 |
13 0.07994
|
|
116 |
14 0.08944
|
|
117 |
15 0.02377
|
|
118 |
16 0.07392
|
|
119 |
17 0.22798
|
|
120 |
18 0.65310
|
|
121 |
19 2.11360
|
|
122 |
20 6.31606
|
|
123 |
21 21.46013
|
|
124 |
\end{filecontents}
|
|
125 |
|
|
126 |
\begin{filecontents}{re2.data}
|
|
127 |
1 0.00240
|
|
128 |
2 0.00013
|
|
129 |
3 0.00020
|
|
130 |
4 0.00030
|
|
131 |
5 0.00049
|
|
132 |
6 0.00083
|
|
133 |
7 0.00146
|
|
134 |
8 0.00228
|
|
135 |
9 0.00351
|
|
136 |
10 0.00640
|
|
137 |
11 0.01217
|
|
138 |
12 0.02565
|
|
139 |
13 0.01382
|
|
140 |
14 0.02423
|
|
141 |
15 0.05065
|
|
142 |
16 0.06522
|
|
143 |
17 0.02140
|
|
144 |
18 0.05176
|
|
145 |
19 0.18254
|
|
146 |
20 0.51898
|
|
147 |
21 1.39631
|
|
148 |
22 2.69501
|
|
149 |
23 8.07952
|
|
150 |
\end{filecontents}
|
|
151 |
|
|
152 |
\begin{filecontents}{re-internal.data}
|
|
153 |
1 0.00069
|
|
154 |
301 0.00700
|
|
155 |
601 0.00297
|
|
156 |
901 0.00470
|
|
157 |
1201 0.01301
|
|
158 |
1501 0.01175
|
|
159 |
1801 0.01761
|
|
160 |
2101 0.01787
|
|
161 |
2401 0.02717
|
|
162 |
2701 0.03932
|
|
163 |
3001 0.03470
|
|
164 |
3301 0.04349
|
|
165 |
3601 0.05411
|
|
166 |
3901 0.06181
|
|
167 |
4201 0.07119
|
|
168 |
4501 0.08578
|
|
169 |
\end{filecontents}
|
|
170 |
|
|
171 |
\begin{filecontents}{re3.data}
|
|
172 |
1 0.001605
|
|
173 |
501 0.131066
|
|
174 |
1001 0.057885
|
|
175 |
1501 0.136875
|
|
176 |
2001 0.176238
|
|
177 |
2501 0.254363
|
|
178 |
3001 0.37262
|
|
179 |
3501 0.500946
|
|
180 |
4001 0.638384
|
|
181 |
4501 0.816605
|
|
182 |
5001 1.00491
|
|
183 |
5501 1.232505
|
|
184 |
6001 1.525672
|
|
185 |
6501 1.757502
|
|
186 |
7001 2.092784
|
|
187 |
7501 2.429224
|
|
188 |
8001 2.803037
|
|
189 |
8501 3.463045
|
|
190 |
9001 3.609
|
|
191 |
9501 4.081504
|
|
192 |
10001 4.54569
|
|
193 |
\end{filecontents}
|
|
194 |
\begin{document}
|
|
195 |
|
|
196 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
197 |
\mode<presentation>{
|
|
198 |
\begin{frame}<1>[t]
|
|
199 |
\frametitle{%
|
|
200 |
\begin{tabular}{@ {}c@ {}}
|
|
201 |
\\[-3mm]
|
|
202 |
\LARGE Automata and \\[-2mm]
|
|
203 |
\LARGE Formal Languages (6)\\[3mm]
|
|
204 |
\end{tabular}}
|
|
205 |
|
|
206 |
\normalsize
|
|
207 |
\begin{center}
|
|
208 |
\begin{tabular}{ll}
|
|
209 |
Email: & christian.urban at kcl.ac.uk\\
|
|
210 |
Of$\!$fice: & S1.27 (1st floor Strand Building)\\
|
|
211 |
Slides: & KEATS (also home work is there)\\
|
|
212 |
\end{tabular}
|
|
213 |
\end{center}
|
|
214 |
|
|
215 |
|
|
216 |
\end{frame}}
|
|
217 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
218 |
|
|
219 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
220 |
\mode<presentation>{
|
|
221 |
\begin{frame}[c]
|
50
|
222 |
|
|
223 |
``I hate coding. I do not want to look at code.''
|
|
224 |
|
|
225 |
\end{frame}}
|
|
226 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
227 |
|
|
228 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
229 |
\mode<presentation>{
|
|
230 |
\begin{frame}[c]
|
|
231 |
|
|
232 |
``I am appalled. You do not show code anymore.''
|
|
233 |
|
|
234 |
\end{frame}}
|
|
235 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
236 |
|
|
237 |
|
|
238 |
|
|
239 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
240 |
\mode<presentation>{
|
|
241 |
\begin{frame}[c]
|
49
|
242 |
\frametitle{\begin{tabular}{c}ReDoS\end{tabular}}
|
|
243 |
|
|
244 |
\begin{itemize}
|
|
245 |
\item \alert{R}egular \alert{e}xpression \alert{D}enial \alert{o}f \alert{S}ervice\bigskip
|
|
246 |
\item ``Regular Expressions Will Stab You in the Back''\bigskip
|
|
247 |
\item Evil regular expressions\medskip
|
|
248 |
\begin{itemize}
|
|
249 |
\item \bl{$(a?\{n\})a\{n\}$}
|
|
250 |
\item \bl{$(a^+)^+$}
|
|
251 |
\item \bl{$([a-zA-Z]^+)^*$}
|
|
252 |
\item \bl{$(a + aa)^+$}
|
|
253 |
\item \bl{$(a + a?)^+$}
|
|
254 |
\end{itemize}
|
|
255 |
\end{itemize}
|
|
256 |
|
|
257 |
\end{frame}}
|
|
258 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
259 |
|
|
260 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
261 |
\mode<presentation>{
|
|
262 |
\begin{frame}[c]
|
|
263 |
\frametitle{\begin{tabular}{c}Regexp Matching\end{tabular}}
|
|
264 |
|
|
265 |
Given a regular expression
|
|
266 |
|
|
267 |
\begin{enumerate}
|
|
268 |
\item you might convert it into a DFA (subset construction)
|
|
269 |
\item you might try all possible paths in an NFA via backtracking
|
|
270 |
\item you might try all paths in an NFA in parallel
|
|
271 |
\item you might try to convert the DFA ``lazily''
|
|
272 |
\end{enumerate}\bigskip
|
|
273 |
|
|
274 |
Often No~2 is implemented (sometimes there are even good reasons for doing this).
|
|
275 |
|
|
276 |
\end{frame}}
|
|
277 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
278 |
|
|
279 |
|
|
280 |
|
|
281 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
282 |
\mode<presentation>{
|
|
283 |
\begin{frame}[c]
|
|
284 |
\frametitle{\begin{tabular}{c}\bl{$(a?\{n\})a\{n\}$} in Python\end{tabular}}
|
|
285 |
|
|
286 |
\begin{tikzpicture}[y=.2cm, x=.3cm]
|
|
287 |
%axis
|
|
288 |
\draw (0,0) -- coordinate (x axis mid) (30,0);
|
|
289 |
\draw (0,0) -- coordinate (y axis mid) (0,30);
|
|
290 |
%ticks
|
|
291 |
\foreach \x in {0,5,...,30}
|
|
292 |
\draw (\x,1pt) -- (\x,-3pt)
|
|
293 |
node[anchor=north] {\x};
|
|
294 |
\foreach \y in {0,5,...,30}
|
|
295 |
\draw (1pt,\y) -- (-3pt,\y)
|
|
296 |
node[anchor=east] {\y};
|
|
297 |
%labels
|
|
298 |
\node[below=0.6cm] at (x axis mid) {\bl{a}s};
|
|
299 |
\node[rotate=90, left=1.2cm] at (y axis mid) {secs};
|
|
300 |
|
|
301 |
%plots
|
|
302 |
\draw[color=blue] plot[mark=*, mark options={fill=white}]
|
|
303 |
file {re-python.data};
|
|
304 |
\only<2->{
|
|
305 |
\draw[color=red] plot[mark=triangle*, mark options={fill=white} ]
|
|
306 |
file {re1.data};}
|
|
307 |
\only<3->{
|
|
308 |
\draw[color=green] plot[mark=square*, mark options={fill=white} ]
|
|
309 |
file {re2.data};}
|
|
310 |
|
|
311 |
%legend
|
|
312 |
\begin{scope}[shift={(4,20)}]
|
|
313 |
\draw[color=blue] (0,0) --
|
|
314 |
plot[mark=*, mark options={fill=white}] (0.25,0) -- (0.5,0)
|
|
315 |
node[right]{\small Python};
|
|
316 |
\only<2->{\draw[yshift=\baselineskip, color=red] (0,0) --
|
|
317 |
plot[mark=triangle*, mark options={fill=white}] (0.25,0) -- (0.5,0)
|
|
318 |
node[right]{\small Scala V1};}
|
|
319 |
\only<3->{
|
|
320 |
\draw[yshift=2\baselineskip, color=green] (0,0) --
|
|
321 |
plot[mark=square*, mark options={fill=white}] (0.25,0) -- (0.5,0)
|
|
322 |
node[right]{\small Scala V2 with simplifications};}
|
|
323 |
\end{scope}
|
|
324 |
\end{tikzpicture}
|
|
325 |
|
|
326 |
\end{frame}}
|
|
327 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
328 |
|
|
329 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
330 |
\mode<presentation>{
|
|
331 |
\begin{frame}[c]
|
|
332 |
|
|
333 |
|
|
334 |
\begin{tikzpicture}[y=.7cm, x=.0009cm]
|
|
335 |
%axis
|
|
336 |
\draw (0,0) -- coordinate (x axis mid) (10000,0);
|
|
337 |
\draw (0,0) -- coordinate (y axis mid) (0,6);
|
|
338 |
%ticks
|
|
339 |
\foreach \x in {0,2000,...,10000}
|
|
340 |
\draw (\x,1pt) -- (\x,-3pt)
|
|
341 |
node[anchor=north] {\x};
|
|
342 |
\foreach \y in {0,1,...,6}
|
|
343 |
\draw (1pt,\y) -- (-3pt,\y)
|
|
344 |
node[anchor=east] {\y};
|
|
345 |
%labels
|
|
346 |
\node[below=0.6cm] at (x axis mid) {\bl{a}s};
|
|
347 |
\node[rotate=90, left=1.2cm] at (y axis mid) {secs};
|
|
348 |
|
|
349 |
%plots
|
|
350 |
\draw[color=blue] plot[mark=*, mark options={fill=white}]
|
|
351 |
file {re-internal.data};
|
|
352 |
\only<2->{
|
|
353 |
\draw[color=red] plot[mark=triangle*, mark options={fill=white} ]
|
|
354 |
file {re3.data};}
|
|
355 |
|
|
356 |
%legend
|
|
357 |
\begin{scope}[shift={(2000,4)}]
|
|
358 |
\draw[color=blue] (0,0) --
|
|
359 |
plot[mark=*, mark options={fill=white}] (0.25,0) -- (0.5,0)
|
|
360 |
node[right]{\small Scala Internal};
|
|
361 |
\only<2->{
|
|
362 |
\draw[yshift=\baselineskip, color=red] (0,0) --
|
|
363 |
plot[mark=triangle*, mark options={fill=white}] (0.25,0) -- (0.5,0)
|
|
364 |
node[right]{\small Scala V3 with explicit $\_\{\_\}$};}
|
|
365 |
\end{scope}
|
|
366 |
\end{tikzpicture}
|
|
367 |
|
|
368 |
\end{frame}}
|
|
369 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
370 |
|
|
371 |
|
|
372 |
|
50
|
373 |
\newcommand{\qq}{\mbox{\texttt{"}}}
|
49
|
374 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
375 |
\mode<presentation>{
|
|
376 |
\begin{frame}[c]
|
50
|
377 |
\frametitle{\begin{tabular}{c}Grammars\end{tabular}}
|
|
378 |
|
53
|
379 |
A (context-free) grammar \bl{$G$} consists of
|
49
|
380 |
|
|
381 |
\begin{itemize}
|
50
|
382 |
\item a finite set of nonterminal symbols (upper case)
|
|
383 |
\item a finite terminal symbols or tokens (lower case)
|
|
384 |
\item a start symbol (which must be a nonterminal)
|
|
385 |
\item a set of rules
|
49
|
386 |
\begin{center}
|
50
|
387 |
\bl{$A \rightarrow \text{rhs}$}
|
49
|
388 |
\end{center}
|
|
389 |
|
50
|
390 |
where \bl{rhs} are sequences involving terminals and nonterminals.\medskip\pause
|
49
|
391 |
|
50
|
392 |
We can also allow rules
|
|
393 |
\begin{center}
|
|
394 |
\bl{$A \rightarrow \text{rhs}_1 | \text{rhs}_2 | \ldots$}
|
|
395 |
\end{center}
|
|
396 |
\end{itemize}
|
49
|
397 |
|
|
398 |
|
|
399 |
\end{frame}}
|
|
400 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
401 |
|
|
402 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
403 |
\mode<presentation>{
|
|
404 |
\begin{frame}[c]
|
50
|
405 |
\frametitle{\begin{tabular}{c}Palindromes\end{tabular}}
|
49
|
406 |
|
|
407 |
\begin{center}
|
50
|
408 |
\bl{\begin{tabular}{lcl}
|
|
409 |
$S$ & $\rightarrow$ & $\epsilon$ \\
|
53
|
410 |
$S$ & $\rightarrow$ & $a\cdot S\cdot a$ \\
|
|
411 |
$S$ & $\rightarrow$ & $b\cdot S\cdot b$ \\
|
50
|
412 |
\end{tabular}}
|
|
413 |
\end{center}\pause
|
|
414 |
|
|
415 |
or
|
|
416 |
|
|
417 |
\begin{center}
|
|
418 |
\bl{\begin{tabular}{lcl}
|
53
|
419 |
$S$ & $\rightarrow$ & $\epsilon \;|\; a\cdot S\cdot a \;|\;b\cdot S\cdot b$ \\
|
50
|
420 |
\end{tabular}}
|
49
|
421 |
\end{center}
|
|
422 |
|
|
423 |
|
|
424 |
\end{frame}}
|
|
425 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
426 |
|
|
427 |
|
|
428 |
|
|
429 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
430 |
\mode<presentation>{
|
|
431 |
\begin{frame}[c]
|
50
|
432 |
\frametitle{\begin{tabular}{c}Arithmetic Expressions\end{tabular}}
|
49
|
433 |
|
|
434 |
\begin{center}
|
|
435 |
\bl{\begin{tabular}{lcl}
|
50
|
436 |
$E$ & $\rightarrow$ & $num\_token$ \\
|
53
|
437 |
$E$ & $\rightarrow$ & $E \cdot + \cdot E$ \\
|
|
438 |
$E$ & $\rightarrow$ & $E \cdot - \cdot E$ \\
|
|
439 |
$E$ & $\rightarrow$ & $E \cdot * \cdot E$ \\
|
|
440 |
$E$ & $\rightarrow$ & $( \cdot E \cdot )$
|
49
|
441 |
\end{tabular}}
|
50
|
442 |
\end{center}\pause
|
49
|
443 |
|
50
|
444 |
\bl{\texttt{1 + 2 * 3 + 4}}
|
49
|
445 |
|
|
446 |
\end{frame}}
|
|
447 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
448 |
|
|
449 |
|
|
450 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
451 |
\mode<presentation>{
|
|
452 |
\begin{frame}[c]
|
50
|
453 |
\frametitle{\begin{tabular}{c}Parse Trees\end{tabular}}
|
49
|
454 |
|
|
455 |
\begin{center}
|
|
456 |
\bl{\begin{tabular}{lcl}
|
53
|
457 |
$E$ & $\rightarrow$ & $F \;|\; F \cdot * \cdot F$\\
|
|
458 |
$F$ & $\rightarrow$ & $T \;|\; T \cdot + \cdot T \;|\; T \cdot - \cdot T$\\
|
|
459 |
$T$ & $\rightarrow$ & $num\_token \;|\; ( \cdot E \cdot )$\\
|
49
|
460 |
\end{tabular}}
|
|
461 |
\end{center}
|
|
462 |
|
|
463 |
\begin{center}
|
|
464 |
\begin{tikzpicture}[level distance=8mm, blue]
|
50
|
465 |
\node {$E$}
|
|
466 |
child {node {$F$}
|
|
467 |
child {node {$T$}
|
|
468 |
child {node {(\,$E$\,)}
|
|
469 |
child {node{$F$ *{} $F$}
|
|
470 |
child {node {$T$} child {node {2}}}
|
|
471 |
child {node {$T$} child {node {3}}}
|
49
|
472 |
}
|
|
473 |
}
|
|
474 |
}
|
50
|
475 |
child {node {+}}
|
|
476 |
child {node {$T$}
|
|
477 |
child {node {(\,$E$\,)}
|
|
478 |
child {node {$F$}
|
|
479 |
child {node {$T$ +{} $T$}
|
49
|
480 |
child {node {3}}
|
|
481 |
child {node {4}}
|
|
482 |
}
|
|
483 |
}}
|
|
484 |
}};
|
|
485 |
\end{tikzpicture}
|
|
486 |
\end{center}
|
|
487 |
|
50
|
488 |
\begin{textblock}{5}(1, 6.5)
|
49
|
489 |
\bl{\texttt{(2*3)+(3+4)}}
|
|
490 |
\end{textblock}
|
|
491 |
|
|
492 |
\end{frame}}
|
|
493 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
50
|
494 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
495 |
\mode<presentation>{
|
|
496 |
\begin{frame}[c]
|
|
497 |
\frametitle{\begin{tabular}{c}Ambiguous Grammars\end{tabular}}
|
|
498 |
|
|
499 |
A grammar is \alert{ambiguous} if there is a string that has at least parse trees.
|
|
500 |
|
|
501 |
|
|
502 |
\begin{center}
|
|
503 |
\bl{\begin{tabular}{lcl}
|
|
504 |
$E$ & $\rightarrow$ & $num\_token$ \\
|
53
|
505 |
$E$ & $\rightarrow$ & $E \cdot + \cdot E$ \\
|
|
506 |
$E$ & $\rightarrow$ & $E \cdot - \cdot E$ \\
|
|
507 |
$E$ & $\rightarrow$ & $E \cdot * \cdot E$ \\
|
|
508 |
$E$ & $\rightarrow$ & $( \cdot E \cdot )$
|
50
|
509 |
\end{tabular}}
|
|
510 |
\end{center}
|
|
511 |
|
|
512 |
\bl{\texttt{1 + 2 * 3 + 4}}
|
|
513 |
|
|
514 |
\end{frame}}
|
|
515 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
516 |
|
|
517 |
|
|
518 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
519 |
\mode<presentation>{
|
|
520 |
\begin{frame}[c]
|
|
521 |
\frametitle{\begin{tabular}{c}Chomsky Normal Form\end{tabular}}
|
|
522 |
|
|
523 |
All rules must be of the form
|
|
524 |
|
|
525 |
\begin{center}
|
|
526 |
\bl{$A \rightarrow a$}
|
|
527 |
\end{center}
|
|
528 |
|
|
529 |
or
|
|
530 |
|
|
531 |
\begin{center}
|
53
|
532 |
\bl{$A \rightarrow B\cdot C$}
|
50
|
533 |
\end{center}
|
|
534 |
|
|
535 |
|
|
536 |
|
|
537 |
\end{frame}}
|
|
538 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
53
|
539 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
540 |
\mode<presentation>{
|
|
541 |
\begin{frame}[c]
|
|
542 |
\frametitle{\begin{tabular}{c}CYK Algorithm\end{tabular}}
|
50
|
543 |
|
53
|
544 |
|
|
545 |
\begin{center}
|
|
546 |
\bl{\begin{tabular}{@ {}lcl}
|
|
547 |
$S$ & $\rightarrow$ & $N\cdot P$ \\
|
|
548 |
$P$ & $\rightarrow$ & $V\cdot N$ \\
|
|
549 |
$N$ & $\rightarrow$ & $N\cdot N$ \\
|
|
550 |
$N$ & $\rightarrow$ & $\texttt{students} \;|\; \texttt{Jeff} \;|\; \texttt{geometry} \;|\; \texttt{trains} $ \\
|
56
|
551 |
$V$ & $\rightarrow$ & $\texttt{trains}$
|
53
|
552 |
\end{tabular}}
|
|
553 |
\end{center}
|
|
554 |
|
|
555 |
\bl{\texttt{Jeff trains geometry students}}
|
|
556 |
|
|
557 |
\end{frame}}
|
|
558 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
51
|
559 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
560 |
\mode<presentation>{
|
|
561 |
\begin{frame}[c]
|
|
562 |
\frametitle{\begin{tabular}{c}CYK Algorithm\end{tabular}}
|
50
|
563 |
|
49
|
564 |
|
52
|
565 |
\begin{itemize}
|
|
566 |
\item runtime is \bl{$O(n^3)$}\bigskip
|
|
567 |
\item grammars need to be transferred into CNF
|
|
568 |
\end{itemize}
|
51
|
569 |
|
|
570 |
\end{frame}}
|
|
571 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
572 |
|
49
|
573 |
\end{document}
|
|
574 |
|
|
575 |
%%% Local Variables:
|
|
576 |
%%% mode: latex
|
|
577 |
%%% TeX-master: t
|
|
578 |
%%% End:
|
|
579 |
|