author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Tue, 12 Nov 2013 22:54:41 +0000 | |
changeset 187 | 9471a0325773 |
parent 186 | fab34204d08e |
child 188 | 12ef150273ce |
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 |
||
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
74 |
\setmonofont{Consolas} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
75 |
|
63 | 76 |
% beamer stuff |
173
7cfb7a6f7c99
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
77 |
\renewcommand{\slidecaption}{AFL 07, King's College London, 13.~November 2013} |
63 | 78 |
\newcommand{\bl}[1]{\textcolor{blue}{#1}} |
79 |
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions |
|
80 |
||
81 |
\begin{document} |
|
82 |
||
83 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
84 |
\mode<presentation>{ |
|
85 |
\begin{frame}<1>[t] |
|
86 |
\frametitle{% |
|
87 |
\begin{tabular}{@ {}c@ {}} |
|
88 |
\\[-3mm] |
|
89 |
\LARGE Automata and \\[-2mm] |
|
90 |
\LARGE Formal Languages (7)\\[3mm] |
|
91 |
\end{tabular}} |
|
92 |
||
93 |
\normalsize |
|
94 |
\begin{center} |
|
95 |
\begin{tabular}{ll} |
|
96 |
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
|
97 |
Office: & S1.27 (1st floor Strand Building)\\ |
63 | 98 |
Slides: & KEATS (also home work is there)\\ |
99 |
\end{tabular} |
|
100 |
\end{center} |
|
101 |
||
102 |
||
103 |
\end{frame}} |
|
104 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
105 |
||
106 |
||
107 |
\newcommand{\qq}{\mbox{\texttt{"}}} |
|
108 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
109 |
\mode<presentation>{ |
|
110 |
\begin{frame}[c] |
|
186
fab34204d08e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
185
diff
changeset
|
111 |
\frametitle{\begin{tabular}{c}Two Weeks Ago: CFGs\end{tabular}} |
63 | 112 |
|
64
2d625418c011
added everything
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
63
diff
changeset
|
113 |
A \alert{context-free} grammar (CFG) \bl{$G$} consists of: |
63 | 114 |
|
115 |
\begin{itemize} |
|
116 |
\item a finite set of nonterminal symbols (upper case) |
|
117 |
\item a finite terminal symbols or tokens (lower case) |
|
118 |
\item a start symbol (which must be a nonterminal) |
|
119 |
\item a set of rules |
|
120 |
\begin{center} |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
121 |
\bl{$A \rightarrow \text{rhs}_1 | \text{rhs}_2 | \ldots$} |
63 | 122 |
\end{center} |
123 |
||
124 |
where \bl{rhs} are sequences involving terminals and nonterminals (can also be empty).\medskip\pause |
|
125 |
||
126 |
\end{itemize} |
|
127 |
||
128 |
\end{frame}} |
|
129 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
130 |
||
131 |
||
132 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
133 |
\mode<presentation>{ |
|
134 |
\begin{frame}[c] |
|
186
fab34204d08e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
185
diff
changeset
|
135 |
\frametitle{\begin{tabular}{c}Hierarchy of Languages\end{tabular}} |
63 | 136 |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
137 |
Recall that languages are sets of strings. |
63 | 138 |
|
139 |
\begin{center} |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
140 |
\begin{tikzpicture} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
141 |
[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
|
142 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
143 |
\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
|
144 |
\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
|
145 |
\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
|
146 |
\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
|
147 |
\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
|
148 |
\end{tikzpicture} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
149 |
|
63 | 150 |
\end{center} |
151 |
||
152 |
\end{frame}} |
|
153 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
154 |
||
155 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
156 |
\mode<presentation>{ |
|
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
157 |
\begin{frame}[c] |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
158 |
\frametitle{\begin{tabular}{c}Arithmetic Expressions\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
159 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
160 |
A grammar for arithmetic expressions and numbers: |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
161 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
162 |
\begin{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
163 |
\bl{\begin{tabular}{lcl} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
164 |
$E$ & $\rightarrow$ & $E \cdot + \cdot E \;|\;E \cdot * \cdot E \;|\;( \cdot E \cdot ) \;|\;N$ \\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
165 |
$N$ & $\rightarrow$ & $N \cdot N \;|\; 0 \;|\; 1 \;|\: \ldots \;|\; 9$ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
166 |
\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
167 |
\end{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
168 |
|
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
169 |
Unfortunately it is left-recursive (and ambiguous).\medskip\\ |
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
170 |
A problem for \alert{recursive descent parsers} (e.g.~parser combinators). |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
171 |
\bigskip\pause |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
172 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
173 |
\end{frame}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
174 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
175 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
176 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
177 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
178 |
\mode<presentation>{ |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
179 |
\begin{frame}[t] |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
180 |
\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
|
181 |
|
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
182 |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
183 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
184 |
\begin{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
185 |
\bl{\begin{tabular}{lcl} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
186 |
$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
|
187 |
\end{tabular}} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
188 |
\end{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
189 |
|
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
190 |
A non-left-recursive, non-ambiguous grammar for numbers: |
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
191 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
192 |
\begin{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
193 |
\bl{\begin{tabular}{lcl} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
194 |
$N$ & $\rightarrow$ & $0 \cdot N \;|\;1 \cdot N \;|\;\ldots\;|\; 0 \;|\; 1 \;|\; \ldots \;|\; 9$\\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
195 |
\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
196 |
\end{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
197 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
198 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
199 |
\end{frame}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
200 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
201 |
|
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
202 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
203 |
\mode<presentation>{ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
204 |
\begin{frame}[c] |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
205 |
\frametitle{\begin{tabular}{c}Operator Precedences\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
206 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
207 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
208 |
To disambiguate |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
209 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
210 |
\begin{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
211 |
\bl{\begin{tabular}{lcl} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
212 |
$E$ & $\rightarrow$ & $E \cdot + \cdot E \;|\;E \cdot * \cdot E \;|\;( \cdot E \cdot ) \;|\;N$ \\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
213 |
\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
214 |
\end{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
215 |
|
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
216 |
Decide on how many precedence levels, say\medskip\\ |
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
217 |
\hspace{5mm}highest for \bl{$()$}, medium for \bl{*}, lowest for \bl{+} |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
218 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
219 |
\begin{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
220 |
\bl{\begin{tabular}{lcl} |
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
221 |
$E_{low}$ & $\rightarrow$ & $E_{med} \cdot + \cdot E_{low} \;|\; E_{med}$ \\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
222 |
$E_{med}$ & $\rightarrow$ & $E_{hi} \cdot * \cdot E_{med} \;|\; E_{hi}$\\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
223 |
$E_{hi}$ & $\rightarrow$ & $( \cdot E_{low} \cdot ) \;|\;N$ \\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
224 |
\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
225 |
\end{center}\pause |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
226 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
227 |
\small What happens with \bl{$1 + 3 + 4$}? |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
228 |
\end{frame}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
229 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
230 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
231 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
232 |
\mode<presentation>{ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
233 |
\begin{frame}[c] |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
234 |
\frametitle{\begin{tabular}{c}Removing Left-Recursion\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
235 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
236 |
The rule for numbers is directly left-recursive: |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
237 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
238 |
\begin{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
239 |
\bl{\begin{tabular}{lcl} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
240 |
$N$ & $\rightarrow$ & $N \cdot N \;|\; 0 \;|\; 1\;\;\;\;(\ldots)$ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
241 |
\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
242 |
\end{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
243 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
244 |
Translate |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
245 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
246 |
\begin{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
247 |
\begin{tabular}{ccc} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
248 |
\bl{\begin{tabular}{lcl} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
249 |
$N$ & $\rightarrow$ & $N \cdot \alpha$\\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
250 |
& $\;|\;$ & $\beta$\\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
251 |
\\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
252 |
\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
253 |
& {\Large$\Rightarrow$} & |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
254 |
\bl{\begin{tabular}{lcl} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
255 |
$N$ & $\rightarrow$ & $\beta \cdot N'$\\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
256 |
$N'$ & $\rightarrow$ & $\alpha \cdot N'$\\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
257 |
& $\;|\;$ & $\epsilon$ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
258 |
\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
259 |
\end{tabular} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
260 |
\end{center}\pause |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
261 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
262 |
Which means |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
263 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
264 |
\begin{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
265 |
\bl{\begin{tabular}{lcl} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
266 |
$N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1 \cdot N'$\\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
267 |
$N'$ & $\rightarrow$ & $N \cdot N' \;|\; \epsilon$\\ |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
268 |
\end{tabular}} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
269 |
\end{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
270 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
271 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
272 |
\end{frame}} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
273 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
274 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
275 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
276 |
\mode<presentation>{ |
63 | 277 |
\begin{frame}[c] |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
278 |
\frametitle{\begin{tabular}{c}Chomsky Normal Form\end{tabular}} |
63 | 279 |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
280 |
All rules must be of the form |
63 | 281 |
|
282 |
\begin{center} |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
283 |
\bl{$A \rightarrow a$} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
284 |
\end{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
285 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
286 |
or |
63 | 287 |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
288 |
\begin{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
289 |
\bl{$A \rightarrow B\cdot C$} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
290 |
\end{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
291 |
|
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
292 |
No rule can contain \bl{$\epsilon$}. |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
293 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
294 |
\end{frame}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
295 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
296 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
297 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
298 |
\mode<presentation>{ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
299 |
\begin{frame}[c] |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
300 |
\frametitle{\begin{tabular}{c}$\epsilon$-Removal\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
301 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
302 |
\begin{enumerate} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
303 |
\item If \bl{$A\rightarrow \alpha \cdot B \cdot \beta$} and \bl{$B \rightarrow \epsilon$} are in the grammar, |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
304 |
then add \bl{$A\rightarrow \alpha \cdot \beta$} (iterate if necessary). |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
305 |
\item Throw out all \bl{$B \rightarrow \epsilon$}. |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
306 |
\end{enumerate} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
307 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
308 |
\small |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
309 |
\begin{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
310 |
\begin{tabular}{ccc} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
311 |
\bl{\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
312 |
$N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1\cdot N'$\\ |
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
313 |
$N'$ & $\rightarrow$ & $N \cdot N'\;|\;\epsilon$\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
314 |
\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
315 |
\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
316 |
\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
317 |
\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
318 |
\\ |
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
319 |
\end{tabular}} & |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
320 |
\bl{\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l} |
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
321 |
\\ |
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
322 |
$N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1\cdot N'\;|\;0\;|\;1$\\ |
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
323 |
$N'$ & $\rightarrow$ & $N \cdot N'\;|\;N\;|\;\epsilon$\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
324 |
\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
325 |
$N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1\cdot N'\;|\;0\;|\;1$\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
326 |
$N'$ & $\rightarrow$ & $N \cdot N'\;|\;N$\\ |
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
327 |
\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
328 |
\end{tabular} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
329 |
\end{center} |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
330 |
|
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
331 |
\pause\normalsize |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
332 |
\begin{center} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
333 |
\bl{\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
334 |
$N$ & $\rightarrow$ & $0 \cdot N\;|\; 1\cdot N\;|\;0\;|\;1$\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
335 |
\end{tabular}} |
63 | 336 |
|
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
337 |
\end{center} |
63 | 338 |
\end{frame}} |
339 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
340 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
341 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
342 |
|
63 | 343 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
344 |
\mode<presentation>{ |
|
345 |
\begin{frame}[c] |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
346 |
\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
|
347 |
|
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
348 |
If grammar is in Chomsky normalform \ldots |
63 | 349 |
|
350 |
\begin{center} |
|
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
351 |
\bl{\begin{tabular}{@ {}lcl@ {}} |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
352 |
$S$ & $\rightarrow$ & $N\cdot P$ \\ |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
353 |
$P$ & $\rightarrow$ & $V\cdot N$ \\ |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
354 |
$N$ & $\rightarrow$ & $N\cdot N$ \\ |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
355 |
$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
|
356 |
$V$ & $\rightarrow$ & $\texttt{trains}$ |
63 | 357 |
\end{tabular}} |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
358 |
\end{center} |
63 | 359 |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
360 |
\bl{\texttt{Jeff trains geometry students}} |
63 | 361 |
|
362 |
\end{frame}} |
|
363 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
364 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
365 |
\mode<presentation>{ |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
366 |
\begin{frame}[c] |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
367 |
\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
|
368 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
369 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
370 |
\begin{itemize} |
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
371 |
\item fastest possible algorithm for recognition problem |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
372 |
\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
|
373 |
\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
|
374 |
\end{itemize} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
375 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
376 |
\end{frame}} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
377 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
63 | 378 |
|
379 |
||
380 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
381 |
\mode<presentation>{ |
|
382 |
\begin{frame}[c] |
|
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
383 |
\frametitle{\begin{tabular}{c}Hierarchy of Languages\end{tabular}} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
384 |
|
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
385 |
Recall that languages are sets of strings. |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
386 |
|
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
387 |
\begin{center} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
388 |
\begin{tikzpicture} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
389 |
[rect/.style={draw=black!50, top color=white,bottom color=black!20, rectangle, very thick, rounded corners}] |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
390 |
|
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
391 |
\draw (0,0) node [rect, text depth=39mm, text width=68mm] {all languages}; |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
392 |
\draw (0,-0.4) node [rect, text depth=28.5mm, text width=64mm] {decidable languages}; |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
393 |
\draw (0,-0.85) node [rect, text depth=17mm] {context sensitive languages}; |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
394 |
\draw (0,-1.14) node [rect, text depth=9mm, text width=50mm] {context-free languages}; |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
395 |
\draw (0,-1.4) node [rect] {regular languages}; |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
396 |
\end{tikzpicture} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
397 |
|
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
398 |
\end{center} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
399 |
|
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
400 |
\end{frame}} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
401 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
402 |
|
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
403 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
404 |
\mode<presentation>{ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
405 |
\begin{frame}[c] |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
406 |
\frametitle{\begin{tabular}{c}Context Sensitive Grms\end{tabular}} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
407 |
|
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
408 |
|
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
409 |
\begin{center} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
410 |
\bl{\begin{tabular}{lcl} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
411 |
$S$ & $\Rightarrow$ & $bSAA\;|\; \epsilon$\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
412 |
$A$ & $\Rightarrow$ & $a$\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
413 |
$bA$ & $\Rightarrow$ & $Ab$\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
414 |
\end{tabular}} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
415 |
\end{center}\pause |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
416 |
|
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
417 |
\begin{center} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
418 |
\bl{$S \Rightarrow\ldots\Rightarrow^? "ababaa"$} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
419 |
\end{center} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
420 |
|
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
421 |
\end{frame}} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
422 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
423 |
|
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
424 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
425 |
\mode<presentation>{ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
426 |
\begin{frame}[c] |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
427 |
\frametitle{\begin{tabular}{c}Parse Trees\end{tabular}} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
428 |
\begin{center} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
429 |
\begin{tabular}{@{}lcl@{}} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
430 |
\textit{Stmt} & $\rightarrow$ & $\texttt{skip}$\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
431 |
& $|$ & \textit{Id}\;\texttt{:=}\;\textit{AExp}\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
432 |
& $|$ & \texttt{if}\; \textit{BExp} \;\texttt{then}\; \textit{Block} \;\texttt{else}\; \textit{Block}\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
433 |
& $|$ & \texttt{while}\; \textit{BExp} \;\texttt{do}\; \textit{Block}\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
434 |
& $|$ & \texttt{read}\;\textit{Id}\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
435 |
& $|$ & \texttt{write}\;\textit{Id}\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
436 |
& $|$ & \texttt{write}\;\textit{String}\medskip\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
437 |
\textit{Stmts} & $\rightarrow$ & \textit{Stmt} \;\texttt{;}\; \textit{Stmts}\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
438 |
& $|$ & \textit{Stmt}\medskip\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
439 |
\textit{Block} & $\rightarrow$ & \texttt{\{}\,\textit{Stmts}\,\texttt{\}}\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
440 |
& $|$ & \textit{Stmt}\medskip\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
441 |
\textit{AExp} & $\rightarrow$ & \ldots\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
442 |
\textit{BExp} & $\rightarrow$ & \ldots\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
443 |
\end{tabular} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
444 |
\end{center} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
445 |
\end{frame}} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
446 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
447 |
|
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
448 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
449 |
\mode<presentation>{ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
450 |
\begin{frame}[c] |
63 | 451 |
\frametitle{\begin{tabular}{c}Parse Trees\end{tabular}} |
452 |
||
453 |
\begin{center} |
|
454 |
\bl{\begin{tabular}{lcl} |
|
455 |
$E$ & $\rightarrow$ & $F \;|\; F \cdot * \cdot F$\\ |
|
456 |
$F$ & $\rightarrow$ & $T \;|\; T \cdot + \cdot T \;|\; T \cdot - \cdot T$\\ |
|
457 |
$T$ & $\rightarrow$ & $num\_token \;|\; ( \cdot E \cdot )$\\ |
|
458 |
\end{tabular}} |
|
459 |
\end{center} |
|
460 |
||
461 |
\begin{center} |
|
462 |
\begin{tikzpicture}[level distance=8mm, blue] |
|
463 |
\node {$E$} |
|
464 |
child {node {$F$} |
|
465 |
child {node {$T$} |
|
466 |
child {node {(\,$E$\,)} |
|
467 |
child {node{$F$ *{} $F$} |
|
468 |
child {node {$T$} child {node {2}}} |
|
469 |
child {node {$T$} child {node {3}}} |
|
470 |
} |
|
471 |
} |
|
472 |
} |
|
473 |
child {node {+}} |
|
474 |
child {node {$T$} |
|
475 |
child {node {(\,$E$\,)} |
|
476 |
child {node {$F$} |
|
477 |
child {node {$T$ +{} $T$} |
|
478 |
child {node {3}} |
|
479 |
child {node {4}} |
|
480 |
} |
|
481 |
}} |
|
482 |
}}; |
|
483 |
\end{tikzpicture} |
|
484 |
\end{center} |
|
485 |
||
486 |
\begin{textblock}{5}(1, 6.5) |
|
487 |
\bl{\texttt{(2*3)+(3+4)}} |
|
488 |
\end{textblock} |
|
489 |
||
490 |
\end{frame}} |
|
491 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
492 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
493 |
\mode<presentation>{ |
|
494 |
\begin{frame}[c] |
|
495 |
\frametitle{\begin{tabular}{c}Ambiguous Grammars\end{tabular}} |
|
496 |
||
497 |
A CFG is \alert{ambiguous} if there is a string that has at least parse trees. |
|
498 |
||
499 |
||
500 |
\begin{center} |
|
501 |
\bl{\begin{tabular}{lcl} |
|
502 |
$E$ & $\rightarrow$ & $num\_token$ \\ |
|
503 |
$E$ & $\rightarrow$ & $E \cdot + \cdot E$ \\ |
|
504 |
$E$ & $\rightarrow$ & $E \cdot - \cdot E$ \\ |
|
505 |
$E$ & $\rightarrow$ & $E \cdot * \cdot E$ \\ |
|
506 |
$E$ & $\rightarrow$ & $( \cdot E \cdot )$ |
|
507 |
\end{tabular}} |
|
508 |
\end{center} |
|
509 |
||
510 |
\bl{\texttt{1 + 2 * 3 + 4}} |
|
511 |
||
512 |
\end{frame}} |
|
513 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
514 |
||
515 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
516 |
\mode<presentation>{ |
|
517 |
\begin{frame}[c] |
|
518 |
\frametitle{\begin{tabular}{c}Dangling Else\end{tabular}} |
|
519 |
||
520 |
Another ambiguous grammar:\bigskip |
|
521 |
||
522 |
\begin{center} |
|
523 |
\bl{\begin{tabular}{lcl} |
|
524 |
$E$ & $\rightarrow$ & if $E$ then $E$\\ |
|
525 |
& $|$ & if $E$ then $E$ else $E$ \\ |
|
526 |
& $|$ & id |
|
527 |
\end{tabular}} |
|
528 |
\end{center}\bigskip |
|
529 |
||
530 |
\bl{\texttt{if a then if x then y else c}} |
|
531 |
||
532 |
\end{frame}} |
|
533 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
534 |
||
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
535 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
536 |
\mode<presentation>{ |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
537 |
\begin{frame}[c] |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
538 |
\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
|
539 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
540 |
\begin{enumerate} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
541 |
\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
|
542 |
\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
|
543 |
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
|
544 |
\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
|
545 |
\end{enumerate} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
546 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
547 |
\begin{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
548 |
\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
|
549 |
\end{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
550 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
551 |
\end{frame}} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
552 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
553 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
554 |
|
63 | 555 |
\end{document} |
556 |
||
557 |
%%% Local Variables: |
|
558 |
%%% mode: latex |
|
559 |
%%% TeX-master: t |
|
560 |
%%% End: |
|
561 |