author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Mon, 11 Nov 2013 23:24:38 +0000 | |
changeset 185 | ea8b94d4755e |
parent 184 | 2e9134d25a2b |
child 186 | fab34204d08e |
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>{ |
|
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
155 |
\begin{frame}[c] |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
156 |
\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
|
157 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
158 |
A grammar for arithmetic expressions and numbers: |
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 |
\begin{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
161 |
\bl{\begin{tabular}{lcl} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
162 |
$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
|
163 |
$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
|
164 |
\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
165 |
\end{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
166 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
167 |
Unfortunately left-recursive (and ambiguous).\medskip\\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
168 |
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
|
169 |
\bigskip\pause |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
170 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
171 |
\end{frame}} |
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 |
|
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 |
\mode<presentation>{ |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
177 |
\begin{frame}[t] |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
178 |
\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
|
179 |
|
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
180 |
|
184
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 |
\begin{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
183 |
\bl{\begin{tabular}{lcl} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
184 |
$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
|
185 |
\end{tabular}} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
186 |
\end{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
187 |
|
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
188 |
A non-left-recursive, non-ambiguous grammar for numbers |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
189 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
190 |
\begin{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
191 |
\bl{\begin{tabular}{lcl} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
192 |
$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
|
193 |
\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
194 |
\end{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
195 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
196 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
197 |
\end{frame}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
198 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
199 |
|
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
200 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
201 |
\mode<presentation>{ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
202 |
\begin{frame}[c] |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
203 |
\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
|
204 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
205 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
206 |
To disambiguate |
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 |
\begin{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
209 |
\bl{\begin{tabular}{lcl} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
210 |
$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
|
211 |
\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
212 |
\end{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
213 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
214 |
Decide how many precedence levels, say\medskip\\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
215 |
\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
|
216 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
217 |
\begin{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
218 |
\bl{\begin{tabular}{lcl} |
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
219 |
$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
|
220 |
$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
|
221 |
$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
|
222 |
\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
223 |
\end{center}\pause |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
224 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
225 |
\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
|
226 |
\end{frame}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
227 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
228 |
|
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 |
\mode<presentation>{ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
231 |
\begin{frame}[c] |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
232 |
\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
|
233 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
234 |
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
|
235 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
236 |
\begin{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
237 |
\bl{\begin{tabular}{lcl} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
238 |
$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
|
239 |
\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
240 |
\end{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
241 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
242 |
Translate |
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 |
\begin{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
245 |
\begin{tabular}{ccc} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
246 |
\bl{\begin{tabular}{lcl} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
247 |
$N$ & $\rightarrow$ & $N \cdot \alpha$\\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
248 |
& $\;|\;$ & $\beta$\\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
249 |
\\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
250 |
\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
251 |
& {\Large$\Rightarrow$} & |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
252 |
\bl{\begin{tabular}{lcl} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
253 |
$N$ & $\rightarrow$ & $\beta \cdot N'$\\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
254 |
$N'$ & $\rightarrow$ & $\alpha \cdot N'$\\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
255 |
& $\;|\;$ & $\epsilon$ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
256 |
\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
257 |
\end{tabular} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
258 |
\end{center}\pause |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
259 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
260 |
Which means |
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 |
\begin{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
263 |
\bl{\begin{tabular}{lcl} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
264 |
$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
|
265 |
$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
|
266 |
\end{tabular}} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
267 |
\end{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
268 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
269 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
270 |
\end{frame}} |
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 |
|
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 |
\mode<presentation>{ |
63 | 275 |
\begin{frame}[c] |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
276 |
\frametitle{\begin{tabular}{c}Chomsky Normal Form\end{tabular}} |
63 | 277 |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
278 |
All rules must be of the form |
63 | 279 |
|
280 |
\begin{center} |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
281 |
\bl{$A \rightarrow a$} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
282 |
\end{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
283 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
284 |
or |
63 | 285 |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
286 |
\begin{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
287 |
\bl{$A \rightarrow B\cdot C$} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
288 |
\end{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
289 |
|
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
290 |
No rule can contain \bl{$\epsilon$}. |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
291 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
292 |
\end{frame}} |
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 |
|
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 |
\mode<presentation>{ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
297 |
\begin{frame}[c] |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
298 |
\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
|
299 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
300 |
\begin{enumerate} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
301 |
\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
|
302 |
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
|
303 |
\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
|
304 |
\end{enumerate} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
305 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
306 |
\small |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
307 |
\begin{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
308 |
\begin{tabular}{ccc} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
309 |
\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
|
310 |
$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
|
311 |
$N'$ & $\rightarrow$ & $N \cdot N'\;|\;\epsilon$ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
312 |
\end{tabular}} & |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
313 |
\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
|
314 |
$N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1\cdot N'\;|\;0\;|\;1$\\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
315 |
$N'$ & $\rightarrow$ & $N \cdot N'\;|\;N\;|\;\epsilon$ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
316 |
\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
317 |
\end{tabular} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
318 |
\end{center} |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
319 |
|
63 | 320 |
|
321 |
\end{frame}} |
|
322 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
323 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
324 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
325 |
|
63 | 326 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
327 |
\mode<presentation>{ |
|
328 |
\begin{frame}[c] |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
329 |
\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
|
330 |
|
63 | 331 |
|
332 |
\begin{center} |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
333 |
\bl{\begin{tabular}{@ {}lcl} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
334 |
$S$ & $\rightarrow$ & $N\cdot P$ \\ |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
335 |
$P$ & $\rightarrow$ & $V\cdot N$ \\ |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
336 |
$N$ & $\rightarrow$ & $N\cdot N$ \\ |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
337 |
$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
|
338 |
$V$ & $\rightarrow$ & $\texttt{trains}$ |
63 | 339 |
\end{tabular}} |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
340 |
\end{center} |
63 | 341 |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
342 |
\bl{\texttt{Jeff trains geometry students}} |
63 | 343 |
|
344 |
\end{frame}} |
|
345 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
346 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
347 |
\mode<presentation>{ |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
348 |
\begin{frame}[c] |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
349 |
\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
|
350 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
351 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
352 |
\begin{itemize} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
353 |
\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
|
354 |
\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
|
355 |
\end{itemize} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
356 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
357 |
\end{frame}} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
358 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
63 | 359 |
|
360 |
||
361 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
362 |
\mode<presentation>{ |
|
363 |
\begin{frame}[c] |
|
364 |
\frametitle{\begin{tabular}{c}Parse Trees\end{tabular}} |
|
365 |
||
366 |
\begin{center} |
|
367 |
\bl{\begin{tabular}{lcl} |
|
368 |
$E$ & $\rightarrow$ & $F \;|\; F \cdot * \cdot F$\\ |
|
369 |
$F$ & $\rightarrow$ & $T \;|\; T \cdot + \cdot T \;|\; T \cdot - \cdot T$\\ |
|
370 |
$T$ & $\rightarrow$ & $num\_token \;|\; ( \cdot E \cdot )$\\ |
|
371 |
\end{tabular}} |
|
372 |
\end{center} |
|
373 |
||
374 |
\begin{center} |
|
375 |
\begin{tikzpicture}[level distance=8mm, blue] |
|
376 |
\node {$E$} |
|
377 |
child {node {$F$} |
|
378 |
child {node {$T$} |
|
379 |
child {node {(\,$E$\,)} |
|
380 |
child {node{$F$ *{} $F$} |
|
381 |
child {node {$T$} child {node {2}}} |
|
382 |
child {node {$T$} child {node {3}}} |
|
383 |
} |
|
384 |
} |
|
385 |
} |
|
386 |
child {node {+}} |
|
387 |
child {node {$T$} |
|
388 |
child {node {(\,$E$\,)} |
|
389 |
child {node {$F$} |
|
390 |
child {node {$T$ +{} $T$} |
|
391 |
child {node {3}} |
|
392 |
child {node {4}} |
|
393 |
} |
|
394 |
}} |
|
395 |
}}; |
|
396 |
\end{tikzpicture} |
|
397 |
\end{center} |
|
398 |
||
399 |
\begin{textblock}{5}(1, 6.5) |
|
400 |
\bl{\texttt{(2*3)+(3+4)}} |
|
401 |
\end{textblock} |
|
402 |
||
403 |
\end{frame}} |
|
404 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
405 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
406 |
\mode<presentation>{ |
|
407 |
\begin{frame}[c] |
|
408 |
\frametitle{\begin{tabular}{c}Ambiguous Grammars\end{tabular}} |
|
409 |
||
410 |
A CFG is \alert{ambiguous} if there is a string that has at least parse trees. |
|
411 |
||
412 |
||
413 |
\begin{center} |
|
414 |
\bl{\begin{tabular}{lcl} |
|
415 |
$E$ & $\rightarrow$ & $num\_token$ \\ |
|
416 |
$E$ & $\rightarrow$ & $E \cdot + \cdot E$ \\ |
|
417 |
$E$ & $\rightarrow$ & $E \cdot - \cdot E$ \\ |
|
418 |
$E$ & $\rightarrow$ & $E \cdot * \cdot E$ \\ |
|
419 |
$E$ & $\rightarrow$ & $( \cdot E \cdot )$ |
|
420 |
\end{tabular}} |
|
421 |
\end{center} |
|
422 |
||
423 |
\bl{\texttt{1 + 2 * 3 + 4}} |
|
424 |
||
425 |
\end{frame}} |
|
426 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
427 |
||
428 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
429 |
\mode<presentation>{ |
|
430 |
\begin{frame}[c] |
|
431 |
\frametitle{\begin{tabular}{c}Dangling Else\end{tabular}} |
|
432 |
||
433 |
Another ambiguous grammar:\bigskip |
|
434 |
||
435 |
\begin{center} |
|
436 |
\bl{\begin{tabular}{lcl} |
|
437 |
$E$ & $\rightarrow$ & if $E$ then $E$\\ |
|
438 |
& $|$ & if $E$ then $E$ else $E$ \\ |
|
439 |
& $|$ & id |
|
440 |
\end{tabular}} |
|
441 |
\end{center}\bigskip |
|
442 |
||
443 |
\bl{\texttt{if a then if x then y else c}} |
|
444 |
||
445 |
\end{frame}} |
|
446 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
447 |
||
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
448 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
449 |
\mode<presentation>{ |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
450 |
\begin{frame}[c] |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
451 |
\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
|
452 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
453 |
\begin{enumerate} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
454 |
\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
|
455 |
\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
|
456 |
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
|
457 |
\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
|
458 |
\end{enumerate} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
459 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
460 |
\begin{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
461 |
\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
|
462 |
\end{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
463 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
464 |
\end{frame}} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
465 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
466 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
467 |
|
63 | 468 |
\end{document} |
469 |
||
470 |
%%% Local Variables: |
|
471 |
%%% mode: latex |
|
472 |
%%% TeX-master: t |
|
473 |
%%% End: |
|
474 |