author | Christian Urban <christian.urban@kcl.ac.uk> |
Sat, 11 Nov 2023 10:08:33 +0000 | |
changeset 954 | eda0ccf56c72 |
parent 940 | 46eee459a999 |
child 972 | ebb4a40d9bae |
permissions | -rw-r--r-- |
666 | 1 |
% !TEX program = xelatex |
744 | 2 |
\documentclass[dvipsnames,14pt,t,xelatex,aspectratio=169,xcolor={table}]{beamer} |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
3 |
\usepackage{../slides} |
871 | 4 |
\usepackage{../graphicss} |
215
828303e8e4af
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
5 |
\usepackage{../langs} |
828303e8e4af
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
6 |
\usepackage{../data} |
597 | 7 |
\usepackage{../grammar} |
49 | 8 |
|
9 |
% beamer stuff |
|
445 | 10 |
\renewcommand{\slidecaption}{CFL 06, King's College London} |
11 |
||
12 |
||
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
13 |
\newcommand{\bl}[1]{\textcolor{blue}{#1}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
14 |
%\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions |
366
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
15 |
\newcommand{\qq}{\mbox{\texttt{"}}} |
49 | 16 |
|
809 | 17 |
\usepackage{tcolorbox} |
18 |
\newtcolorbox{mybox}{colback=red!5!white,colframe=red!75!black} |
|
19 |
\newtcolorbox{mybox2}[1]{colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries,title=#1} |
|
20 |
\newtcolorbox{mybox3}[1]{colback=Cyan!5!white,colframe=Cyan!75!black,fonttitle=\bfseries,title=#1} |
|
21 |
||
22 |
||
23 |
||
49 | 24 |
\begin{document} |
25 |
||
26 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
27 |
\begin{frame}[t] |
49 | 28 |
\frametitle{% |
29 |
\begin{tabular}{@ {}c@ {}} |
|
30 |
\\[-3mm] |
|
895 | 31 |
\LARGE Compilers and \\[-1mm] |
32 |
\LARGE Formal Languages\\[-5mm] |
|
49 | 33 |
\end{tabular}} |
34 |
||
35 |
\normalsize |
|
36 |
\begin{center} |
|
37 |
\begin{tabular}{ll} |
|
940 | 38 |
Email: & christian.urban at kcl.ac.uk\\ |
39 |
Office Hour: & Thurdays 15 -- 16\\ |
|
895 | 40 |
Location: & N7.07 (North Wing, Bush House)\\ |
41 |
Slides \& Progs: & KEATS\\ |
|
42 |
Pollev: & \texttt{\alert{https://pollev.com/cfltutoratki576}}\\ |
|
49 | 43 |
\end{tabular} |
44 |
\end{center} |
|
45 |
||
744 | 46 |
\begin{center} |
47 |
\begin{tikzpicture} |
|
48 |
\node[drop shadow,fill=white,inner sep=0pt] |
|
49 |
{\footnotesize\rowcolors{1}{capri!10}{white} |
|
50 |
\begin{tabular}{|p{4.8cm}|p{4.8cm}|}\hline |
|
51 |
1 Introduction, Languages & \cellcolor{blue!50} 6 While-Language \\ |
|
52 |
2 Regular Expressions, Derivatives & 7 Compilation, JVM \\ |
|
53 |
3 Automata, Regular Languages & 8 Compiling Functional Languages \\ |
|
54 |
4 Lexing, Tokenising & 9 Optimisations \\ |
|
55 |
5 Grammars, Parsing & 10 LLVM \\ \hline |
|
56 |
\end{tabular}% |
|
57 |
}; |
|
58 |
\end{tikzpicture} |
|
59 |
\end{center} |
|
60 |
||
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
61 |
\end{frame} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
62 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
49 | 63 |
|
849 | 64 |
|
65 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
66 |
\begin{frame}[c] |
|
67 |
\frametitle{Parser Combinators} |
|
68 |
||
69 |
One of the simplest ways to implement a parser, see |
|
70 |
{\small\url{https://vimeo.com/142341803}} (by Haoyi Li)\bigskip |
|
71 |
||
72 |
\begin{itemize} |
|
895 | 73 |
\item[$\bullet$] built-in library in Scala |
849 | 74 |
\item[$\bullet$] fastparse (2) library by Haoyi Li; is part of Ammonite |
75 |
\item[$\bullet$] possible exponential runtime behaviour |
|
76 |
\end{itemize} |
|
77 |
||
78 |
\end{frame} |
|
79 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
80 |
||
81 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
954 | 82 |
\begin{frame}[t] |
83 |
\frametitle{Palindromes} |
|
84 |
||
85 |
A grammar for palindromes over the alphabet~\bl{$\{a,b\}$}: |
|
86 |
||
87 |
\only<1>{% |
|
88 |
\bl{\begin{plstx}[margin=1cm] |
|
89 |
: \meta{S} ::= a\cdot \meta{S}\cdot a | b\cdot \meta{S}\cdot b | a | b | \epsilon\\ |
|
90 |
\end{plstx}}} |
|
91 |
||
92 |
%\small |
|
93 |
%Can you find the grammar rules for matched parentheses? |
|
94 |
||
95 |
\end{frame} |
|
96 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
97 |
||
98 |
||
99 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
849 | 100 |
\begin{frame}[c] |
101 |
\frametitle{Parser Combinators} |
|
102 |
||
103 |
Parser combinators: \bigskip |
|
104 |
||
105 |
\begin{minipage}{1.1\textwidth} |
|
106 |
\begin{center} |
|
107 |
\mbox{}\hspace{-12mm}\mbox{}$\underbrace{\text{list of tokens}}_{\text{input}}$ \bl{$\Rightarrow$} |
|
108 |
$\underbrace{\text{set of (parsed input, unparsed input)}}_{\text{output}}$ |
|
109 |
\end{center} |
|
110 |
\end{minipage}\bigskip |
|
111 |
||
112 |
\begin{itemize} |
|
113 |
\item atomic parsers |
|
114 |
\item sequencing |
|
115 |
\item alternative |
|
116 |
\item semantic action (map-parser) |
|
117 |
\end{itemize} |
|
118 |
||
119 |
\end{frame} |
|
120 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
121 |
||
122 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
123 |
\begin{frame}[c] |
|
954 | 124 |
\frametitle{Abstract Parser Class} |
125 |
||
126 |
\small |
|
127 |
\lstinputlisting[language=Scala,xleftmargin=1mm] |
|
128 |
{../progs/app7.scala} |
|
129 |
\end{frame} |
|
130 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
131 |
||
132 |
||
133 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
134 |
\begin{frame}[c] |
|
849 | 135 |
|
136 |
Atomic parsers, for example, number tokens |
|
137 |
||
138 |
\begin{center} |
|
139 |
\bl{$\texttt{Num(123)}::rest \;\Rightarrow\; \{(\texttt{Num(123)}, rest)\}$} |
|
140 |
\end{center}\bigskip |
|
141 |
||
142 |
\begin{itemize} |
|
143 |
\item you consume one or more token from the\\ |
|
144 |
input (stream) |
|
145 |
\item also works for characters and strings |
|
146 |
\end{itemize} |
|
147 |
\end{frame} |
|
148 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
149 |
||
150 |
||
151 |
||
152 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
153 |
\begin{frame}[c] |
|
154 |
||
155 |
Alternative parser (code \bl{$p\;||\;q$})\bigskip |
|
156 |
||
157 |
\begin{itemize} |
|
158 |
\item apply \bl{$p$} and also \bl{$q$}; then combine |
|
159 |
the outputs |
|
160 |
\end{itemize} |
|
161 |
||
162 |
\begin{center} |
|
163 |
\large \bl{$p(\text{input}) \cup q(\text{input})$} |
|
164 |
\end{center} |
|
165 |
||
166 |
\end{frame} |
|
167 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
168 |
||
169 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
170 |
\begin{frame}[c] |
|
171 |
||
172 |
Sequence parser (code \bl{$p\sim q$})\bigskip |
|
173 |
||
174 |
\begin{itemize} |
|
175 |
\item apply first \bl{$p$} producing a set of pairs |
|
176 |
\item then apply \bl{$q$} to the unparsed parts |
|
177 |
\item then combine the results:\medskip |
|
178 |
\begin{center} |
|
179 |
((output$_1$, output$_2$), unparsed part) |
|
180 |
\end{center} |
|
181 |
\end{itemize} |
|
182 |
||
183 |
\begin{center} |
|
184 |
\begin{tabular}{l} |
|
185 |
\large \bl{$\{((o_1, o_2), u_2) \;|\;$}\\[2mm] |
|
186 |
\large\mbox{}\hspace{15mm} \bl{$(o_1, u_1) \in p(\text{input}) \wedge$}\\[2mm] |
|
187 |
\large\mbox{}\hspace{15mm} \bl{$(o_2, u_2) \in q(u_1)\}$} |
|
188 |
\end{tabular} |
|
189 |
\end{center} |
|
190 |
||
191 |
||
192 |
\end{frame} |
|
193 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
194 |
||
195 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
196 |
\begin{frame}[c] |
|
197 |
||
198 |
Map-parser (code \bl{$p.map(f)\;$})\bigskip |
|
199 |
||
200 |
\begin{itemize} |
|
201 |
\item apply \bl{$p$} producing a set of pairs |
|
202 |
\item then apply the function \bl{$f$} to each first component |
|
203 |
\end{itemize} |
|
204 |
||
205 |
\begin{center} |
|
206 |
\begin{tabular}{l} |
|
207 |
\large \bl{$\{(f(o_1), u_1) \;|\; (o_1, u_1) \in p(\text{input})\}$} |
|
208 |
\end{tabular} |
|
209 |
\end{center}\bigskip\bigskip\pause |
|
210 |
||
211 |
\bl{$f$} is the semantic action (``what to do with the parsed input'') |
|
212 |
||
213 |
\end{frame} |
|
214 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
215 |
||
216 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
217 |
\begin{frame}[c] |
|
218 |
\frametitle{\begin{tabular}{c}Semantic Actions\end{tabular}} |
|
219 |
||
220 |
Addition |
|
221 |
||
222 |
\begin{center} |
|
223 |
\bl{$\meta{T} \sim + \sim \meta{E} \Rightarrow \underbrace{f\,((x,y), z) \Rightarrow x + z}_{\text{semantic action}}$} |
|
224 |
\end{center}\pause |
|
225 |
||
226 |
Multiplication |
|
227 |
||
228 |
\begin{center} |
|
229 |
\bl{$\meta{F} \sim * \sim \meta{T} \Rightarrow f\,((x,y), z) \Rightarrow x * z$} |
|
230 |
\end{center}\pause |
|
231 |
||
232 |
Parenthesis |
|
233 |
||
234 |
\begin{center} |
|
235 |
\bl{$\text{(} \sim \meta{E} \sim \text{)} \Rightarrow f\,((x,y), z) \Rightarrow y$} |
|
236 |
\end{center} |
|
237 |
||
238 |
\end{frame} |
|
239 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
240 |
||
241 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
242 |
\begin{frame}[c] |
|
243 |
\frametitle{Input Types of Parsers} |
|
244 |
||
245 |
\begin{itemize} |
|
246 |
\item input: \alert{token list} |
|
247 |
\item output: set of (output\_type, \alert{token list}) |
|
248 |
\end{itemize}\bigskip\pause |
|
249 |
||
250 |
actually it can be any input type as long as it is a kind of |
|
251 |
sequence (for example a string) |
|
252 |
||
253 |
\end{frame} |
|
254 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
255 |
||
256 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
257 |
\begin{frame}[c] |
|
258 |
\frametitle{Scannerless Parsers} |
|
259 |
||
260 |
\begin{itemize} |
|
261 |
\item input: \alert{string} |
|
262 |
\item output: set of (output\_type, \alert{string}) |
|
263 |
\end{itemize}\bigskip\bigskip |
|
264 |
||
265 |
but using lexers is better because whitespaces or comments can be |
|
266 |
filtered out; then input is a sequence of tokens |
|
267 |
||
268 |
\end{frame} |
|
269 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
270 |
||
271 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
272 |
\begin{frame}[c] |
|
273 |
\frametitle{Abstract Parser Class} |
|
274 |
||
275 |
\small |
|
276 |
\lstinputlisting[language=Scala,xleftmargin=1mm] |
|
277 |
{../progs/app7.scala} |
|
278 |
\end{frame} |
|
279 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
280 |
||
281 |
||
282 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
283 |
\begin{frame}[c] |
|
284 |
\frametitle{Successful Parses} |
|
285 |
||
286 |
\begin{itemize} |
|
287 |
\item input: string |
|
288 |
\item output: \alert{set of} (output\_type, string) |
|
289 |
\end{itemize}\bigskip |
|
290 |
||
291 |
a parse is successful whenever the input has been fully |
|
292 |
``consumed'' (that is the second component is empty) |
|
293 |
||
294 |
\end{frame} |
|
295 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
296 |
||
297 |
||
298 |
||
799 | 299 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
300 |
\begin{frame}[c] |
|
803 | 301 |
%%\frametitle{Test Program} |
799 | 302 |
|
803 | 303 |
\mbox{}\\[-18mm]\mbox{} |
799 | 304 |
|
803 | 305 |
{\lstset{language=While}%%\fontsize{10}{12}\selectfont |
306 |
\texttt{\lstinputlisting{../progs/while-tests/loops.while}}} |
|
799 | 307 |
|
308 |
\end{frame} |
|
309 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
310 |
||
311 |
||
312 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
313 |
\begin{frame} |
|
314 |
\frametitle{While-Language} |
|
315 |
\mbox{}\\[-23mm]\mbox{} |
|
316 |
||
317 |
\bl{\begin{plstx}[rhs style=,one per line]: \meta{Stmt} ::= skip |
|
318 |
| \meta{Id} := \meta{AExp} |
|
319 |
| if \meta{BExp} then \meta{Block} else \meta{Block} |
|
320 |
| while \meta{BExp} do \meta{Block}\\ |
|
321 |
: \meta{Stmts} ::= \meta{Stmt} ; \meta{Stmts} |
|
322 |
| \meta{Stmt}\\ |
|
323 |
: \meta{Block} ::= \{ \meta{Stmts} \} |
|
324 |
| \meta{Stmt}\\ |
|
325 |
: \meta{AExp} ::= \ldots\\ |
|
326 |
: \meta{BExp} ::= \ldots\\\end{plstx}} |
|
327 |
||
328 |
\end{frame} |
|
329 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
330 |
||
331 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
803 | 332 |
\mode<presentation>{ |
799 | 333 |
\begin{frame}[c] |
803 | 334 |
\frametitle{\begin{tabular}{c}Aexps\end{tabular}} |
799 | 335 |
|
336 |
\begin{center} |
|
803 | 337 |
\bl{\begin{tabular}{@{}lcl@{}} |
338 |
$\text{eval}(n)$ & $\dn$ & $n$\\ |
|
339 |
$\text{eval}(a_1 + a_2)$ & $\dn$ & $\text{eval}(a_1) + \text{eval}(a_2)$\\ |
|
340 |
$\text{eval}(a_1 - a_2)$ & $\dn$ & $\text{eval}(a_1) - \text{eval}(a_2)$\\ |
|
341 |
$\text{eval}(a_1 * a_2)$ & $\dn$ & $\text{eval}(a_1) * \text{eval}(a_2)$\bigskip\\ |
|
342 |
$\text{eval}(x)$ & $\dn$ & $???$\\ |
|
799 | 343 |
\end{tabular}} |
344 |
\end{center} |
|
345 |
||
803 | 346 |
\end{frame}} |
347 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
799 | 348 |
|
349 |
||
350 |
||
351 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
352 |
\mode<presentation>{ |
|
353 |
\begin{frame}[c] |
|
354 |
\frametitle{\begin{tabular}{c}Interpreter\end{tabular}} |
|
355 |
||
356 |
\begin{center} |
|
357 |
\bl{\begin{tabular}{@{}lcl@{}} |
|
358 |
$\text{eval}(n, E)$ & $\dn$ & $n$\\ |
|
359 |
$\text{eval}(x, E)$ & $\dn$ & $E(x)$ \;\;\;\textcolor{black}{lookup \bl{$x$} in \bl{$E$}}\\ |
|
360 |
$\text{eval}(a_1 + a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) + \text{eval}(a_2, E)$\\ |
|
361 |
$\text{eval}(a_1 - a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) - \text{eval}(a_2, E)$\\ |
|
362 |
$\text{eval}(a_1 * a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) * \text{eval}(a_2, E)$\bigskip\\ |
|
363 |
$\text{eval}(a_1 = a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) = \text{eval}(a_2, E)$\\ |
|
364 |
$\text{eval}(a_1\,!\!= a_2, E)$ & $\dn$ & $\neg(\text{eval}(a_1, E) = \text{eval}(a_2, E))$\\ |
|
365 |
$\text{eval}(a_1 < a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) < \text{eval}(a_2, E)$\ |
|
366 |
\end{tabular}} |
|
367 |
\end{center} |
|
368 |
||
369 |
\end{frame}} |
|
803 | 370 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
371 |
||
372 |
||
373 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
374 |
\begin{frame}[c] |
|
375 |
\frametitle{An Interpreter (1)} |
|
376 |
||
377 |
\begin{center} |
|
378 |
\bl{\begin{tabular}{l} |
|
379 |
$\{$\\ |
|
380 |
\;\;$x := 5 \text{;}$\\ |
|
381 |
\;\;$y := x * 3\text{;}$\\ |
|
382 |
\;\;$y := x * 4\text{;}$\\ |
|
383 |
\;\;$x := u * 3$\\ |
|
384 |
$\}$ |
|
385 |
\end{tabular}} |
|
386 |
\end{center} |
|
387 |
||
388 |
\begin{itemize} |
|
389 |
\item the interpreter has to record the value of \bl{$x$} before assigning a value to \bl{$y$}\pause |
|
390 |
\item \bl{\texttt{eval(stmt, env)}} |
|
391 |
\end{itemize} |
|
392 |
||
393 |
\end{frame} |
|
799 | 394 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
803 | 395 |
|
799 | 396 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
397 |
\mode<presentation>{ |
|
398 |
\begin{frame}[c] |
|
399 |
\frametitle{\begin{tabular}{c}Interpreter (2)\end{tabular}} |
|
400 |
||
401 |
\begin{center} |
|
402 |
\bl{\begin{tabular}{@{}lcl@{}} |
|
403 |
$\text{eval}(\text{skip}, E)$ & $\dn$ & $E$\\ |
|
404 |
$\text{eval}(x:=a, E)$ & $\dn$ & \bl{$E(x \mapsto \text{eval}(a, E))$}\\ |
|
405 |
\multicolumn{3}{@{}l@{}}{$\text{eval}(\text{if}\;b\;\text{then}\;cs_1\;\text{else}\;cs_2 , E) \dn$}\\ |
|
406 |
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)\;\text{then}\; |
|
407 |
\text{eval}(cs_1,E)$}\\ |
|
408 |
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\phantom{\text{if}\;\text{eval}(b,E)\;}\text{else}\;\text{eval}(cs_2,E)$}\\ |
|
409 |
\multicolumn{3}{@{}l@{}}{$\text{eval}(\text{while}\;b\;\text{do}\;cs, E) \dn$}\\ |
|
410 |
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)$}\\ |
|
411 |
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{then}\; |
|
412 |
\text{eval}(\text{while}\;b\;\text{do}\;cs, \text{eval}(cs,E))$}\\ |
|
413 |
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{else}\; E$}\\ |
|
414 |
$\text{eval}(\text{write}\; x, E)$ & $\dn$ & $\{\;\text{println}(E(x))\; ;\;E\;\}$\\ |
|
415 |
\end{tabular}} |
|
416 |
\end{center} |
|
417 |
||
418 |
\end{frame}} |
|
419 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
420 |
||
421 |
||
422 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
423 |
\mode<presentation>{ |
|
424 |
\begin{frame}[t] |
|
425 |
\frametitle{\begin{tabular}{c}Interpreted Code\end{tabular}} |
|
426 |
||
427 |
\begin{center} |
|
428 |
\begin{tikzpicture} |
|
429 |
\begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small] |
|
430 |
\addplot+[smooth] file {interpreted.data}; |
|
431 |
\end{axis} |
|
432 |
\end{tikzpicture} |
|
433 |
\end{center} |
|
434 |
||
435 |
\end{frame}} |
|
436 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
437 |
||
809 | 438 |
|
439 |
\begin{frame}[t,fragile] |
|
440 |
\begin{mybox3}{} |
|
441 |
In CW3, in the collatz program there is the line write "$\backslash$n" Should this print "/n" or perform the new line command /n ? Also should write be print() or println() ? |
|
442 |
\end{mybox3} |
|
443 |
\end{frame} |
|
444 |
||
445 |
||
895 | 446 |
\begin{frame}<1-30>[c] |
809 | 447 |
\end{frame} |
448 |
||
449 |
||
803 | 450 |
\end{document} |
451 |
||
452 |
||
799 | 453 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
454 |
\mode<presentation>{ |
|
455 |
\begin{frame}[c] |
|
456 |
\frametitle{\begin{tabular}{c}Java Virtual Machine\end{tabular}} |
|
457 |
||
458 |
\begin{itemize} |
|
459 |
\item introduced in 1995 |
|
460 |
\item is a stack-based VM (like Postscript, CLR of .Net) |
|
461 |
\item contains a JIT compiler |
|
462 |
\item many languages take advantage of JVM's infrastructure (JRE) |
|
463 |
\item is garbage collected $\Rightarrow$ no buffer overflows |
|
464 |
\item some languages compile to the JVM: Scala, Clojure\ldots |
|
465 |
\end{itemize} |
|
466 |
||
467 |
\end{frame}} |
|
468 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
469 |
||
470 |
||
471 |
||
803 | 472 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
473 |
% \begin{frame}[t] |
|
474 |
% \frametitle{% |
|
475 |
% \begin{tabular}{@ {}c@ {}} |
|
476 |
% \\[-3mm] |
|
477 |
% \LARGE Compilers and \\[-2mm] |
|
478 |
% \LARGE Formal Languages\\[3mm] |
|
479 |
% \end{tabular}} |
|
799 | 480 |
|
803 | 481 |
% \normalsize |
482 |
% \begin{center} |
|
483 |
% \begin{tabular}{ll} |
|
484 |
% Email: & christian.urban at kcl.ac.uk\\ |
|
485 |
% %Office Hours: & Thursdays 12 -- 14\\ |
|
486 |
% %Location: & N7.07 (North Wing, Bush House)\\ |
|
487 |
% Slides \& Progs: & KEATS (also homework is there)\\ |
|
488 |
% \end{tabular} |
|
489 |
% \end{center} |
|
799 | 490 |
|
803 | 491 |
% \begin{center} |
492 |
% \begin{tikzpicture} |
|
493 |
% \node[drop shadow,fill=white,inner sep=0pt] |
|
494 |
% {\footnotesize\rowcolors{1}{capri!10}{white} |
|
495 |
% \begin{tabular}{|p{4.8cm}|p{4.8cm}|}\hline |
|
496 |
% 1 Introduction, Languages & \cellcolor{blue!50} 6 While-Language \\ |
|
497 |
% 2 Regular Expressions, Derivatives & 7 Compilation, JVM \\ |
|
498 |
% 3 Automata, Regular Languages & 8 Compiling Functional Languages \\ |
|
499 |
% 4 Lexing, Tokenising & 9 Optimisations \\ |
|
500 |
% 5 Grammars, Parsing & 10 LLVM \\ \hline |
|
501 |
% \end{tabular}% |
|
502 |
% }; |
|
503 |
% \end{tikzpicture} |
|
504 |
% \end{center} |
|
799 | 505 |
|
803 | 506 |
% \end{frame} |
507 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
799 | 508 |
|
509 |
||
510 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
531 | 511 |
% \begin{frame}[c] |
512 |
% \small |
|
513 |
% \mbox{}\\[5mm] |
|
514 |
% %\begin{textblock}{10}(3,5) |
|
515 |
% \begin{tikzpicture}[scale=1.5, |
|
516 |
% node distance=1cm, |
|
517 |
% every node/.style={minimum size=7mm}] |
|
518 |
% \node (r1) {\bl{$r_1$}}; |
|
519 |
% \node (r2) [right=of r1] {\bl{$r_2$}}; |
|
520 |
% \draw[->,line width=1mm] (r1) -- (r2) node[above,midway] {\bl{$der\,a$}}; |
|
521 |
% \node (r3) [right=of r2] {\bl{$r_3$}}; |
|
522 |
% \draw[->,line width=1mm] (r2) -- (r3) node[above,midway] {\bl{$der\,b$}}; |
|
523 |
% \node (r4) [right=of r3] {\bl{$r_4$}}; |
|
524 |
% \draw[->,line width=1mm] (r3) -- (r4) node[above,midway] {\bl{$der\,c$}}; |
|
525 |
% \draw (r4) node[anchor=west] {\;\raisebox{3mm}{\bl{$nullable$}}}; |
|
526 |
% \node (v4) [below=of r4] {\bl{$v_4$}}; |
|
527 |
% \draw[->,line width=1mm] (r4) -- (v4); |
|
528 |
% \node (v3) [left=of v4] {\bl{$v_3$}}; |
|
529 |
% \draw[->,line width=1mm] (v4) -- (v3) node[below,midway] {\bl{$inj\,c$}}; |
|
530 |
% \node (v2) [left=of v3] {\bl{$v_2$}}; |
|
531 |
% \draw[->,line width=1mm] (v3) -- (v2) node[below,midway] {\bl{$inj\,b$}}; |
|
532 |
% \node (v1) [left=of v2] {\bl{$v_1$}}; |
|
533 |
% \draw[->,line width=1mm] (v2) -- (v1) node[below,midway] {\bl{$inj\,a$}}; |
|
534 |
% \draw[->,line width=0.5mm] (r3) -- (v3); |
|
535 |
% \draw[->,line width=0.5mm] (r2) -- (v2); |
|
536 |
% \draw[->,line width=0.5mm] (r1) -- (v1); |
|
537 |
% \draw (r4) node[anchor=north west] {\;\raisebox{-8mm}{\bl{$mkeps$}}}; |
|
538 |
% \end{tikzpicture} |
|
539 |
% %\end{textblock} |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
540 |
|
531 | 541 |
% \begin{center} |
542 |
% \begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l} |
|
543 |
% \\[-10mm] |
|
544 |
% \bl{$inj\,(c)\,c\,Empty$} & \bl{$\dn$} & \bl{$Char\,c$}\\ |
|
545 |
% \bl{$inj\,(r_1 + r_2)\,c\,Left(v)$} & \bl{$\dn$} & \bl{$Left(inj\,r_1\,c\,v)$}\\ |
|
546 |
% \bl{$inj\,(r_1 + r_2)\,c\,Right(v)$} & \bl{$\dn$} & \bl{$Right(inj\,r_2\,c\,v)$}\\ |
|
547 |
% \bl{$inj\,(r_1 \cdot r_2)\,c\,Seq(v_1,v_2)$} & \bl{$\dn$} & \bl{$Seq(inj\,r_1\,c\,v_1,v_2)$}\\ |
|
548 |
% \bl{$inj\,(r_1 \cdot r_2)\,c\,Left(Seq(v_1,v_2))$} & \bl{$\dn$} & \bl{$Seq(inj\,r_1\,c\,v_1,v_2)$}\\ |
|
549 |
% \bl{$inj\,(r_1 \cdot r_2)\,c\,Right(v)$} & \bl{$\dn$} & \bl{$Seq(mkeps(r_1),inj\,r_2\,c\,v)$}\\ |
|
550 |
% \bl{$inj\,(r^*)\,c\,Seq(v,vs)$} & \bl{$\dn$} & \bl{$inj\,r\,c\,v\,::\,vs$}\\ |
|
551 |
% \end{tabular} |
|
552 |
% \end{center} |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
553 |
|
531 | 554 |
% \end{frame} |
555 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
556 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
557 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
683 | 558 |
\begin{frame}[t] |
559 |
\frametitle{Starting Symbol} |
|
560 |
||
561 |
\bl{\begin{plstx}[margin=1cm] |
|
562 |
: \meta{S} ::= \meta{A}\cdot\meta{S}\cdot\meta{B} | |
|
563 |
\meta{B}\cdot\meta{S}\cdot\meta{A} | \epsilon\\ |
|
564 |
: \meta{A} ::= a | \epsilon\\ |
|
565 |
: \meta{B} ::= b\\ |
|
566 |
\end{plstx}} |
|
567 |
||
750 | 568 |
|
569 |
TODO: Testcases for math expressions |
|
570 |
\url{https://github.com/ArashPartow/math-parser-benchmark-project} |
|
571 |
||
683 | 572 |
\end{frame} |
573 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
574 |
||
575 |
||
576 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
577 |
\begin{frame}[c] |
683 | 578 |
\frametitle{Hierarchy of Languages} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
579 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
580 |
Recall that languages are sets of strings. |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
581 |
|
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
582 |
\begin{center} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
583 |
\begin{tikzpicture} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
584 |
[rect/.style={draw=black!50, top color=white,bottom color=black!20, rectangle, very thick, rounded corners}] |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
585 |
|
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
586 |
\draw (0,0) node [rect, text depth=39mm, text width=68mm] {all languages}; |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
587 |
\draw (0,-0.4) node [rect, text depth=28.5mm, text width=64mm] {decidable languages}; |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
588 |
\draw (0,-0.85) node [rect, text depth=17mm] {context sensitive languages}; |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
589 |
\draw (0,-1.14) node [rect, text depth=9mm, text width=50mm] {context-free languages}; |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
590 |
\draw (0,-1.4) node [rect] {regular languages}; |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
591 |
\end{tikzpicture} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
592 |
|
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
593 |
\end{center} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
594 |
|
366
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
595 |
\end{frame} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
596 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
597 |
|
531 | 598 |
|
366
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
599 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
600 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
601 |
\begin{frame}[c] |
598 | 602 |
\frametitle{Parser Combinators} |
603 |
||
366
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
604 |
Atomic parsers, for example |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
605 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
606 |
\begin{center} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
607 |
\bl{$1::rest \;\Rightarrow\; \{(1, rest)\}$} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
608 |
\end{center}\bigskip |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
609 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
610 |
\begin{itemize} |
597 | 611 |
\item you consume one or more tokens from the\\ |
366
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
612 |
input (stream) |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
613 |
\item also works for characters and strings |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
614 |
\end{itemize} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
615 |
\end{frame} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
616 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
617 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
618 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
619 |
\begin{frame}[c] |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
620 |
|
686 | 621 |
Alternative parser (code \bl{$p\;|\;q$})\bigskip |
366
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
622 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
623 |
\begin{itemize} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
624 |
\item apply \bl{$p$} and also \bl{$q$}; then combine |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
625 |
the outputs |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
626 |
\end{itemize} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
627 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
628 |
\begin{center} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
629 |
\large \bl{$p(\text{input}) \cup q(\text{input})$} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
630 |
\end{center} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
631 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
632 |
\end{frame} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
633 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
634 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
635 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
636 |
\begin{frame}[c] |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
637 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
638 |
Sequence parser (code \bl{$p\sim q$})\bigskip |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
639 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
640 |
\begin{itemize} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
641 |
\item apply first \bl{$p$} producing a set of pairs |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
642 |
\item then apply \bl{$q$} to the unparsed parts |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
643 |
\item then combine the results:\medskip |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
644 |
\begin{center} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
645 |
((output$_1$, output$_2$), unparsed part) |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
646 |
\end{center} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
647 |
\end{itemize} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
648 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
649 |
\begin{center} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
650 |
\begin{tabular}{l} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
651 |
\large \bl{$\{((o_1, o_2), u_2) \;|\;$}\\[2mm] |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
652 |
\large\mbox{}\hspace{15mm} \bl{$(o_1, u_1) \in p(\text{input}) \wedge$}\\[2mm] |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
653 |
\large\mbox{}\hspace{15mm} \bl{$(o_2, u_2) \in q(u_1)\}$} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
654 |
\end{tabular} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
655 |
\end{center} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
656 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
657 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
658 |
\end{frame} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
659 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
660 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
661 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
662 |
\begin{frame}[c] |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
663 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
664 |
Function parser (code \bl{$p \Rightarrow f\;$})\bigskip |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
665 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
666 |
\begin{itemize} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
667 |
\item apply \bl{$p$} producing a set of pairs |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
668 |
\item then apply the function \bl{$f$} to each first component |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
669 |
\end{itemize} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
670 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
671 |
\begin{center} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
672 |
\begin{tabular}{l} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
673 |
\large \bl{$\{(f(o_1), u_1) \;|\; (o_1, u_1) \in p(\text{input})\}$} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
674 |
\end{tabular} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
675 |
\end{center} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
676 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
677 |
\end{frame} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
678 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
679 |
|
531 | 680 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
681 |
\begin{frame}[c] |
|
682 |
\frametitle{Types of Parsers} |
|
683 |
||
684 |
\begin{itemize} |
|
685 |
\item {\bf Sequencing}: if \bl{$p$} returns results of type \bl{$T$}, and \bl{$q$} results of type \bl{$S$}, |
|
686 |
then \bl{$p \sim q$} returns results of type |
|
687 |
||
688 |
\begin{center} |
|
689 |
\bl{$T \times S$} |
|
690 |
\end{center}\pause |
|
691 |
||
692 |
\item {\bf Alternative}: if \bl{$p$} returns results of type \bl{$T$} then \bl{$q$} \alert{must} also have results of type \bl{$T$}, |
|
686 | 693 |
and \bl{$p \;|\; q$} returns results of type |
531 | 694 |
|
695 |
\begin{center} |
|
696 |
\bl{$T$} |
|
697 |
\end{center}\pause |
|
698 |
||
699 |
\item {\bf Semantic Action}: if \bl{$p$} returns results of type \bl{$T$} and \bl{$f$} is a function from |
|
700 |
\bl{$T$} to \bl{$S$}, then |
|
701 |
\bl{$p \Rightarrow f$} returns results of type |
|
702 |
||
703 |
\begin{center} |
|
704 |
\bl{$S$} |
|
705 |
\end{center} |
|
706 |
||
707 |
\end{itemize} |
|
708 |
||
709 |
\end{frame} |
|
710 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
711 |
||
712 |
||
713 |
||
714 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
715 |
\begin{frame}[c] |
|
716 |
\frametitle{Two Grammars} |
|
717 |
||
718 |
Which languages are recognised by the following two grammars? |
|
719 |
||
597 | 720 |
\bl{\begin{plstx}[margin=3cm] |
721 |
: \meta{S} ::= \liningnums{1}\cdot\meta{S}\cdot \meta{S} | \epsilon\\ |
|
722 |
\end{plstx}} |
|
531 | 723 |
|
597 | 724 |
\bl{\begin{plstx}[margin=3cm] |
725 |
: \meta{U} ::= \liningnums{1}\cdot\meta{U} | \epsilon\\ |
|
726 |
\end{plstx}} |
|
531 | 727 |
|
728 |
\end{frame} |
|
729 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
366
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
730 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
731 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
732 |
\begin{frame}[t] |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
733 |
\frametitle{Ambiguous Grammars} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
734 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
735 |
\begin{center} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
736 |
\begin{tikzpicture} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
737 |
\begin{axis}[xlabel={\pcode{1}s},ylabel={time in secs}, |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
738 |
enlargelimits=false, |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
739 |
xtick={0,100,...,1000}, |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
740 |
xmax=1050, |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
741 |
ymax=33, |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
742 |
ytick={0,5,...,30}, |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
743 |
scaled ticks=false, |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
744 |
axis lines=left, |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
745 |
width=11cm, |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
746 |
height=7cm, |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
747 |
legend entries={unambiguous,ambiguous}, |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
748 |
legend pos=north east, |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
749 |
legend cell align=left, |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
750 |
x tick label style={font=\small,/pgf/number format/1000 sep={}}] |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
751 |
\addplot[blue,mark=*, mark options={fill=white}] |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
752 |
table {s-grammar1.data}; |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
753 |
\only<2>{ |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
754 |
\addplot[red,mark=triangle*, mark options={fill=white}] |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
755 |
table {s-grammar2.data};} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
756 |
\end{axis} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
757 |
\end{tikzpicture} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
758 |
\end{center} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
759 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
760 |
\end{frame} |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
761 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
762 |
|
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
763 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
764 |
\begin{frame}[c] |
597 | 765 |
\frametitle{Arithmetic Expressions} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
766 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
767 |
A grammar for arithmetic expressions and numbers: |
50 | 768 |
|
597 | 769 |
\bl{\begin{plstx}[margin=1cm] |
770 |
: \meta{E} ::= \meta{E} \cdot + \cdot \meta{E} |
|
771 |
| \meta{E} \cdot * \cdot \meta{E} |
|
772 |
| ( \cdot \meta{E} \cdot ) | \meta{N}\\ |
|
773 |
: \meta{N} ::= \meta{N} \cdot \meta{N} | |
|
774 |
0 | 1 | \ldots | 9\\ |
|
775 |
\end{plstx}} |
|
49 | 776 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
777 |
Unfortunately it is left-recursive (and ambiguous).\medskip\\ |
597 | 778 |
A problem for \alert{recursive descent parsers} (e.g.~parser |
779 |
combinators). \bigskip\pause |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
780 |
|
597 | 781 |
\end{frame} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
782 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
783 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
784 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
785 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
786 |
\begin{frame}[t] |
597 | 787 |
\frametitle{Numbers} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
788 |
|
597 | 789 |
\bl{\begin{plstx}[margin=1cm] |
790 |
: \meta{N} ::= \meta{N} \cdot \meta{N} | |
|
791 |
0 | 1 | \ldots | 9\\ |
|
792 |
\end{plstx}} |
|
49 | 793 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
794 |
A non-left-recursive, non-ambiguous grammar for numbers: |
49 | 795 |
|
597 | 796 |
\bl{\begin{plstx}[margin=1cm] |
797 |
: \meta{N} ::= 0 \cdot \meta{N} | 1 \cdot \meta{N} | \ldots | |
|
798 |
0 | 1 | \ldots | 9\\ |
|
799 |
\end{plstx}} |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
800 |
|
597 | 801 |
\end{frame} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
802 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
803 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
804 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
805 |
\begin{frame}[c] |
597 | 806 |
\frametitle{Removing Left-Recursion} |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
807 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
808 |
The rule for numbers is directly left-recursive: |
49 | 809 |
|
810 |
\begin{center} |
|
50 | 811 |
\bl{\begin{tabular}{lcl} |
597 | 812 |
$\meta{N}$ & $::=$ & $\meta{N} \cdot \meta{N} \;|\; 0 \;|\; 1\;\;\;\;(\ldots)$ |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
813 |
\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
814 |
\end{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
815 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
816 |
Translate |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
817 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
818 |
\begin{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
819 |
\begin{tabular}{ccc} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
820 |
\bl{\begin{tabular}{lcl} |
597 | 821 |
$\meta{N}$ & $::=$ & $\meta{N} \cdot \alpha$\\ |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
822 |
& $\;|\;$ & $\beta$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
823 |
\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
824 |
\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
825 |
& {\Large$\Rightarrow$} & |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
826 |
\bl{\begin{tabular}{lcl} |
597 | 827 |
$\meta{N}$ & $::=$ & $\beta \cdot \meta{N}'$\\ |
828 |
$\meta{N}'$ & $::=$ & $\alpha \cdot \meta{N}'$\\ |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
829 |
& $\;|\;$ & $\epsilon$ |
50 | 830 |
\end{tabular}} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
831 |
\end{tabular} |
50 | 832 |
\end{center}\pause |
833 |
||
597 | 834 |
Which means in this case: |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
835 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
836 |
\begin{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
837 |
\bl{\begin{tabular}{lcl} |
597 | 838 |
$\meta{N}$ & $\rightarrow$ & $0 \cdot \meta{N}' \;|\; 1 \cdot \meta{N}'$\\ |
839 |
$\meta{N}'$ & $\rightarrow$ & $\meta{N} \cdot \meta{N}' \;|\; \epsilon$\\ |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
840 |
\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
841 |
\end{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
842 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
843 |
|
597 | 844 |
\end{frame} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
845 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
846 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
847 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
685 | 848 |
%\begin{frame}[c] |
849 |
%\frametitle{Operator Precedences} |
|
850 |
% |
|
851 |
% |
|
852 |
%To disambiguate |
|
853 |
% |
|
854 |
%\begin{center} |
|
855 |
%\bl{\begin{tabular}{lcl} |
|
856 |
%$\meta{E}$ & $::=$ & $\meta{E} \cdot + \cdot \meta{E} \;|\;\meta{E} \cdot * \cdot \meta{E} \;|\;( \cdot \meta{E} \cdot ) \;|\;\meta{N}$ \\ |
|
857 |
%\end{tabular}} |
|
858 |
%\end{center} |
|
859 |
% |
|
860 |
%Decide on how many precedence levels, say\medskip\\ |
|
861 |
%highest for \bl{$()$}, medium for \bl{*}, lowest for \bl{+} |
|
862 |
% |
|
863 |
%\begin{center} |
|
864 |
%\bl{\begin{tabular}{lcl} |
|
865 |
%$\meta{E}_{low}$ & $::=$ & $\meta{E}_{med} \cdot + \cdot \meta{E}_{low} \;|\; \meta{E}_{med}$ \\ |
|
866 |
%$\meta{E}_{med}$ & $::=$ & $\meta{E}_{hi} \cdot * \cdot \meta{E}_{med} \;|\; \meta{E}_{hi}$\\ |
|
867 |
%$\meta{E}_{hi}$ & $::=$ & $( \cdot \meta{E}_{low} \cdot ) \;|\;\meta{N}$ \\ |
|
868 |
%\end{tabular}} |
|
869 |
%\end{center}\pause |
|
870 |
% |
|
871 |
%\small What happens with \bl{$1 + 3 + 4$}? |
|
872 |
%\end{frame} |
|
366
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
873 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
874 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
875 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
876 |
\begin{frame}[c] |
597 | 877 |
\frametitle{Chomsky Normal Form} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
878 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
879 |
All rules must be of the form |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
880 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
881 |
\begin{center} |
597 | 882 |
\bl{$\meta{A} ::= a$} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
883 |
\end{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
884 |
|
50 | 885 |
or |
886 |
||
887 |
\begin{center} |
|
597 | 888 |
\bl{$\meta{A} ::= \meta{B}\cdot \meta{C}$} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
889 |
\end{center} |
49 | 890 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
891 |
No rule can contain \bl{$\epsilon$}. |
49 | 892 |
|
597 | 893 |
\end{frame} |
49 | 894 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
895 |
||
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
896 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
897 |
\begin{frame}[c] |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
898 |
\frametitle{\begin{tabular}{c}$\epsilon$-Removal\end{tabular}} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
899 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
900 |
\begin{enumerate} |
597 | 901 |
\item If \bl{$A::= \alpha \cdot B \cdot \beta$} and \bl{$B ::= \epsilon$} are in the grammar, |
902 |
then add \bl{$A::= \alpha \cdot \beta$} (iterate if necessary). |
|
903 |
\item Throw out all \bl{$B ::= \epsilon$}. |
|
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
904 |
\end{enumerate} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
905 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
906 |
\small |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
907 |
\begin{center} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
908 |
\begin{tabular}{ccc} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
909 |
\bl{\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l} |
597 | 910 |
$N$ & $::=$ & $0 \cdot N' \;|\; 1\cdot N'$\\ |
911 |
$N'$ & $::=$ & $N \cdot N'\;|\;\epsilon$\\ |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
912 |
\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
913 |
\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
914 |
\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
915 |
\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
916 |
\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
917 |
\end{tabular}} & |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
918 |
\bl{\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
919 |
\\ |
597 | 920 |
$N$ & $::=$ & $0 \cdot N' \;|\; 1\cdot N'\;|\;0\;|\;1$\\ |
921 |
$N'$ & $::=$ & $N \cdot N'\;|\;N\;|\;\epsilon$\\ |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
922 |
\\ |
597 | 923 |
$N$ & $::=$ & $0 \cdot N' \;|\; 1\cdot N'\;|\;0\;|\;1$\\ |
924 |
$N'$ & $::=$ & $N \cdot N'\;|\;N$\\ |
|
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
925 |
\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
926 |
\end{tabular} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
927 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
928 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
929 |
\pause\normalsize |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
930 |
\begin{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
931 |
\bl{\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l} |
597 | 932 |
$N$ & $::=$ & $0 \cdot N\;|\; 1\cdot N\;|\;0\;|\;1$\\ |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
933 |
\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
934 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
935 |
\end{center} |
368
a9911966c0df
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
366
diff
changeset
|
936 |
\end{frame} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
937 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
938 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
939 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
940 |
|
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
941 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
942 |
\begin{frame}[c] |
597 | 943 |
\frametitle{CYK Algorithm} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
944 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
945 |
If grammar is in Chomsky normalform \ldots |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
946 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
947 |
\begin{center} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
948 |
\bl{\begin{tabular}{@ {}lcl@ {}} |
597 | 949 |
$\meta{S}$ & $::=$ & $\meta{N}\cdot \meta{P}$ \\ |
950 |
$\meta{P}$ & $::=$ & $\meta{V}\cdot \meta{N}$ \\ |
|
951 |
$\meta{N}$ & $::=$ & $\meta{N}\cdot \meta{N}$ \\ |
|
952 |
$\meta{N}$ & $::=$ & $\texttt{students} \;|\; \texttt{Jeff} \;|\; \texttt{geometry} \;|\; \texttt{trains} $ \\ |
|
953 |
$\meta{V}$ & $::=$ & $\texttt{trains}$ |
|
49 | 954 |
\end{tabular}} |
955 |
\end{center} |
|
956 |
||
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
957 |
\bl{\texttt{Jeff trains geometry students}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
958 |
|
597 | 959 |
\end{frame} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
960 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
597 | 961 |
|
962 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
963 |
\begin{frame}[c] |
597 | 964 |
\frametitle{CYK Algorithm} |
49 | 965 |
|
966 |
||
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
967 |
\begin{itemize} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
968 |
\item fastest possible algorithm for recognition problem |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
969 |
\item runtime is \bl{$O(n^3)$}\bigskip |
597 | 970 |
\item grammars need to be transformed into CNF |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
971 |
\end{itemize} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
972 |
|
597 | 973 |
\end{frame} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
974 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
975 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
976 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
366
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
977 |
\begin{frame}[c] |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
978 |
\frametitle{The Goal of this Course} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
979 |
\mbox{}\\[-26mm]\mbox{} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
980 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
981 |
\begin{center} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
982 |
\begin{tikzpicture}[scale=1, |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
983 |
node/.style={ |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
984 |
rectangle,rounded corners=3mm, |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
985 |
very thick,draw=black!50, |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
986 |
minimum height=18mm, minimum width=20mm, |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
987 |
top color=white,bottom color=black!20}] |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
988 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
989 |
\node at (3.05, 1.8) {\Large\bf Write a Compiler}; |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
990 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
991 |
\node (0) at (-2.3,0) {}; |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
992 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
993 |
\node (A) at (0,0) [node] {}; |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
994 |
\node [below right] at (A.north west) {lexer}; |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
995 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
996 |
\node (B) at (3,0) [node] {}; |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
997 |
\node [below right=1mm] at (B.north west) |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
998 |
{\mbox{}\hspace{-1mm}parser}; |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
999 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
1000 |
\node (C) at (6,0) [node] {}; |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
1001 |
\node [below right] at (C.north west) |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
1002 |
{\mbox{}\hspace{-1mm}code gen}; |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
1003 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
1004 |
\node (1) at (8.4,0) {}; |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
1005 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
1006 |
\draw [->,line width=4mm] (0) -- (A); |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
1007 |
\draw [->,line width=4mm] (A) -- (B); |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
1008 |
\draw [->,line width=4mm] (B) -- (C); |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
1009 |
\draw [->,line width=4mm] (C) -- (1); |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
1010 |
\end{tikzpicture} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
1011 |
\end{center} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
1012 |
|
598 | 1013 |
We have a lexer and a parser\ldots |
366
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
1014 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
1015 |
\end{frame} |
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
1016 |
|
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
1017 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1018 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1019 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1020 |
\begin{center} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1021 |
\bl{\begin{tabular}{@{}lcl@{}} |
598 | 1022 |
\meta{Stmt} & $::=$ & $\texttt{skip}$\\ |
1023 |
& $|$ & \textit{Id}\;\texttt{:=}\;\meta{AExp}\\ |
|
1024 |
& $|$ & \texttt{if}\; \meta{BExp} \;\texttt{then}\; \meta{Block} \;\texttt{else}\; \meta{Block}\\ |
|
1025 |
& $|$ & \texttt{while}\; \meta{BExp} \;\texttt{do}\; \meta{Block}\\ |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1026 |
& $|$ & \texttt{read}\;\textit{Id}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1027 |
& $|$ & \texttt{write}\;\textit{Id}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1028 |
& $|$ & \texttt{write}\;\textit{String}\medskip\\ |
598 | 1029 |
\meta{Stmts} & $::=$ & \meta{Stmt} \;\texttt{;}\; \meta{Stmts}\\ |
1030 |
& $|$ & \meta{Stmt}\medskip\\ |
|
1031 |
\meta{Block} & $::=$ & \texttt{\{}\,\meta{Stmts}\,\texttt{\}}\\ |
|
1032 |
& $|$ & \meta{Stmt}\medskip\\ |
|
1033 |
\meta{AExp} & $::=$ & \ldots\\ |
|
1034 |
\meta{BExp} & $::=$ & \ldots\\ |
|
50 | 1035 |
\end{tabular}} |
1036 |
\end{center} |
|
366
5a83336a9690
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
365
diff
changeset
|
1037 |
\end{frame} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1038 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1039 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1040 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1041 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1042 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1043 |
|
744 | 1044 |
??%%\mbox{\lstinputlisting[language=while]{../progs/fib.while}} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1045 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1046 |
\end{frame}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1047 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1048 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1049 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1050 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1051 |
\begin{frame}[c] |
598 | 1052 |
\frametitle{An Interpreter} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1053 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1054 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1055 |
\bl{\begin{tabular}{l} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1056 |
$\{$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1057 |
\;\;$x := 5 \text{;}$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1058 |
\;\;$y := x * 3\text{;}$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1059 |
\;\;$y := x * 4\text{;}$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1060 |
\;\;$x := u * 3$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1061 |
$\}$ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1062 |
\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1063 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1064 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1065 |
\begin{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1066 |
\item the interpreter has to record the value of \bl{$x$} before assigning a value to \bl{$y$}\pause |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1067 |
\item \bl{\text{eval}(stmt, env)} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1068 |
\end{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1069 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1070 |
|
598 | 1071 |
\end{frame} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1072 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1073 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1074 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1075 |
\begin{frame}[c] |
598 | 1076 |
\frametitle{An Interpreter} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1077 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1078 |
\begin{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1079 |
\bl{\begin{tabular}{@{}lcl@{}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1080 |
$\text{eval}(n, E)$ & $\dn$ & $n$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1081 |
$\text{eval}(x, E)$ & $\dn$ & $E(x)$ \;\;\;\textcolor{black}{lookup \bl{$x$} in \bl{$E$}}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1082 |
$\text{eval}(a_1 + a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) + \text{eval}(a_2, E)$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1083 |
$\text{eval}(a_1 - a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) - \text{eval}(a_2, E)$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1084 |
$\text{eval}(a_1 * a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) * \text{eval}(a_2, E)$\bigskip\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1085 |
$\text{eval}(a_1 = a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) = \text{eval}(a_2, E)$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1086 |
$\text{eval}(a_1\,!\!= a_2, E)$ & $\dn$ & $\neg(\text{eval}(a_1, E) = \text{eval}(a_2, E))$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1087 |
$\text{eval}(a_1 < a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) < \text{eval}(a_2, E)$\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1088 |
\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1089 |
\end{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1090 |
|
598 | 1091 |
\end{frame} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1092 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
598 | 1093 |
|
1094 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1095 |
\begin{frame}[c] |
598 | 1096 |
\frametitle{An Interpreter (2)} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1097 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1098 |
\begin{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1099 |
\bl{\begin{tabular}{@{}lcl@{}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1100 |
$\text{eval}(\text{skip}, E)$ & $\dn$ & $E$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1101 |
$\text{eval}(x:=a, E)$ & $\dn$ & \bl{$E(x \mapsto \text{eval}(a, E))$}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1102 |
\multicolumn{3}{@{}l@{}}{$\text{eval}(\text{if}\;b\;\text{then}\;cs_1\;\text{else}\;cs_2 , E) \dn$}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1103 |
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)\;\text{then}\; |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1104 |
\text{eval}(cs_1,E)$}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1105 |
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\phantom{\text{if}\;\text{eval}(b,E)\;}\text{else}\;\text{eval}(cs_2,E)$}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1106 |
\multicolumn{3}{@{}l@{}}{$\text{eval}(\text{while}\;b\;\text{do}\;cs, E) \dn$}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1107 |
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)$}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1108 |
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{then}\; |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1109 |
\text{eval}(\text{while}\;b\;\text{do}\;cs, \text{eval}(cs,E))$}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1110 |
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{else}\; E$}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1111 |
$\text{eval}(\text{write}\; x, E)$ & $\dn$ & $\{\;\text{println}(E(x))\; ;\;E\;\}$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1112 |
\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1113 |
\end{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1114 |
|
598 | 1115 |
\end{frame} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1116 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1117 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1118 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1119 |
\begin{frame}[c] |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1120 |
\frametitle{\begin{tabular}{c}Test Program\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1121 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1122 |
\mbox{}\\[-18mm]\mbox{} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1123 |
|
744 | 1124 |
?? |
1125 |
%{\lstset{language=While}%%\fontsize{10}{12}\selectfont |
|
1126 |
%\texttt{\lstinputlisting{../progs/loops.while}}} |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1127 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
1128 |
\end{frame} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1129 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
1130 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1131 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1132 |
\mode<presentation>{ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1133 |
\begin{frame}[t] |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1134 |
\frametitle{\begin{tabular}{c}Interpreted Code\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1135 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1136 |
\begin{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1137 |
\begin{tikzpicture} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1138 |
\begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small] |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1139 |
\addplot+[smooth] file {interpreted.data}; |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1140 |
\end{axis} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1141 |
\end{tikzpicture} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1142 |
\end{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1143 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1144 |
\end{frame}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1145 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1146 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1147 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1148 |
\begin{frame}[c] |
685 | 1149 |
\frametitle{Java Virtual Machine} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1150 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1151 |
\begin{itemize} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1152 |
\item introduced in 1995 |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1153 |
\item is a stack-based VM (like Postscript, CLR of .Net) |
685 | 1154 |
\item contains a JIT compiler\\ |
1155 |
\begin{itemize} |
|
1156 |
\item From the Cradle to the Holy Graal - the JDK Story |
|
1157 |
\item \url{https://www.youtube.com/watch?v=h419kfbLhUI} |
|
1158 |
\end{itemize} |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1159 |
\item is garbage collected $\Rightarrow$ no buffer overflows |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1160 |
\item some languages compile to the JVM: Scala, Clojure\ldots |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1161 |
\end{itemize} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1162 |
|
685 | 1163 |
\end{frame} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1164 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
1165 |
|
685 | 1166 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1167 |
\begin{frame}[c] |
|
1168 |
\frametitle{LLVM} |
|
1169 |
||
1170 |
\begin{itemize} |
|
1171 |
\item LLVM started by academics in 2000 (University of Illinois in |
|
1172 |
Urbana-Champaign) |
|
1173 |
\item suite of compiler tools |
|
1174 |
\item SSA-based intermediate language |
|
1175 |
\item no need to allocate registers |
|
686 | 1176 |
\item source languages: C, C++, Rust, Go, Swift |
1177 |
\item target CPUs: x86, ARM, PowerPC, \ldots |
|
685 | 1178 |
\end{itemize} |
1179 |
\end{frame} |
|
1180 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
702 | 1181 |
|
598 | 1182 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
666 | 1183 |
%\begin{frame}[c] |
1184 |
% \frametitle{Coursework: MkEps} |
|
1185 |
% |
|
1186 |
%\begin{center} |
|
1187 |
%\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}} |
|
1188 |
% \bl{$mkeps([c_1 c_2 \ldots c_n])$} & \bl{$\dn$} & $\bl{undefined}$\\ |
|
1189 |
% \bl{$mkeps(r^*)$} & \bl{$\dn$} & $\bl{Stars\,[]}$\\ |
|
1190 |
% \bl{$mkeps(r^{\{n\}})$} & \bl{$\dn$} & $\bl{Stars\,(mkeps(r))^n}$\\ |
|
1191 |
% \bl{$mkeps(r^{\{n..\}})$} & \bl{$\dn$} & $\bl{Stars\,(mkeps(r))^n}$\\ |
|
1192 |
% \bl{$mkeps(r^{\{..n\}})$} & \bl{$\dn$} & $\bl{Stars\,[]}$\\ |
|
1193 |
% \bl{$mkeps(r^{\{n..m\}})$} & \bl{$\dn$} & $\bl{Stars\,(mkeps(r))^n}$\medskip\\ |
|
1194 |
% |
|
1195 |
% \bl{$mkeps(r^+)$} & \bl{$\dn$} & \bl{$mkeps(r^{\{1..\}})$}\\ |
|
1196 |
% \bl{$mkeps(r^?)$} & \bl{$\dn$} & \bl{$mkeps(r^{\{..1\}})$}\\ |
|
1197 |
%\end{tabular} |
|
1198 |
%\end{center} |
|
1199 |
% |
|
1200 |
%\end{frame} |
|
1201 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1202 |
% |
|
1203 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1204 |
%\begin{frame}[c] |
|
1205 |
% \frametitle{Coursework: Inj} |
|
1206 |
% |
|
1207 |
%\begin{center} |
|
1208 |
%\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}} |
|
1209 |
% \bl{$inj([c_1 c_2 \ldots c_n])\,c\,Empty$} & \bl{$\dn$} & $\bl{Chr\,c}$\\ |
|
1210 |
% \bl{$inj(r^*)\,c\;(Seq\,v\,(Stars\,vs))$} & \bl{$\dn$} & $\bl{Stars\,(inj\,r\,c\,v::vs)}$\\ |
|
1211 |
% \bl{$inj(r^{\{n\}})\,c\;(Seq\,v\,(Stars\,vs))$} & \bl{$\dn$} & $\bl{Stars\,(inj\,r\,c\,v::vs)}$\\ |
|
1212 |
% \bl{$inj(r^{\{n..\}})\,c\;(Seq\,v\,(Stars\,vs))$} & \bl{$\dn$} & $\bl{Stars\,(inj\,r\,c\,v::vs)}$\\ |
|
1213 |
% \bl{$inj(r^{\{..n\}})\,c\;(Seq\,v\,(Stars\,vs))$} & \bl{$\dn$} & $\bl{Stars\,(inj\,r\,c\,v::vs)}$\\ |
|
1214 |
% \bl{$inj(r^{\{n..m\}})\,c\;(Seq\,v\,(Stars\,vs))$} & \bl{$\dn$} & $\bl{Stars\,(inj\,r\,c\,v::vs)}$\medskip\\ |
|
1215 |
% |
|
1216 |
% \bl{$inj(r^+)\,c\,v$} & \bl{$\dn$} & \bl{$inj(r^{\{1..\}})\,c\,v$}\\ |
|
1217 |
% \bl{$inj(r^?)\,c\,v$} & \bl{$\dn$} & \bl{$inj(r^{\{..1\}})\,c\,v$}\\ |
|
1218 |
%\end{tabular} |
|
1219 |
%\end{center} |
|
1220 |
% |
|
1221 |
%\end{frame} |
|
1222 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
702 | 1223 |
% |
598 | 1224 |
|
809 | 1225 |
|
1226 |
||
1227 |
||
49 | 1228 |
\end{document} |
1229 |
||
803 | 1230 |
|
1231 |
||
1232 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1233 |
\begin{frame}[c] |
|
1234 |
\frametitle{Parser Combinators} |
|
1235 |
||
1236 |
Parser combinators: \bigskip |
|
1237 |
||
1238 |
\begin{minipage}{1.1\textwidth} |
|
1239 |
\begin{center} |
|
1240 |
\mbox{}\hspace{-12mm}\mbox{}$\underbrace{\text{list of tokens}}_{\text{input}}$ \bl{$\Rightarrow$} |
|
1241 |
$\underbrace{\text{set of (parsed input, unparsed input)}}_{\text{output}}$ |
|
1242 |
\end{center} |
|
1243 |
\end{minipage}\bigskip |
|
1244 |
||
1245 |
\begin{itemize} |
|
1246 |
\item atomic parsers |
|
1247 |
\item sequencing |
|
1248 |
\item alternative |
|
1249 |
\item semantic action (map-parser) |
|
1250 |
\end{itemize} |
|
1251 |
||
1252 |
\end{frame} |
|
1253 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1254 |
||
1255 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1256 |
\begin{frame}[c] |
|
1257 |
||
1258 |
Atomic parsers, for example, number tokens |
|
1259 |
||
1260 |
\begin{center} |
|
1261 |
\bl{$\texttt{Num(123)}::rest \;\Rightarrow\; \{(\texttt{Num(123)}, rest)\}$} |
|
1262 |
\end{center}\bigskip |
|
1263 |
||
1264 |
\begin{itemize} |
|
1265 |
\item you consume one or more token from the\\ |
|
1266 |
input (stream) |
|
1267 |
\item also works for characters and strings |
|
1268 |
\end{itemize} |
|
1269 |
\end{frame} |
|
1270 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1271 |
||
1272 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1273 |
\begin{frame}[c] |
|
1274 |
||
1275 |
Alternative parser (code \bl{$p\;||\;q$})\bigskip |
|
1276 |
||
1277 |
\begin{itemize} |
|
1278 |
\item apply \bl{$p$} and also \bl{$q$}; then combine |
|
1279 |
the outputs |
|
1280 |
\end{itemize} |
|
1281 |
||
1282 |
\begin{center} |
|
1283 |
\large \bl{$p(\text{input}) \cup q(\text{input})$} |
|
1284 |
\end{center} |
|
1285 |
||
1286 |
\end{frame} |
|
1287 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1288 |
||
1289 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1290 |
\begin{frame}[c] |
|
1291 |
||
1292 |
Sequence parser (code \bl{$p\sim q$})\bigskip |
|
1293 |
||
1294 |
\begin{itemize} |
|
1295 |
\item apply first \bl{$p$} producing a set of pairs |
|
1296 |
\item then apply \bl{$q$} to the unparsed part |
|
1297 |
\item then combine the results:\medskip |
|
1298 |
\begin{center} |
|
1299 |
((output$_1$, output$_2$), unparsed part) |
|
1300 |
\end{center} |
|
1301 |
\end{itemize} |
|
1302 |
||
1303 |
\begin{center} |
|
1304 |
\begin{tabular}{l} |
|
1305 |
\large \bl{$\{((o_1, o_2), u_2) \;|\;$}\\[2mm] |
|
1306 |
\large\mbox{}\hspace{15mm} \bl{$(o_1, u_1) \in p(\text{input}) \wedge$}\\[2mm] |
|
1307 |
\large\mbox{}\hspace{15mm} \bl{$(o_2, u_2) \in q(u_1)\}$} |
|
1308 |
\end{tabular} |
|
1309 |
\end{center} |
|
1310 |
||
1311 |
||
1312 |
\end{frame} |
|
1313 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1314 |
||
1315 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1316 |
\begin{frame}[c] |
|
1317 |
||
1318 |
Map-parser (code \bl{$p.map(f)\;$})\bigskip |
|
1319 |
||
1320 |
\begin{itemize} |
|
1321 |
\item apply \bl{$p$} producing a set of pairs |
|
1322 |
\item then apply the function \bl{$f$} to each first component |
|
1323 |
\end{itemize} |
|
1324 |
||
1325 |
\begin{center} |
|
1326 |
\begin{tabular}{l} |
|
1327 |
\large \bl{$\{(f(o_1), u_1) \;|\; (o_1, u_1) \in p(\text{input})\}$} |
|
1328 |
\end{tabular} |
|
1329 |
\end{center}\bigskip\bigskip\pause |
|
1330 |
||
1331 |
\bl{$f$} is the semantic action (``what to do with the parsed input'') |
|
1332 |
||
1333 |
\end{frame} |
|
1334 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1335 |
||
1336 |
||
1337 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1338 |
\mode<presentation>{ |
|
1339 |
\begin{frame}[c] |
|
1340 |
\frametitle{\begin{tabular}{c}Semantic Actions\end{tabular}} |
|
1341 |
||
1342 |
Addition |
|
1343 |
||
1344 |
\begin{center} |
|
1345 |
\bl{$\meta{T} \sim + \sim \meta{E} \Rightarrow \underbrace{f\,((x,y), z) \Rightarrow x + z}_{\text{semantic action}}$} |
|
1346 |
\end{center}\pause |
|
1347 |
||
1348 |
Multiplication |
|
1349 |
||
1350 |
\begin{center} |
|
1351 |
\bl{$\meta{F} \sim * \sim \meta{T} \Rightarrow f\,((x,y), z) \Rightarrow x * z$} |
|
1352 |
\end{center}\pause |
|
1353 |
||
1354 |
Parenthesis |
|
1355 |
||
1356 |
\begin{center} |
|
1357 |
\bl{$\text{(} \sim \meta{E} \sim \text{)} \Rightarrow f\,((x,y), z) \Rightarrow y$} |
|
1358 |
\end{center} |
|
1359 |
||
1360 |
\end{frame}} |
|
1361 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1362 |
||
1363 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1364 |
\begin{frame}[c] |
|
1365 |
\frametitle{Types of Parsers} |
|
1366 |
||
1367 |
\begin{itemize} |
|
1368 |
\item {\bf Sequencing}: if \bl{$p$} returns results of type \bl{$T$}, and \bl{$q$} results of type \bl{$S$}, |
|
1369 |
then \bl{$p \sim q$} returns results of type |
|
1370 |
||
1371 |
\begin{center} |
|
1372 |
\bl{$T \times S$} |
|
1373 |
\end{center}\pause |
|
1374 |
||
1375 |
\item {\bf Alternative}: if \bl{$p$} returns results of type \bl{$T$} then \bl{$q$} \alert{must} also have results of type \bl{$T$}, |
|
1376 |
and \bl{$p \;||\; q$} returns results of type |
|
1377 |
||
1378 |
\begin{center} |
|
1379 |
\bl{$T$} |
|
1380 |
\end{center}\pause |
|
1381 |
||
1382 |
\item {\bf Semantic Action}: if \bl{$p$} returns results of type \bl{$T$} and \bl{$f$} is a function from |
|
1383 |
\bl{$T$} to \bl{$S$}, then |
|
1384 |
\bl{$p \Rightarrow f$} returns results of type |
|
1385 |
||
1386 |
\begin{center} |
|
1387 |
\bl{$S$} |
|
1388 |
\end{center} |
|
1389 |
||
1390 |
\end{itemize} |
|
1391 |
||
1392 |
\end{frame} |
|
1393 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1394 |
||
1395 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1396 |
\begin{frame}[c] |
|
1397 |
\frametitle{Input Types of Parsers} |
|
1398 |
||
1399 |
\begin{itemize} |
|
1400 |
\item input: \alert{token list} |
|
1401 |
\item output: set of (output\_type, \alert{token list}) |
|
1402 |
\end{itemize}\bigskip\pause |
|
1403 |
||
1404 |
actually it can be any input type as long as it is a kind of |
|
1405 |
sequence (for example a string) |
|
1406 |
||
1407 |
\end{frame} |
|
1408 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1409 |
||
1410 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1411 |
\begin{frame}[c] |
|
1412 |
\frametitle{Scannerless Parsers} |
|
1413 |
||
1414 |
\begin{itemize} |
|
1415 |
\item input: \alert{string} |
|
1416 |
\item output: set of (output\_type, \alert{string}) |
|
1417 |
\end{itemize}\bigskip\bigskip |
|
1418 |
||
1419 |
but using lexers is better because whitespaces or comments can be |
|
1420 |
filtered out; then input is a sequence of tokens |
|
1421 |
||
1422 |
\end{frame} |
|
1423 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1424 |
||
1425 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1426 |
\begin{frame}[c] |
|
1427 |
\frametitle{Successful Parses} |
|
1428 |
||
1429 |
\begin{itemize} |
|
1430 |
\item input: string |
|
1431 |
\item output: \alert{set of} (output\_type, string) |
|
1432 |
\end{itemize}\bigskip |
|
1433 |
||
1434 |
a parse is successful whenever the input has been fully |
|
1435 |
``consumed'' (that is the second component is empty) |
|
1436 |
||
1437 |
\end{frame} |
|
1438 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1439 |
||
1440 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1441 |
\begin{frame}[c] |
|
1442 |
\frametitle{Abstract Parser Class} |
|
1443 |
||
1444 |
\small |
|
1445 |
\lstinputlisting[language=Scala,xleftmargin=1mm] |
|
1446 |
{../progs/app7.scala} |
|
1447 |
\end{frame} |
|
1448 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1449 |
||
1450 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1451 |
\begin{frame}[c] |
|
1452 |
||
1453 |
\small |
|
1454 |
\fontsize{10}{12}\selectfont |
|
1455 |
\lstinputlisting[language=Scala,xleftmargin=1mm] |
|
1456 |
{../progs/app8.scala} |
|
1457 |
\end{frame} |
|
1458 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1459 |
||
1460 |
||
1461 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1462 |
\begin{frame}[c] |
|
1463 |
\frametitle{Two Grammars} |
|
1464 |
||
1465 |
Which languages are recognised by the following two grammars? |
|
1466 |
||
1467 |
\begin{center} |
|
1468 |
\bl{\begin{tabular}{lcl} |
|
1469 |
$\meta{S}$ & $\rightarrow$ & $1 \cdot \meta{S} \cdot \meta{S}$\\ |
|
1470 |
& $|$ & $\epsilon$ |
|
1471 |
\end{tabular}} |
|
1472 |
\end{center}\bigskip |
|
1473 |
||
1474 |
\begin{center} |
|
1475 |
\bl{\begin{tabular}{lcl} |
|
1476 |
$\meta{U}$ & $\rightarrow$ & $1 \cdot \meta{U}$\\ |
|
1477 |
& $|$ & $\epsilon$ |
|
1478 |
\end{tabular}} |
|
1479 |
\end{center} |
|
1480 |
||
1481 |
\end{frame} |
|
1482 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1483 |
||
1484 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1485 |
\begin{frame}[t] |
|
1486 |
\frametitle{Ambiguous Grammars} |
|
1487 |
||
1488 |
\begin{center} |
|
1489 |
\begin{tikzpicture} |
|
1490 |
\begin{axis}[xlabel={\pcode{1}s},ylabel={time in secs}, |
|
1491 |
enlargelimits=false, |
|
1492 |
xtick={0,100,...,1000}, |
|
1493 |
xmax=1050, |
|
1494 |
ymax=33, |
|
1495 |
ytick={0,5,...,30}, |
|
1496 |
scaled ticks=false, |
|
1497 |
axis lines=left, |
|
1498 |
width=11cm, |
|
1499 |
height=7cm, |
|
1500 |
legend entries={unambiguous,ambiguous}, |
|
1501 |
legend pos=north east, |
|
1502 |
legend cell align=left, |
|
1503 |
x tick label style={font=\small,/pgf/number format/1000 sep={}}] |
|
1504 |
\addplot[blue,mark=*, mark options={fill=white}] |
|
1505 |
table {s-grammar1.data}; |
|
1506 |
\only<2>{ |
|
1507 |
\addplot[red,mark=triangle*, mark options={fill=white}] |
|
1508 |
table {s-grammar2.data};} |
|
1509 |
\end{axis} |
|
1510 |
\end{tikzpicture} |
|
1511 |
\end{center} |
|
1512 |
||
1513 |
\end{frame} |
|
1514 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1515 |
||
809 | 1516 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1517 |
||
803 | 1518 |
|
1519 |
||
1520 |
||
49 | 1521 |
%%% Local Variables: |
1522 |
%%% mode: latex |
|
1523 |
%%% TeX-master: t |
|
1524 |
%%% End: |
|
1525 |