author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Fri, 06 Nov 2015 04:54:41 +0000 | |
changeset 365 | 9b71dead1219 |
parent 295 | 19f23c4c2167 |
child 366 | 5a83336a9690 |
permissions | -rw-r--r-- |
49 | 1 |
\documentclass[dvipsnames,14pt,t]{beamer} |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
2 |
\usepackage{../slides} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
3 |
\usepackage{../graphics} |
215
828303e8e4af
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
4 |
\usepackage{../langs} |
828303e8e4af
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
5 |
\usepackage{../data} |
49 | 6 |
|
7 |
||
8 |
% beamer stuff |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
9 |
\renewcommand{\slidecaption}{AFL 06, King's College London} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
10 |
\newcommand{\bl}[1]{\textcolor{blue}{#1}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
11 |
%\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions |
49 | 12 |
|
13 |
\begin{document} |
|
14 |
||
15 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
16 |
\begin{frame}[t] |
49 | 17 |
\frametitle{% |
18 |
\begin{tabular}{@ {}c@ {}} |
|
19 |
\\[-3mm] |
|
20 |
\LARGE Automata and \\[-2mm] |
|
21 |
\LARGE Formal Languages (6)\\[3mm] |
|
22 |
\end{tabular}} |
|
23 |
||
24 |
\normalsize |
|
25 |
\begin{center} |
|
26 |
\begin{tabular}{ll} |
|
27 |
Email: & christian.urban at kcl.ac.uk\\ |
|
168
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
28 |
Office: & S1.27 (1st floor Strand Building)\\ |
49 | 29 |
Slides: & KEATS (also home work is there)\\ |
30 |
\end{tabular} |
|
31 |
\end{center} |
|
32 |
||
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
33 |
\end{frame} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
34 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
49 | 35 |
|
170
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
36 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
37 |
\begin{frame}[c] |
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
38 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
39 |
\mbox{}\\[-18mm]\mbox{} |
170
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
40 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
41 |
{\lstset{language=Scala}\fontsize{10}{12}\selectfont |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
42 |
\texttt{\lstinputlisting[xleftmargin=0mm]{../progs/pow.scala}}} |
170
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
43 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
44 |
\end{frame} |
170
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
45 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
49 | 46 |
|
47 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
48 |
\begin{frame}[c] |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
49 |
\small |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
50 |
\mbox{}\\[5mm] |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
51 |
%\begin{textblock}{10}(3,5) |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
52 |
\begin{tikzpicture}[scale=1.5, |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
53 |
node distance=1cm, |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
54 |
every node/.style={minimum size=7mm}] |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
55 |
\node (r1) {\bl{$r_1$}}; |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
56 |
\node (r2) [right=of r1] {\bl{$r_2$}}; |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
57 |
\draw[->,line width=1mm] (r1) -- (r2) node[above,midway] {\bl{$der\,a$}}; |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
58 |
\node (r3) [right=of r2] {\bl{$r_3$}}; |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
59 |
\draw[->,line width=1mm] (r2) -- (r3) node[above,midway] {\bl{$der\,b$}}; |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
60 |
\node (r4) [right=of r3] {\bl{$r_4$}}; |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
61 |
\draw[->,line width=1mm] (r3) -- (r4) node[above,midway] {\bl{$der\,c$}}; |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
62 |
\draw (r4) node[anchor=west] {\;\raisebox{3mm}{\bl{$nullable$}}}; |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
63 |
\node (v4) [below=of r4] {\bl{$v_4$}}; |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
64 |
\draw[->,line width=1mm] (r4) -- (v4); |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
65 |
\node (v3) [left=of v4] {\bl{$v_3$}}; |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
66 |
\draw[->,line width=1mm] (v4) -- (v3) node[below,midway] {\bl{$inj\,c$}}; |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
67 |
\node (v2) [left=of v3] {\bl{$v_2$}}; |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
68 |
\draw[->,line width=1mm] (v3) -- (v2) node[below,midway] {\bl{$inj\,b$}}; |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
69 |
\node (v1) [left=of v2] {\bl{$v_1$}}; |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
70 |
\draw[->,line width=1mm] (v2) -- (v1) node[below,midway] {\bl{$inj\,a$}}; |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
71 |
\draw[->,line width=0.5mm] (r3) -- (v3); |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
72 |
\draw[->,line width=0.5mm] (r2) -- (v2); |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
73 |
\draw[->,line width=0.5mm] (r1) -- (v1); |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
74 |
\draw (r4) node[anchor=north west] {\;\raisebox{-8mm}{\bl{$mkeps$}}}; |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
75 |
\end{tikzpicture} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
76 |
%\end{textblock} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
77 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
78 |
\begin{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
79 |
\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
|
80 |
\\[-10mm] |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
81 |
\bl{$inj\,(c)\,c\,Empty$} & \bl{$\dn$} & \bl{$Char\,c$}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
82 |
\bl{$inj\,(r_1 + r_2)\,c\,Left(v)$} & \bl{$\dn$} & \bl{$Left(inj\,r_1\,c\,v)$}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
83 |
\bl{$inj\,(r_1 + r_2)\,c\,Right(v)$} & \bl{$\dn$} & \bl{$Right(inj\,r_2\,c\,v)$}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
84 |
\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)$}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
85 |
\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)$}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
86 |
\bl{$inj\,(r_1 \cdot r_2)\,c\,Right(v)$} & \bl{$\dn$} & \bl{$Seq(mkeps(r_1),inj\,r_2\,c\,v)$}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
87 |
\bl{$inj\,(r^*)\,c\,Seq(v,vs)$} & \bl{$\dn$} & \bl{$inj\,r\,c\,v\,::\,vs$}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
88 |
\end{tabular} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
89 |
\end{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
90 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
91 |
\end{frame} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
92 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
93 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
94 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
95 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
96 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
97 |
\newcommand{\qq}{\mbox{\texttt{"}}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
98 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
99 |
\begin{frame}[c] |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
100 |
\frametitle{CFGs} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
101 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
102 |
A \alert{context-free} grammar (CFG) \bl{$G$} consists of: |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
103 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
104 |
\begin{itemize} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
105 |
\item a finite set of nonterminal symbols (upper case) |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
106 |
\item a finite terminal symbols or tokens (lower case) |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
107 |
\item a start symbol (which must be a nonterminal) |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
108 |
\item a set of rules |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
109 |
\begin{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
110 |
\bl{$A \rightarrow \text{rhs}_1 | \text{rhs}_2 | \ldots$} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
111 |
\end{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
112 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
113 |
where \bl{rhs} are sequences involving terminals and nonterminals (can also be empty).\medskip\pause |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
114 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
115 |
\end{itemize} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
116 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
117 |
\end{frame} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
118 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
119 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
120 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
121 |
\mode<presentation>{ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
122 |
\begin{frame}[c] |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
123 |
\frametitle{\begin{tabular}{c}Hierarchy of Languages\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
124 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
125 |
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
|
126 |
|
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
127 |
\begin{center} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
128 |
\begin{tikzpicture} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
129 |
[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
|
130 |
|
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
131 |
\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
|
132 |
\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
|
133 |
\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
|
134 |
\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
|
135 |
\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
|
136 |
\end{tikzpicture} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
137 |
|
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
138 |
\end{center} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
139 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
140 |
\end{frame}} |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
141 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
142 |
|
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
143 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
144 |
\mode<presentation>{ |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
145 |
\begin{frame}[c] |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
146 |
\frametitle{\begin{tabular}{c}Arithmetic Expressions\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
147 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
148 |
A grammar for arithmetic expressions and numbers: |
50 | 149 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
150 |
\begin{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
151 |
\bl{\begin{tabular}{lcl} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
152 |
$E$ & $\rightarrow$ & $E \cdot + \cdot E \;|\;E \cdot * \cdot E \;|\;( \cdot E \cdot ) \;|\;N$ \\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
153 |
$N$ & $\rightarrow$ & $N \cdot N \;|\; 0 \;|\; 1 \;|\: \ldots \;|\; 9$ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
154 |
\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
155 |
\end{center} |
49 | 156 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
157 |
Unfortunately it is left-recursive (and ambiguous).\medskip\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
158 |
A problem for \alert{recursive descent parsers} (e.g.~parser combinators). |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
159 |
\bigskip\pause |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
160 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
161 |
\end{frame}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
162 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
163 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
164 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
165 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
166 |
\mode<presentation>{ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
167 |
\begin{frame}[t] |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
168 |
\frametitle{\begin{tabular}{c}Numbers\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
169 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
170 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
171 |
|
49 | 172 |
\begin{center} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
173 |
\bl{\begin{tabular}{lcl} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
174 |
$N$ & $\rightarrow$ & $N \cdot N \;|\; 0 \;|\; 1 \;|\; \ldots \;|\; 9$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
175 |
\end{tabular}} |
49 | 176 |
\end{center} |
177 |
||
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
178 |
A non-left-recursive, non-ambiguous grammar for numbers: |
49 | 179 |
|
50 | 180 |
\begin{center} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
181 |
\bl{\begin{tabular}{lcl} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
182 |
$N$ & $\rightarrow$ & $0 \cdot N \;|\;1 \cdot N \;|\;\ldots\;|\; 0 \;|\; 1 \;|\; \ldots \;|\; 9$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
183 |
\end{tabular}} |
50 | 184 |
\end{center} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
185 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
186 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
187 |
\end{frame}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
188 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
189 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
190 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
191 |
\mode<presentation>{ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
192 |
\begin{frame}[c] |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
193 |
\frametitle{\begin{tabular}{c}Operator Precedences\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
194 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
195 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
196 |
To disambiguate |
49 | 197 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
198 |
\begin{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
199 |
\bl{\begin{tabular}{lcl} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
200 |
$E$ & $\rightarrow$ & $E \cdot + \cdot E \;|\;E \cdot * \cdot E \;|\;( \cdot E \cdot ) \;|\;N$ \\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
201 |
\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
202 |
\end{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
203 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
204 |
Decide on how many precedence levels, say\medskip\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
205 |
\hspace{5mm}highest for \bl{$()$}, medium for \bl{*}, lowest for \bl{+} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
206 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
207 |
\begin{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
208 |
\bl{\begin{tabular}{lcl} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
209 |
$E_{low}$ & $\rightarrow$ & $E_{med} \cdot + \cdot E_{low} \;|\; E_{med}$ \\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
210 |
$E_{med}$ & $\rightarrow$ & $E_{hi} \cdot * \cdot E_{med} \;|\; E_{hi}$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
211 |
$E_{hi}$ & $\rightarrow$ & $( \cdot E_{low} \cdot ) \;|\;N$ \\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
212 |
\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
213 |
\end{center}\pause |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
214 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
215 |
\small What happens with \bl{$1 + 3 + 4$}? |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
216 |
\end{frame}} |
49 | 217 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
218 |
||
219 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
220 |
\mode<presentation>{ |
49 | 221 |
\begin{frame}[c] |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
222 |
\frametitle{\begin{tabular}{c}Removing Left-Recursion\end{tabular}} |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
223 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
224 |
The rule for numbers is directly left-recursive: |
49 | 225 |
|
226 |
\begin{center} |
|
50 | 227 |
\bl{\begin{tabular}{lcl} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
228 |
$N$ & $\rightarrow$ & $N \cdot N \;|\; 0 \;|\; 1\;\;\;\;(\ldots)$ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
229 |
\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
230 |
\end{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
231 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
232 |
Translate |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
233 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
234 |
\begin{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
235 |
\begin{tabular}{ccc} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
236 |
\bl{\begin{tabular}{lcl} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
237 |
$N$ & $\rightarrow$ & $N \cdot \alpha$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
238 |
& $\;|\;$ & $\beta$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
239 |
\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
240 |
\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
241 |
& {\Large$\Rightarrow$} & |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
242 |
\bl{\begin{tabular}{lcl} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
243 |
$N$ & $\rightarrow$ & $\beta \cdot N'$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
244 |
$N'$ & $\rightarrow$ & $\alpha \cdot N'$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
245 |
& $\;|\;$ & $\epsilon$ |
50 | 246 |
\end{tabular}} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
247 |
\end{tabular} |
50 | 248 |
\end{center}\pause |
249 |
||
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
250 |
Which means |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
251 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
252 |
\begin{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
253 |
\bl{\begin{tabular}{lcl} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
254 |
$N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1 \cdot N'$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
255 |
$N'$ & $\rightarrow$ & $N \cdot N' \;|\; \epsilon$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
256 |
\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
257 |
\end{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
258 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
259 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
260 |
\end{frame}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
261 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
262 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
263 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
264 |
\mode<presentation>{ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
265 |
\begin{frame}[c] |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
266 |
\frametitle{\begin{tabular}{c}Chomsky Normal Form\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
267 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
268 |
All rules must be of the form |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
269 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
270 |
\begin{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
271 |
\bl{$A \rightarrow a$} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
272 |
\end{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
273 |
|
50 | 274 |
or |
275 |
||
276 |
\begin{center} |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
277 |
\bl{$A \rightarrow B\cdot C$} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
278 |
\end{center} |
49 | 279 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
280 |
No rule can contain \bl{$\epsilon$}. |
49 | 281 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
282 |
\end{frame}} |
49 | 283 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
284 |
||
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
285 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
286 |
\mode<presentation>{ |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
287 |
\begin{frame}[c] |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
288 |
\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
|
289 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
290 |
\begin{enumerate} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
291 |
\item If \bl{$A\rightarrow \alpha \cdot B \cdot \beta$} and \bl{$B \rightarrow \epsilon$} are in the grammar, |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
292 |
then add \bl{$A\rightarrow \alpha \cdot \beta$} (iterate if necessary). |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
293 |
\item Throw out all \bl{$B \rightarrow \epsilon$}. |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
294 |
\end{enumerate} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
295 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
296 |
\small |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
297 |
\begin{center} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
298 |
\begin{tabular}{ccc} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
299 |
\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
|
300 |
$N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1\cdot N'$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
301 |
$N'$ & $\rightarrow$ & $N \cdot N'\;|\;\epsilon$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
302 |
\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
303 |
\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
304 |
\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
305 |
\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
306 |
\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
307 |
\end{tabular}} & |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
308 |
\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
|
309 |
\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
310 |
$N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1\cdot N'\;|\;0\;|\;1$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
311 |
$N'$ & $\rightarrow$ & $N \cdot N'\;|\;N\;|\;\epsilon$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
312 |
\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
313 |
$N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1\cdot N'\;|\;0\;|\;1$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
314 |
$N'$ & $\rightarrow$ & $N \cdot N'\;|\;N$\\ |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
315 |
\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
316 |
\end{tabular} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
317 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
318 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
319 |
\pause\normalsize |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
320 |
\begin{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
321 |
\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
|
322 |
$N$ & $\rightarrow$ & $0 \cdot N\;|\; 1\cdot N\;|\;0\;|\;1$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
323 |
\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
324 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
325 |
\end{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
326 |
\end{frame}} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
327 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
328 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
329 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
330 |
|
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
331 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
332 |
\mode<presentation>{ |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
333 |
\begin{frame}[c] |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
334 |
\frametitle{\begin{tabular}{c}CYK Algorithm\end{tabular}} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
335 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
336 |
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
|
337 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
338 |
\begin{center} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
339 |
\bl{\begin{tabular}{@ {}lcl@ {}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
340 |
$S$ & $\rightarrow$ & $N\cdot P$ \\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
341 |
$P$ & $\rightarrow$ & $V\cdot N$ \\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
342 |
$N$ & $\rightarrow$ & $N\cdot N$ \\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
343 |
$N$ & $\rightarrow$ & $\texttt{students} \;|\; \texttt{Jeff} \;|\; \texttt{geometry} \;|\; \texttt{trains} $ \\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
344 |
$V$ & $\rightarrow$ & $\texttt{trains}$ |
49 | 345 |
\end{tabular}} |
346 |
\end{center} |
|
347 |
||
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
348 |
\bl{\texttt{Jeff trains geometry students}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
349 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
350 |
\end{frame}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
351 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
352 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
353 |
\mode<presentation>{ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
354 |
\begin{frame}[c] |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
355 |
\frametitle{\begin{tabular}{c}CYK Algorithm\end{tabular}} |
49 | 356 |
|
357 |
||
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
358 |
\begin{itemize} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
359 |
\item fastest possible algorithm for recognition problem |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
360 |
\item runtime is \bl{$O(n^3)$}\bigskip |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
361 |
\item grammars need to be transferred into CNF |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
362 |
\end{itemize} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
363 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
364 |
\end{frame}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
365 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
366 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
367 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
368 |
\mode<presentation>{ |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
369 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
370 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
371 |
\begin{center} |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
372 |
\bl{\begin{tabular}{@{}lcl@{}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
373 |
\textit{Stmt} & $\rightarrow$ & $\texttt{skip}$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
374 |
& $|$ & \textit{Id}\;\texttt{:=}\;\textit{AExp}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
375 |
& $|$ & \texttt{if}\; \textit{BExp} \;\texttt{then}\; \textit{Block} \;\texttt{else}\; \textit{Block}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
376 |
& $|$ & \texttt{while}\; \textit{BExp} \;\texttt{do}\; \textit{Block}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
377 |
& $|$ & \texttt{read}\;\textit{Id}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
378 |
& $|$ & \texttt{write}\;\textit{Id}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
379 |
& $|$ & \texttt{write}\;\textit{String}\medskip\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
380 |
\textit{Stmts} & $\rightarrow$ & \textit{Stmt} \;\texttt{;}\; \textit{Stmts}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
381 |
& $|$ & \textit{Stmt}\medskip\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
382 |
\textit{Block} & $\rightarrow$ & \texttt{\{}\,\textit{Stmts}\,\texttt{\}}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
383 |
& $|$ & \textit{Stmt}\medskip\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
384 |
\textit{AExp} & $\rightarrow$ & \ldots\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
385 |
\textit{BExp} & $\rightarrow$ & \ldots\\ |
50 | 386 |
\end{tabular}} |
387 |
\end{center} |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
388 |
\end{frame}} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
389 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
390 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
391 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
392 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
393 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
394 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
395 |
\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
|
396 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
397 |
\end{frame}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
398 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
399 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
400 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
401 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
402 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
403 |
\begin{frame}[c] |
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
404 |
\frametitle{\begin{tabular}{c}An Interpreter\end{tabular}} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
405 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
406 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
407 |
\bl{\begin{tabular}{l} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
408 |
$\{$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
409 |
\;\;$x := 5 \text{;}$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
410 |
\;\;$y := x * 3\text{;}$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
411 |
\;\;$y := x * 4\text{;}$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
412 |
\;\;$x := u * 3$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
413 |
$\}$ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
414 |
\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
415 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
416 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
417 |
\begin{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
418 |
\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
|
419 |
\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
|
420 |
\end{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
421 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
422 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
423 |
\end{frame}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
424 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
425 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
426 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
427 |
\mode<presentation>{ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
428 |
\begin{frame}[c] |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
429 |
\frametitle{\begin{tabular}{c}Interpreter\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
430 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
431 |
\begin{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
432 |
\bl{\begin{tabular}{@{}lcl@{}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
433 |
$\text{eval}(n, E)$ & $\dn$ & $n$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
434 |
$\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
|
435 |
$\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
|
436 |
$\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
|
437 |
$\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
|
438 |
$\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
|
439 |
$\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
|
440 |
$\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
|
441 |
\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
442 |
\end{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
443 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
444 |
\end{frame}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
445 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
446 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
447 |
\mode<presentation>{ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
448 |
\begin{frame}[c] |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
449 |
\frametitle{\begin{tabular}{c}Interpreter (2)\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
450 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
451 |
\begin{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
452 |
\bl{\begin{tabular}{@{}lcl@{}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
453 |
$\text{eval}(\text{skip}, E)$ & $\dn$ & $E$\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
454 |
$\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
|
455 |
\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
|
456 |
\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
|
457 |
\text{eval}(cs_1,E)$}\\ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
458 |
\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
|
459 |
\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
|
460 |
\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
|
461 |
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{then}\; |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
462 |
\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
|
463 |
\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
|
464 |
$\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
|
465 |
\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
466 |
\end{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
467 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
468 |
\end{frame}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
469 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
470 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
471 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
472 |
\begin{frame}[c] |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
473 |
\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
|
474 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
475 |
\mbox{}\\[-18mm]\mbox{} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
476 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
477 |
{\lstset{language=While}%%\fontsize{10}{12}\selectfont |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
478 |
\texttt{\lstinputlisting{../progs/loops.while}}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
479 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
480 |
\end{frame} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
481 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
482 |
|
365
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
483 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
484 |
\mode<presentation>{ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
485 |
\begin{frame}[t] |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
486 |
\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
|
487 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
488 |
\begin{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
489 |
\begin{tikzpicture} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
490 |
\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
|
491 |
\addplot+[smooth] file {interpreted.data}; |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
492 |
\end{axis} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
493 |
\end{tikzpicture} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
494 |
\end{center} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
495 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
496 |
\end{frame}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
497 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
498 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
499 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
500 |
\mode<presentation>{ |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
501 |
\begin{frame}[c] |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
502 |
\frametitle{\begin{tabular}{c}Java Virtual Machine\end{tabular}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
503 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
504 |
\begin{itemize} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
505 |
\item introduced in 1995 |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
506 |
\item is a stack-based VM (like Postscript, CLR of .Net) |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
507 |
\item contains a JIT compiler |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
508 |
\item many languages take advantage of JVM's infrastructure (JRE) |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
509 |
\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
|
510 |
\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
|
511 |
\end{itemize} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
512 |
|
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
513 |
\end{frame}} |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
514 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
9b71dead1219
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
295
diff
changeset
|
515 |
|
50 | 516 |
|
49 | 517 |
\end{document} |
518 |
||
519 |
%%% Local Variables: |
|
520 |
%%% mode: latex |
|
521 |
%%% TeX-master: t |
|
522 |
%%% End: |
|
523 |