author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Tue, 19 Nov 2013 23:44:49 +0000 | |
changeset 197 | 6622bd256029 |
parent 188 | 12ef150273ce |
child 215 | 828303e8e4af |
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} |
|
188
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
23 |
\usepackage{pgfplots} |
63 | 24 |
|
25 |
\definecolor{javared}{rgb}{0.6,0,0} % for strings |
|
26 |
\definecolor{javagreen}{rgb}{0.25,0.5,0.35} % comments |
|
27 |
\definecolor{javapurple}{rgb}{0.5,0,0.35} % keywords |
|
28 |
\definecolor{javadocblue}{rgb}{0.25,0.35,0.75} % javadoc |
|
29 |
||
30 |
\lstset{language=Java, |
|
31 |
basicstyle=\ttfamily, |
|
32 |
keywordstyle=\color{javapurple}\bfseries, |
|
33 |
stringstyle=\color{javagreen}, |
|
34 |
commentstyle=\color{javagreen}, |
|
35 |
morecomment=[s][\color{javadocblue}]{/**}{*/}, |
|
36 |
numbers=left, |
|
37 |
numberstyle=\tiny\color{black}, |
|
38 |
stepnumber=1, |
|
39 |
numbersep=10pt, |
|
40 |
tabsize=2, |
|
41 |
showspaces=false, |
|
42 |
showstringspaces=false} |
|
43 |
||
44 |
\lstdefinelanguage{scala}{ |
|
45 |
morekeywords={abstract,case,catch,class,def,% |
|
46 |
do,else,extends,false,final,finally,% |
|
47 |
for,if,implicit,import,match,mixin,% |
|
48 |
new,null,object,override,package,% |
|
49 |
private,protected,requires,return,sealed,% |
|
50 |
super,this,throw,trait,true,try,% |
|
51 |
type,val,var,while,with,yield}, |
|
52 |
otherkeywords={=>,<-,<\%,<:,>:,\#,@}, |
|
53 |
sensitive=true, |
|
54 |
morecomment=[l]{//}, |
|
55 |
morecomment=[n]{/*}{*/}, |
|
56 |
morestring=[b]", |
|
57 |
morestring=[b]', |
|
58 |
morestring=[b]""" |
|
59 |
} |
|
60 |
||
61 |
\lstset{language=Scala, |
|
62 |
basicstyle=\ttfamily, |
|
63 |
keywordstyle=\color{javapurple}\bfseries, |
|
64 |
stringstyle=\color{javagreen}, |
|
65 |
commentstyle=\color{javagreen}, |
|
66 |
morecomment=[s][\color{javadocblue}]{/**}{*/}, |
|
67 |
numbers=left, |
|
68 |
numberstyle=\tiny\color{black}, |
|
69 |
stepnumber=1, |
|
70 |
numbersep=10pt, |
|
71 |
tabsize=2, |
|
72 |
showspaces=false, |
|
73 |
showstringspaces=false} |
|
74 |
||
188
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
75 |
\lstdefinelanguage{While}{ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
76 |
morekeywords={while, if, then. else, read, write}, |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
77 |
otherkeywords={=>,<-,<\%,<:,>:,\#,@}, |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
78 |
sensitive=true, |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
79 |
morecomment=[l]{//}, |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
80 |
morecomment=[n]{/*}{*/}, |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
81 |
morestring=[b]", |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
82 |
morestring=[b]', |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
83 |
morestring=[b]""" |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
84 |
} |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
85 |
|
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
86 |
|
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
87 |
\setmonofont{Consolas} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
88 |
|
188
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
89 |
\begin{filecontents}{interpreted.data} |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
90 |
%1 0.00503 |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
91 |
200 1.005863 |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
92 |
400 7.8296765 |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
93 |
500 15.43106 |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
94 |
600 27.2321885 |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
95 |
800 65.249271 |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
96 |
1000 135.4493445 |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
97 |
1200 232.134097 |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
98 |
1400 382.527227 |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
99 |
\end{filecontents} |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
100 |
|
63 | 101 |
% beamer stuff |
173
7cfb7a6f7c99
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
102 |
\renewcommand{\slidecaption}{AFL 07, King's College London, 13.~November 2013} |
63 | 103 |
\newcommand{\bl}[1]{\textcolor{blue}{#1}} |
104 |
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions |
|
105 |
||
106 |
\begin{document} |
|
107 |
||
108 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
109 |
\mode<presentation>{ |
|
110 |
\begin{frame}<1>[t] |
|
111 |
\frametitle{% |
|
112 |
\begin{tabular}{@ {}c@ {}} |
|
113 |
\\[-3mm] |
|
114 |
\LARGE Automata and \\[-2mm] |
|
115 |
\LARGE Formal Languages (7)\\[3mm] |
|
116 |
\end{tabular}} |
|
117 |
||
118 |
\normalsize |
|
119 |
\begin{center} |
|
120 |
\begin{tabular}{ll} |
|
121 |
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
|
122 |
Office: & S1.27 (1st floor Strand Building)\\ |
63 | 123 |
Slides: & KEATS (also home work is there)\\ |
124 |
\end{tabular} |
|
125 |
\end{center} |
|
126 |
||
127 |
||
128 |
\end{frame}} |
|
129 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
130 |
||
131 |
||
132 |
\newcommand{\qq}{\mbox{\texttt{"}}} |
|
133 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
134 |
\mode<presentation>{ |
|
135 |
\begin{frame}[c] |
|
186
fab34204d08e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
185
diff
changeset
|
136 |
\frametitle{\begin{tabular}{c}Two Weeks Ago: CFGs\end{tabular}} |
63 | 137 |
|
64
2d625418c011
added everything
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
63
diff
changeset
|
138 |
A \alert{context-free} grammar (CFG) \bl{$G$} consists of: |
63 | 139 |
|
140 |
\begin{itemize} |
|
141 |
\item a finite set of nonterminal symbols (upper case) |
|
142 |
\item a finite terminal symbols or tokens (lower case) |
|
143 |
\item a start symbol (which must be a nonterminal) |
|
144 |
\item a set of rules |
|
145 |
\begin{center} |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
146 |
\bl{$A \rightarrow \text{rhs}_1 | \text{rhs}_2 | \ldots$} |
63 | 147 |
\end{center} |
148 |
||
149 |
where \bl{rhs} are sequences involving terminals and nonterminals (can also be empty).\medskip\pause |
|
150 |
||
151 |
\end{itemize} |
|
152 |
||
153 |
\end{frame}} |
|
154 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
155 |
||
156 |
||
157 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
158 |
\mode<presentation>{ |
|
159 |
\begin{frame}[c] |
|
186
fab34204d08e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
185
diff
changeset
|
160 |
\frametitle{\begin{tabular}{c}Hierarchy of Languages\end{tabular}} |
63 | 161 |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
162 |
Recall that languages are sets of strings. |
63 | 163 |
|
164 |
\begin{center} |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
165 |
\begin{tikzpicture} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
166 |
[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
|
167 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
168 |
\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
|
169 |
\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
|
170 |
\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
|
171 |
\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
|
172 |
\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
|
173 |
\end{tikzpicture} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
174 |
|
63 | 175 |
\end{center} |
176 |
||
177 |
\end{frame}} |
|
178 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
179 |
||
180 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
181 |
\mode<presentation>{ |
|
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
182 |
\begin{frame}[c] |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
183 |
\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
|
184 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
185 |
A grammar for arithmetic expressions and numbers: |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
186 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
187 |
\begin{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
188 |
\bl{\begin{tabular}{lcl} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
189 |
$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
|
190 |
$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
|
191 |
\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
192 |
\end{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
193 |
|
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
194 |
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
|
195 |
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
|
196 |
\bigskip\pause |
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 |
\end{frame}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
199 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
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 |
|
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>{ |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
204 |
\begin{frame}[t] |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
205 |
\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
|
206 |
|
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
207 |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
208 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
209 |
\begin{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
210 |
\bl{\begin{tabular}{lcl} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
211 |
$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
|
212 |
\end{tabular}} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
213 |
\end{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
214 |
|
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
215 |
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
|
216 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
217 |
\begin{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
218 |
\bl{\begin{tabular}{lcl} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
219 |
$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
|
220 |
\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
221 |
\end{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
222 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
223 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
224 |
\end{frame}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
225 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
226 |
|
185
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 |
\mode<presentation>{ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
229 |
\begin{frame}[c] |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
230 |
\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
|
231 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
232 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
233 |
To disambiguate |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
234 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
235 |
\begin{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
236 |
\bl{\begin{tabular}{lcl} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
237 |
$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
|
238 |
\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
239 |
\end{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
240 |
|
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
241 |
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
|
242 |
\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
|
243 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
244 |
\begin{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
245 |
\bl{\begin{tabular}{lcl} |
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
246 |
$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
|
247 |
$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
|
248 |
$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
|
249 |
\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
250 |
\end{center}\pause |
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 |
\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
|
253 |
\end{frame}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
254 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
255 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
256 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
257 |
\mode<presentation>{ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
258 |
\begin{frame}[c] |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
259 |
\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
|
260 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
261 |
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
|
262 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
263 |
\begin{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
264 |
\bl{\begin{tabular}{lcl} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
265 |
$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
|
266 |
\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
267 |
\end{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
268 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
269 |
Translate |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
270 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
271 |
\begin{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
272 |
\begin{tabular}{ccc} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
273 |
\bl{\begin{tabular}{lcl} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
274 |
$N$ & $\rightarrow$ & $N \cdot \alpha$\\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
275 |
& $\;|\;$ & $\beta$\\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
276 |
\\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
277 |
\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
278 |
& {\Large$\Rightarrow$} & |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
279 |
\bl{\begin{tabular}{lcl} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
280 |
$N$ & $\rightarrow$ & $\beta \cdot N'$\\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
281 |
$N'$ & $\rightarrow$ & $\alpha \cdot N'$\\ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
282 |
& $\;|\;$ & $\epsilon$ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
283 |
\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
284 |
\end{tabular} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
285 |
\end{center}\pause |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
286 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
287 |
Which means |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
288 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
289 |
\begin{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
290 |
\bl{\begin{tabular}{lcl} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
291 |
$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
|
292 |
$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
|
293 |
\end{tabular}} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
294 |
\end{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
295 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
296 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
297 |
\end{frame}} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
298 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
299 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
300 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
301 |
\mode<presentation>{ |
63 | 302 |
\begin{frame}[c] |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
303 |
\frametitle{\begin{tabular}{c}Chomsky Normal Form\end{tabular}} |
63 | 304 |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
305 |
All rules must be of the form |
63 | 306 |
|
307 |
\begin{center} |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
308 |
\bl{$A \rightarrow a$} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
309 |
\end{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
310 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
311 |
or |
63 | 312 |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
313 |
\begin{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
314 |
\bl{$A \rightarrow B\cdot C$} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
315 |
\end{center} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
316 |
|
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
317 |
No rule can contain \bl{$\epsilon$}. |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
318 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
319 |
\end{frame}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
320 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
321 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
322 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
323 |
\mode<presentation>{ |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
324 |
\begin{frame}[c] |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
325 |
\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
|
326 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
327 |
\begin{enumerate} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
328 |
\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
|
329 |
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
|
330 |
\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
|
331 |
\end{enumerate} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
332 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
333 |
\small |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
334 |
\begin{center} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
335 |
\begin{tabular}{ccc} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
336 |
\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
|
337 |
$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
|
338 |
$N'$ & $\rightarrow$ & $N \cdot N'\;|\;\epsilon$\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
339 |
\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
340 |
\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
341 |
\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
342 |
\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
343 |
\\ |
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
344 |
\end{tabular}} & |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
345 |
\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
|
346 |
\\ |
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
347 |
$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
|
348 |
$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
|
349 |
\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
350 |
$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
|
351 |
$N'$ & $\rightarrow$ & $N \cdot N'\;|\;N$\\ |
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
352 |
\end{tabular}} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
353 |
\end{tabular} |
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
354 |
\end{center} |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
355 |
|
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
356 |
\pause\normalsize |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
357 |
\begin{center} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
358 |
\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
|
359 |
$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
|
360 |
\end{tabular}} |
63 | 361 |
|
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
362 |
\end{center} |
63 | 363 |
\end{frame}} |
364 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
185
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
365 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
366 |
|
ea8b94d4755e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
367 |
|
63 | 368 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
369 |
\mode<presentation>{ |
|
370 |
\begin{frame}[c] |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
371 |
\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
|
372 |
|
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
373 |
If grammar is in Chomsky normalform \ldots |
63 | 374 |
|
375 |
\begin{center} |
|
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
376 |
\bl{\begin{tabular}{@ {}lcl@ {}} |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
377 |
$S$ & $\rightarrow$ & $N\cdot P$ \\ |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
378 |
$P$ & $\rightarrow$ & $V\cdot N$ \\ |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
379 |
$N$ & $\rightarrow$ & $N\cdot N$ \\ |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
380 |
$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
|
381 |
$V$ & $\rightarrow$ & $\texttt{trains}$ |
63 | 382 |
\end{tabular}} |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
383 |
\end{center} |
63 | 384 |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
385 |
\bl{\texttt{Jeff trains geometry students}} |
63 | 386 |
|
387 |
\end{frame}} |
|
388 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
389 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
390 |
\mode<presentation>{ |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
391 |
\begin{frame}[c] |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
392 |
\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
|
393 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
394 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
395 |
\begin{itemize} |
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
396 |
\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
|
397 |
\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
|
398 |
\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
|
399 |
\end{itemize} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
400 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
401 |
\end{frame}} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
402 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
63 | 403 |
|
404 |
||
405 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
406 |
\mode<presentation>{ |
|
407 |
\begin{frame}[c] |
|
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
408 |
\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
|
409 |
|
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
410 |
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
|
411 |
|
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
412 |
\begin{center} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
413 |
\begin{tikzpicture} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
414 |
[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
|
415 |
|
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
416 |
\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
|
417 |
\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
|
418 |
\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
|
419 |
\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
|
420 |
\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
|
421 |
\end{tikzpicture} |
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 |
\end{center} |
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 |
\end{frame}} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
426 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
427 |
|
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
428 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
429 |
\mode<presentation>{ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
430 |
\begin{frame}[c] |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
431 |
\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
|
432 |
|
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
433 |
|
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
434 |
\begin{center} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
435 |
\bl{\begin{tabular}{lcl} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
436 |
$S$ & $\Rightarrow$ & $bSAA\;|\; \epsilon$\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
437 |
$A$ & $\Rightarrow$ & $a$\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
438 |
$bA$ & $\Rightarrow$ & $Ab$\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
439 |
\end{tabular}} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
440 |
\end{center}\pause |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
441 |
|
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
442 |
\begin{center} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
443 |
\bl{$S \Rightarrow\ldots\Rightarrow^? "ababaa"$} |
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 |
|
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
446 |
\end{frame}} |
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 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
450 |
\mode<presentation>{ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
451 |
\begin{frame}[c] |
188
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
452 |
|
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
453 |
\begin{center} |
188
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
454 |
\bl{\begin{tabular}{@{}lcl@{}} |
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
455 |
\textit{Stmt} & $\rightarrow$ & $\texttt{skip}$\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
456 |
& $|$ & \textit{Id}\;\texttt{:=}\;\textit{AExp}\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
457 |
& $|$ & \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
|
458 |
& $|$ & \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
|
459 |
& $|$ & \texttt{read}\;\textit{Id}\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
460 |
& $|$ & \texttt{write}\;\textit{Id}\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
461 |
& $|$ & \texttt{write}\;\textit{String}\medskip\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
462 |
\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
|
463 |
& $|$ & \textit{Stmt}\medskip\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
464 |
\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
|
465 |
& $|$ & \textit{Stmt}\medskip\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
466 |
\textit{AExp} & $\rightarrow$ & \ldots\\ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
467 |
\textit{BExp} & $\rightarrow$ & \ldots\\ |
188
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
468 |
\end{tabular}} |
187
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
469 |
\end{center} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
470 |
\end{frame}} |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
471 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
472 |
|
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
473 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
474 |
\mode<presentation>{ |
9471a0325773
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
186
diff
changeset
|
475 |
\begin{frame}[c] |
188
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
476 |
|
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
477 |
\mbox{\lstinputlisting[language=while]{../progs/fib.while}} |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
478 |
|
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
479 |
\end{frame}} |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
480 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
481 |
|
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
482 |
|
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
483 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
484 |
\mode<presentation>{ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
485 |
\begin{frame}[c] |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
486 |
\frametitle{\begin{tabular}{c}An Interpreter\end{tabular}} |
63 | 487 |
|
488 |
\begin{center} |
|
188
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
489 |
\bl{\begin{tabular}{l} |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
490 |
$\{$\\ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
491 |
\;\;$x := 5 \text{;}$\\ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
492 |
\;\;$y := x * 3\text{;}$\\ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
493 |
\;\;$y := x * 4\text{;}$\\ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
494 |
\;\;$x := u * 3$\\ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
495 |
$\}$ |
63 | 496 |
\end{tabular}} |
497 |
\end{center} |
|
498 |
||
188
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
499 |
\begin{itemize} |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
500 |
\item the interpreter has to record the value of \bl{$x$} before assigning a value to \bl{$y$}\pause |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
501 |
\item \bl{\text{eval}(stmt, env)} |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
502 |
\end{itemize} |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
503 |
|
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
504 |
|
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
505 |
\end{frame}} |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
506 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
507 |
|
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
508 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
509 |
\mode<presentation>{ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
510 |
\begin{frame}[c] |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
511 |
\frametitle{\begin{tabular}{c}Interpreter\end{tabular}} |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
512 |
|
63 | 513 |
\begin{center} |
188
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
514 |
\bl{\begin{tabular}{@{}lcl@{}} |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
515 |
$\text{eval}(n, E)$ & $\dn$ & $n$\\ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
516 |
$\text{eval}(x, E)$ & $\dn$ & $E(x)$ \;\;\;\textcolor{black}{lookup \bl{$x$} in \bl{$E$}}\\ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
517 |
$\text{eval}(a_1 + a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) + \text{eval}(a_2, E)$\\ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
518 |
$\text{eval}(a_1 - a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) - \text{eval}(a_2, E)$\\ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
519 |
$\text{eval}(a_1 * a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) * \text{eval}(a_2, E)$\bigskip\\ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
520 |
$\text{eval}(a_1 = a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) = \text{eval}(a_2, E)$\\ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
521 |
$\text{eval}(a_1\,!\!= a_2, E)$ & $\dn$ & $\neg(\text{eval}(a_1, E) = \text{eval}(a_2, E))$\\ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
522 |
$\text{eval}(a_1 < a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) < \text{eval}(a_2, E)$\ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
523 |
\end{tabular}} |
63 | 524 |
\end{center} |
525 |
||
526 |
\end{frame}} |
|
527 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
528 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
529 |
\mode<presentation>{ |
|
530 |
\begin{frame}[c] |
|
188
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
531 |
\frametitle{\begin{tabular}{c}Interpreter (2)\end{tabular}} |
63 | 532 |
|
533 |
\begin{center} |
|
188
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
534 |
\bl{\begin{tabular}{@{}lcl@{}} |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
535 |
$\text{eval}(\text{skip}, E)$ & $\dn$ & $E$\\ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
536 |
$\text{eval}(x:=a, E)$ & $\dn$ & \bl{$E(x \mapsto \text{eval}(a, E))$}\\ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
537 |
\multicolumn{3}{@{}l@{}}{$\text{eval}(\text{if}\;b\;\text{then}\;cs_1\;\text{else}\;cs_2 , E) \dn$}\\ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
538 |
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)\;\text{then}\; |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
539 |
\text{eval}(cs_1,E)$}\\ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
540 |
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\phantom{\text{if}\;\text{eval}(b,E)\;}\text{else}\;\text{eval}(cs_2,E)$}\\ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
541 |
\multicolumn{3}{@{}l@{}}{$\text{eval}(\text{while}\;b\;\text{do}\;cs, E) \dn$}\\ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
542 |
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)$}\\ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
543 |
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{then}\; |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
544 |
\text{eval}(\text{while}\;b\;\text{do}\;cs, \text{eval}(cs,E))$}\\ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
545 |
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{else}\; E$}\\ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
546 |
$\text{eval}(\text{write}\; x, E)$ & $\dn$ & $\{\;\text{println}(E(x))\; ;\;E\;\}$\\ |
63 | 547 |
\end{tabular}} |
548 |
\end{center} |
|
549 |
||
188
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
550 |
\end{frame}} |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
551 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
552 |
|
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
553 |
|
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
554 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
555 |
\mode<presentation>{ |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
556 |
\begin{frame}[c] |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
557 |
\frametitle{\begin{tabular}{c}Test Program\end{tabular}} |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
558 |
|
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
559 |
\mbox{}\\[-18mm]\mbox{} |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
560 |
|
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
561 |
{\lstset{language=While}%%\fontsize{10}{12}\selectfont |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
562 |
\texttt{\lstinputlisting{../progs/loops.while}}} |
63 | 563 |
|
564 |
\end{frame}} |
|
565 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
566 |
||
567 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
568 |
\mode<presentation>{ |
|
188
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
569 |
\begin{frame}[t] |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
570 |
\frametitle{\begin{tabular}{c}Interpreted Code\end{tabular}} |
63 | 571 |
|
572 |
\begin{center} |
|
188
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
573 |
\begin{tikzpicture} |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
574 |
\begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small] |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
575 |
\addplot+[smooth] file {interpreted.data}; |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
576 |
\end{axis} |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
577 |
\end{tikzpicture} |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
578 |
\end{center} |
63 | 579 |
|
580 |
\end{frame}} |
|
581 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
582 |
||
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
583 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
584 |
\mode<presentation>{ |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
585 |
\begin{frame}[c] |
188
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
586 |
\frametitle{\begin{tabular}{c}Java Virtual Machine\end{tabular}} |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
587 |
|
188
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
588 |
\begin{itemize} |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
589 |
\item introduced in 1995 |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
590 |
\item is a stack-based VM (like Postscript, CLR of .Net) |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
591 |
\item contains a JIT compiler |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
592 |
\item many languages take advantage of JVM's infrastructure (JRE) |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
593 |
\item is garbage collected $\Rightarrow$ no buffer overflows |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
594 |
\item some languages compile to the JVM: Scala, Clojure\ldots |
12ef150273ce
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
187
diff
changeset
|
595 |
\end{itemize} |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
596 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
597 |
\end{frame}} |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
598 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
599 |
|
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
173
diff
changeset
|
600 |
|
63 | 601 |
\end{document} |
602 |
||
603 |
%%% Local Variables: |
|
604 |
%%% mode: latex |
|
605 |
%%% TeX-master: t |
|
606 |
%%% End: |
|
607 |