author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Mon, 11 Nov 2013 15:26:20 +0000 | |
changeset 184 | 2e9134d25a2b |
parent 173 | 7cfb7a6f7c99 |
child 185 | ea8b94d4755e |
permissions | -rw-r--r-- |
63 | 1 |
\documentclass[dvipsnames,14pt,t]{beamer} |
173
7cfb7a6f7c99
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
2 |
\usepackage{beamerthemeplaincu} |
7cfb7a6f7c99
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
3 |
%\usepackage[T1]{fontenc} |
7cfb7a6f7c99
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
4 |
%\usepackage[latin1]{inputenc} |
63 | 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 |
|
173
7cfb7a6f7c99
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
75 |
\renewcommand{\slidecaption}{AFL 07, King's College London, 13.~November 2013} |
63 | 76 |
\newcommand{\bl}[1]{\textcolor{blue}{#1}} |
77 |
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions |
|
78 |
||
79 |
\begin{document} |
|
80 |
||
81 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
82 |
\mode<presentation>{ |
|
83 |
\begin{frame}<1>[t] |
|
84 |
\frametitle{% |
|
85 |
\begin{tabular}{@ {}c@ {}} |
|
86 |
\\[-3mm] |
|
87 |
\LARGE Automata and \\[-2mm] |
|
88 |
\LARGE Formal Languages (7)\\[3mm] |
|
89 |
\end{tabular}} |
|
90 |
||
91 |
\normalsize |
|
92 |
\begin{center} |
|
93 |
\begin{tabular}{ll} |
|
94 |
Email: & christian.urban at kcl.ac.uk\\ |
|
173
7cfb7a6f7c99
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
95 |
Office: & S1.27 (1st floor Strand Building)\\ |
63 | 96 |
Slides: & KEATS (also home work is there)\\ |
97 |
\end{tabular} |
|
98 |
\end{center} |
|
99 |
||
100 |
||
101 |
\end{frame}} |
|
102 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
103 |
||
104 |
||
105 |
\newcommand{\qq}{\mbox{\texttt{"}}} |
|
106 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
107 |
\mode<presentation>{ |
|
108 |
\begin{frame}[c] |
|
64
2d625418c011
added everything
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
63
diff
changeset
|
109 |
\frametitle{\begin{tabular}{c}CFGs\end{tabular}} |
63 | 110 |
|
64
2d625418c011
added everything
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
63
diff
changeset
|
111 |
A \alert{context-free} grammar (CFG) \bl{$G$} consists of: |
63 | 112 |
|
113 |
\begin{itemize} |
|
114 |
\item a finite set of nonterminal symbols (upper case) |
|
115 |
\item a finite terminal symbols or tokens (lower case) |
|
116 |
\item a start symbol (which must be a nonterminal) |
|
117 |
\item a set of rules |
|
118 |
\begin{center} |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
119 |
\bl{$A \rightarrow \text{rhs}_1 | \text{rhs}_2 | \ldots$} |
63 | 120 |
\end{center} |
121 |
||
122 |
where \bl{rhs} are sequences involving terminals and nonterminals (can also be empty).\medskip\pause |
|
123 |
||
124 |
\end{itemize} |
|
125 |
||
126 |
\end{frame}} |
|
127 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
128 |
||
129 |
||
130 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
131 |
\mode<presentation>{ |
|
132 |
\begin{frame}[c] |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
133 |
\frametitle{\begin{tabular}{c}Hierarchie of Languages\end{tabular}} |
63 | 134 |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
135 |
Recall that languages are sets of strings. |
63 | 136 |
|
137 |
\begin{center} |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
138 |
\begin{tikzpicture} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
139 |
[rect/.style={draw=black!50, top color=white,bottom color=black!20, rectangle, very thick, rounded corners}] |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
140 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
141 |
\draw (0,0) node [rect, text depth=39mm, text width=68mm] {all languages}; |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
142 |
\draw (0,-0.4) node [rect, text depth=28.5mm, text width=64mm] {decidable languages}; |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
143 |
\draw (0,-0.85) node [rect, text depth=17mm] {context sensitive languages}; |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
144 |
\draw (0,-1.14) node [rect, text depth=9mm, text width=50mm] {context-free languages}; |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
145 |
\draw (0,-1.4) node [rect] {regular languages}; |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
146 |
\end{tikzpicture} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
147 |
|
63 | 148 |
\end{center} |
149 |
||
150 |
\end{frame}} |
|
151 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
152 |
||
153 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
154 |
\mode<presentation>{ |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
155 |
\begin{frame}[t] |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
156 |
\frametitle{\begin{tabular}{c}Numbers\end{tabular}} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
157 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
158 |
A grammar for numbers: |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
159 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
160 |
\begin{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
161 |
\bl{\begin{tabular}{lcl} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
162 |
$N$ & $\rightarrow$ & $N \cdot N \;|\; 0 \;|\; 1 \;|\; \ldots \;|\; 9$\\ |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
163 |
\end{tabular}} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
164 |
\end{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
165 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
166 |
Unfortunately left-recursive (and ambiguous).\medskip\\ |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
167 |
A problem for \alert{recursive descent parsers} (e.g.~parser combinators). |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
168 |
\bigskip\pause |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
169 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
170 |
A non-left-recursive grammar for numbers |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
171 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
172 |
\begin{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
173 |
\bl{\begin{tabular}{lcl} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
174 |
$N$ & $\rightarrow$ & $0 \cdot N \;|\;1 \cdot N \;|\ldots\;|\; 0 \;|\; 1 \;|\; \ldots \;|\; 9$\\ |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
175 |
\end{tabular}} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
176 |
\end{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
177 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
178 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
179 |
\end{frame}} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
180 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
181 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
182 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
183 |
\mode<presentation>{ |
63 | 184 |
\begin{frame}[c] |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
185 |
\frametitle{\begin{tabular}{c}Chomsky Normal Form\end{tabular}} |
63 | 186 |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
187 |
All rules must be of the form |
63 | 188 |
|
189 |
\begin{center} |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
190 |
\bl{$A \rightarrow a$} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
191 |
\end{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
192 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
193 |
or |
63 | 194 |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
195 |
\begin{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
196 |
\bl{$A \rightarrow B\cdot C$} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
197 |
\end{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
198 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
199 |
|
63 | 200 |
|
201 |
\end{frame}} |
|
202 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
203 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
204 |
\mode<presentation>{ |
|
205 |
\begin{frame}[c] |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
206 |
\frametitle{\begin{tabular}{c}CYK Algorithm\end{tabular}} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
207 |
|
63 | 208 |
|
209 |
\begin{center} |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
210 |
\bl{\begin{tabular}{@ {}lcl} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
211 |
$S$ & $\rightarrow$ & $N\cdot P$ \\ |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
212 |
$P$ & $\rightarrow$ & $V\cdot N$ \\ |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
213 |
$N$ & $\rightarrow$ & $N\cdot N$ \\ |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
214 |
$N$ & $\rightarrow$ & $\texttt{students} \;|\; \texttt{Jeff} \;|\; \texttt{geometry} \;|\; \texttt{trains} $ \\ |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
215 |
$V$ & $\rightarrow$ & $\texttt{trains}$ |
63 | 216 |
\end{tabular}} |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
217 |
\end{center} |
63 | 218 |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
219 |
\bl{\texttt{Jeff trains geometry students}} |
63 | 220 |
|
221 |
\end{frame}} |
|
222 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
223 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
224 |
\mode<presentation>{ |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
225 |
\begin{frame}[c] |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
226 |
\frametitle{\begin{tabular}{c}CYK Algorithm\end{tabular}} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
227 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
228 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
229 |
\begin{itemize} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
230 |
\item runtime is \bl{$O(n^3)$}\bigskip |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
231 |
\item grammars need to be transferred into CNF |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
232 |
\end{itemize} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
233 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
234 |
\end{frame}} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
235 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
63 | 236 |
|
237 |
||
238 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
239 |
\mode<presentation>{ |
|
240 |
\begin{frame}[c] |
|
241 |
\frametitle{\begin{tabular}{c}Parse Trees\end{tabular}} |
|
242 |
||
243 |
\begin{center} |
|
244 |
\bl{\begin{tabular}{lcl} |
|
245 |
$E$ & $\rightarrow$ & $F \;|\; F \cdot * \cdot F$\\ |
|
246 |
$F$ & $\rightarrow$ & $T \;|\; T \cdot + \cdot T \;|\; T \cdot - \cdot T$\\ |
|
247 |
$T$ & $\rightarrow$ & $num\_token \;|\; ( \cdot E \cdot )$\\ |
|
248 |
\end{tabular}} |
|
249 |
\end{center} |
|
250 |
||
251 |
\begin{center} |
|
252 |
\begin{tikzpicture}[level distance=8mm, blue] |
|
253 |
\node {$E$} |
|
254 |
child {node {$F$} |
|
255 |
child {node {$T$} |
|
256 |
child {node {(\,$E$\,)} |
|
257 |
child {node{$F$ *{} $F$} |
|
258 |
child {node {$T$} child {node {2}}} |
|
259 |
child {node {$T$} child {node {3}}} |
|
260 |
} |
|
261 |
} |
|
262 |
} |
|
263 |
child {node {+}} |
|
264 |
child {node {$T$} |
|
265 |
child {node {(\,$E$\,)} |
|
266 |
child {node {$F$} |
|
267 |
child {node {$T$ +{} $T$} |
|
268 |
child {node {3}} |
|
269 |
child {node {4}} |
|
270 |
} |
|
271 |
}} |
|
272 |
}}; |
|
273 |
\end{tikzpicture} |
|
274 |
\end{center} |
|
275 |
||
276 |
\begin{textblock}{5}(1, 6.5) |
|
277 |
\bl{\texttt{(2*3)+(3+4)}} |
|
278 |
\end{textblock} |
|
279 |
||
280 |
\end{frame}} |
|
281 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
282 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
283 |
\mode<presentation>{ |
|
284 |
\begin{frame}[c] |
|
285 |
\frametitle{\begin{tabular}{c}Ambiguous Grammars\end{tabular}} |
|
286 |
||
287 |
A CFG is \alert{ambiguous} if there is a string that has at least parse trees. |
|
288 |
||
289 |
||
290 |
\begin{center} |
|
291 |
\bl{\begin{tabular}{lcl} |
|
292 |
$E$ & $\rightarrow$ & $num\_token$ \\ |
|
293 |
$E$ & $\rightarrow$ & $E \cdot + \cdot E$ \\ |
|
294 |
$E$ & $\rightarrow$ & $E \cdot - \cdot E$ \\ |
|
295 |
$E$ & $\rightarrow$ & $E \cdot * \cdot E$ \\ |
|
296 |
$E$ & $\rightarrow$ & $( \cdot E \cdot )$ |
|
297 |
\end{tabular}} |
|
298 |
\end{center} |
|
299 |
||
300 |
\bl{\texttt{1 + 2 * 3 + 4}} |
|
301 |
||
302 |
\end{frame}} |
|
303 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
304 |
||
305 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
306 |
\mode<presentation>{ |
|
307 |
\begin{frame}[c] |
|
308 |
\frametitle{\begin{tabular}{c}Dangling Else\end{tabular}} |
|
309 |
||
310 |
Another ambiguous grammar:\bigskip |
|
311 |
||
312 |
\begin{center} |
|
313 |
\bl{\begin{tabular}{lcl} |
|
314 |
$E$ & $\rightarrow$ & if $E$ then $E$\\ |
|
315 |
& $|$ & if $E$ then $E$ else $E$ \\ |
|
316 |
& $|$ & id |
|
317 |
\end{tabular}} |
|
318 |
\end{center}\bigskip |
|
319 |
||
320 |
\bl{\texttt{if a then if x then y else c}} |
|
321 |
||
322 |
\end{frame}} |
|
323 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
324 |
||
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
325 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
326 |
\mode<presentation>{ |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
327 |
\begin{frame}[c] |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
328 |
\frametitle{\begin{tabular}{c}A CFG Derivation\end{tabular}} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
329 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
330 |
\begin{enumerate} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
331 |
\item Begin with a string with only the start symbol \bl{$S$}\bigskip |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
332 |
\item Replace any non-terminal \bl{$X$} in the string by the |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
333 |
right-hand side of some production \bl{$X \rightarrow \text{rhs}$}\bigskip |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
334 |
\item Repeat 2 until there are no non-terminals |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
335 |
\end{enumerate} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
336 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
337 |
\begin{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
338 |
\bl{$S \rightarrow \ldots \rightarrow \ldots \rightarrow \ldots \rightarrow \ldots $} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
339 |
\end{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
340 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
341 |
\end{frame}} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
342 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
343 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
344 |
|
63 | 345 |
\end{document} |
346 |
||
347 |
%%% Local Variables: |
|
348 |
%%% mode: latex |
|
349 |
%%% TeX-master: t |
|
350 |
%%% End: |
|
351 |