author | Christian Urban <urbanc@in.tum.de> |
Tue, 16 Oct 2018 08:28:12 +0100 | |
changeset 579 | 1a521448d211 |
parent 550 | 71fc4a7a7039 |
child 582 | d236e75e1d55 |
permissions | -rw-r--r-- |
44 | 1 |
\documentclass[dvipsnames,14pt,t]{beamer} |
270
4dbeaf43031d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
2 |
\usepackage{../slides} |
4dbeaf43031d
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:
169
diff
changeset
|
4 |
\usepackage{../langs} |
828303e8e4af
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
5 |
\usepackage{../data} |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
6 |
\usepackage{../grammar} |
44 | 7 |
|
270
4dbeaf43031d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
8 |
\hfuzz=220pt |
4dbeaf43031d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
9 |
|
4dbeaf43031d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
10 |
\pgfplotsset{compat=1.11} |
4dbeaf43031d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
11 |
|
4dbeaf43031d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
12 |
\newcommand{\bl}[1]{\textcolor{blue}{#1}} |
44 | 13 |
|
14 |
% beamer stuff |
|
445 | 15 |
\renewcommand{\slidecaption}{CFL 05, King's College London} |
270
4dbeaf43031d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
16 |
|
44 | 17 |
|
18 |
\begin{document} |
|
19 |
||
20 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
270
4dbeaf43031d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
21 |
\begin{frame}[t] |
44 | 22 |
\frametitle{% |
23 |
\begin{tabular}{@ {}c@ {}} |
|
24 |
\\[-3mm] |
|
445 | 25 |
\LARGE Compilers and \\[-2mm] |
44 | 26 |
\LARGE Formal Languages (5)\\[3mm] |
27 |
\end{tabular}} |
|
28 |
||
29 |
\normalsize |
|
30 |
\begin{center} |
|
31 |
\begin{tabular}{ll} |
|
32 |
Email: & christian.urban at kcl.ac.uk\\ |
|
500 | 33 |
Office: & N7.07 (North Wing, Bush House)\\ |
44 | 34 |
Slides: & KEATS (also home work is there)\\ |
35 |
\end{tabular} |
|
36 |
\end{center} |
|
270
4dbeaf43031d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
37 |
\end{frame} |
289
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
38 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
44 | 39 |
|
528 | 40 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
41 |
% \begin{frame}[c] |
|
42 |
% \frametitle{Survey: Thanks!} |
|
43 |
% \small |
|
462 | 44 |
|
528 | 45 |
% \begin{itemize} |
46 |
% \item {\bf My Voice} ``could be a bit louder'' |
|
47 |
% \item {\bf Writing} ``sometimes a bit difficult to read'' |
|
48 |
% \item {\bf Recording} ``video caps of blackboard'' |
|
49 |
% \item ``It's all great'' |
|
50 |
% \end{itemize} |
|
462 | 51 |
|
528 | 52 |
% \end{frame} |
53 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
462 | 54 |
|
55 |
||
56 |
||
57 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
58 |
\begin{frame}[c] |
|
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
59 |
\frametitle{\begin{tabular}{c}Last Week\\[-1mm] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
60 |
Regexes and Values\end{tabular}} |
44 | 61 |
|
289
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
62 |
Regular expressions and their corresponding values: |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
63 |
|
147
4725bba8ef26
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
64 |
\begin{center} |
289
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
65 |
\begin{columns} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
66 |
\begin{column}{3cm} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
67 |
\begin{tabular}{@{}rrl@{}} |
445 | 68 |
\bl{$r$} & \bl{$::=$} & \bl{$\ZERO$}\\ |
69 |
& \bl{$\mid$} & \bl{$\ONE$} \\ |
|
289
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
70 |
& \bl{$\mid$} & \bl{$c$} \\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
71 |
& \bl{$\mid$} & \bl{$r_1 \cdot r_2$}\\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
72 |
& \bl{$\mid$} & \bl{$r_1 + r_2$} \\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
73 |
\\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
74 |
& \bl{$\mid$} & \bl{$r^*$} \\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
75 |
\end{tabular} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
76 |
\end{column} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
77 |
\begin{column}{3cm} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
78 |
\begin{tabular}{@{\hspace{-7mm}}rrl@{}} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
79 |
\bl{$v$} & \bl{$::=$} & \\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
80 |
& & \bl{$Empty$} \\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
81 |
& \bl{$\mid$} & \bl{$Char(c)$} \\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
82 |
& \bl{$\mid$} & \bl{$Seq(v_1,v_2)$}\\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
83 |
& \bl{$\mid$} & \bl{$Left(v)$} \\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
84 |
& \bl{$\mid$} & \bl{$Right(v)$} \\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
85 |
& \bl{$\mid$} & \bl{$[v_1,\ldots\,v_n]$} \\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
86 |
\end{tabular} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
87 |
\end{column} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
88 |
\end{columns} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
89 |
\end{center} |
44 | 90 |
|
289
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
91 |
|
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
92 |
\end{frame} |
147
4725bba8ef26
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
93 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
4725bba8ef26
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
94 |
|
44 | 95 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
272
1446bc47a294
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
270
diff
changeset
|
96 |
\begin{frame}[c] |
44 | 97 |
|
289
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
98 |
\begin{textblock}{10}(3,5) |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
99 |
\begin{tikzpicture}[scale=2,node distance=1.3cm,every node/.style={minimum size=8mm}] |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
100 |
\node (r1) {\bl{$r_1$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
101 |
\node (r2) [right=of r1] {\bl{$r_2$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
102 |
\draw[->,line width=1mm] (r1) -- (r2) node[above,midway] {\bl{$der\,a$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
103 |
\node (r3) [right=of r2] {\bl{$r_3$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
104 |
\draw[->,line width=1mm] (r2) -- (r3) node[above,midway] {\bl{$der\,b$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
105 |
\node (r4) [right=of r3] {\bl{$r_4$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
106 |
\draw[->,line width=1mm] (r3) -- (r4) node[above,midway] {\bl{$der\,c$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
107 |
\draw (r4) node[anchor=west] {\;\raisebox{3mm}{\bl{$nullable$}}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
108 |
\node (v4) [below=of r4] {\bl{$v_4$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
109 |
\draw[->,line width=1mm] (r4) -- (v4); |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
110 |
\node (v3) [left=of v4] {\bl{$v_3$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
111 |
\draw[->,line width=1mm] (v4) -- (v3) node[below,midway] {\bl{$inj\,c$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
112 |
\node (v2) [left=of v3] {\bl{$v_2$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
113 |
\draw[->,line width=1mm] (v3) -- (v2) node[below,midway] {\bl{$inj\,b$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
114 |
\node (v1) [left=of v2] {\bl{$v_1$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
115 |
\draw[->,line width=1mm] (v2) -- (v1) node[below,midway] {\bl{$inj\,a$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
116 |
\draw[->,line width=0.5mm] (r3) -- (v3); |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
117 |
\draw[->,line width=0.5mm] (r2) -- (v2); |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
118 |
\draw[->,line width=0.5mm] (r1) -- (v1); |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
119 |
\draw (r4) node[anchor=north west] {\;\raisebox{-8mm}{\bl{$mkeps$}}}; |
147
4725bba8ef26
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
120 |
\end{tikzpicture} |
289
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
121 |
\end{textblock} |
147
4725bba8ef26
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
122 |
|
289
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
123 |
\begin{textblock}{6}(1,0.8) |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
124 |
\begin{bubble}[6cm] |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
125 |
\small |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
126 |
\begin{tabular}{ll} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
127 |
\bl{$r_1$}: & \bl{$a \cdot (b \cdot c)$}\\ |
445 | 128 |
\bl{$r_2$}: & \bl{$\ONE \cdot (b \cdot c)$}\\ |
129 |
\bl{$r_3$}: & \bl{$(\ZERO \cdot (b \cdot c)) + (\ONE \cdot c)$}\\ |
|
130 |
\bl{$r_4$}: & \bl{$(\ZERO \cdot (b \cdot c)) + ((\ZERO \cdot c) + \ONE)$}\\ |
|
147
4725bba8ef26
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
131 |
\end{tabular} |
289
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
132 |
\end{bubble} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
133 |
\end{textblock} |
147
4725bba8ef26
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
134 |
|
289
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
135 |
\begin{textblock}{6}(1,11.4) |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
136 |
\begin{bubble}[7.6cm] |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
137 |
\small |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
138 |
\begin{tabular}{ll} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
139 |
\bl{$v_1$}: & \bl{$Seq(Char(a), Seq(Char(b), Char(c)))$}\\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
140 |
\bl{$v_2$}: & \bl{$Seq(Empty, Seq(Char(b), Char(c)))$}\\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
141 |
\bl{$v_3$}: & \bl{$Right(Seq(Empty, Char(c)))$}\\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
142 |
\bl{$v_4$}: & \bl{$Right(Right(Empty))$}\\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
143 |
\end{tabular} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
144 |
\end{bubble} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
145 |
\end{textblock} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
146 |
|
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
147 |
\begin{textblock}{6}(12,11.4) |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
148 |
\begin{bubble}[2cm] |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
149 |
\small |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
150 |
\begin{tabular}{ll} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
151 |
\bl{$|v_1|$}: & \bl{$abc$}\\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
152 |
\bl{$|v_2|$}: & \bl{$bc$}\\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
153 |
\bl{$|v_3|$}: & \bl{$c$}\\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
154 |
\bl{$|v_4|$}: & \bl{$[]$} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
155 |
\end{tabular} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
156 |
\end{bubble} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
157 |
\end{textblock} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
158 |
|
44 | 159 |
|
272
1446bc47a294
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
270
diff
changeset
|
160 |
\end{frame} |
44 | 161 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
162 |
||
289
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
163 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
164 |
\begin{frame}[c] |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
165 |
\frametitle{Simplification} |
147
4725bba8ef26
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
166 |
|
289
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
167 |
\begin{itemize} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
168 |
\item If we simplify after the derivative, then we are builing the |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
169 |
value for the simplified regular expression, but \emph{not} for the original |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
170 |
regular expression. |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
171 |
\end{itemize} |
44 | 172 |
|
147
4725bba8ef26
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
173 |
\begin{center} |
289
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
174 |
\begin{tikzpicture}[scale=2,node distance=1.3cm,every node/.style={minimum size=8mm}] |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
175 |
\node (r1) {\bl{$r_1$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
176 |
\node (r2) [right=of r1] {\bl{$r_2$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
177 |
\draw[->,line width=1mm] (r1) -- (r2) node[above,midway] {\bl{$der\,a$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
178 |
\node (r3) [right=of r2] {\bl{$r_3$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
179 |
\draw[->,line width=1mm] (r2) -- (r3) node[above,midway] {\bl{$der\,b$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
180 |
\node (r4) [right=of r3] {\bl{$r_4$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
181 |
\draw[->,line width=1mm] (r3) -- (r4) node[above,midway] {\bl{$der\,c$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
182 |
\draw (r4) node[anchor=west] {\;\raisebox{3mm}{\bl{$nullable$}}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
183 |
\node (v4) [below=of r4] {\bl{$v_4$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
184 |
\draw[->,line width=1mm] (r4) -- (v4); |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
185 |
\node (v3) [left=of v4] {\bl{$v_3$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
186 |
\draw[->,line width=1mm] (v4) -- (v3) node[below,midway] {\bl{$inj\,c$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
187 |
\node (v2) [left=of v3] {\bl{$v_2$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
188 |
\draw[->,line width=1mm] (v3) -- (v2) node[below,midway] {\bl{$inj\,b$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
189 |
\node (v1) [left=of v2] {\bl{$v_1$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
190 |
\draw[->,line width=1mm] (v2) -- (v1) node[below,midway] {\bl{$inj\,a$}}; |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
191 |
\draw[->,line width=0.5mm] (r3) -- (v3); |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
192 |
\draw[->,line width=0.5mm] (r2) -- (v2); |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
193 |
\draw[->,line width=0.5mm] (r1) -- (v1); |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
194 |
\draw (r4) node[anchor=north west] {\;\raisebox{-8mm}{\bl{$mkeps$}}}; |
147
4725bba8ef26
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
195 |
\end{tikzpicture} |
4725bba8ef26
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
196 |
\end{center} |
44 | 197 |
|
289
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
198 |
\small |
445 | 199 |
\hspace{4.5cm}\bl{$(b \cdot c) + (\ZERO + \ONE)$} |
289
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
200 |
$\mapsto$ |
445 | 201 |
\bl{$(b \cdot c) + \ONE$} |
289
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
202 |
|
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
203 |
\end{frame} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
204 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
205 |
|
528 | 206 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
207 |
% \begin{frame}[t] |
|
361
9c7eb266594c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
360
diff
changeset
|
208 |
|
528 | 209 |
% \begin{center} |
210 |
% \bl{$\only<1>{(b \cdot c)}% |
|
211 |
% \only<2-3>{(\underline{b \cdot c})}% |
|
212 |
% \only<1-3>{+}% |
|
213 |
% \only<1>{(\ZERO + \ONE)}% |
|
214 |
% \only<2-3>{(\underline{\ZERO + \ONE})}$}% |
|
215 |
% \only<4->{% |
|
216 |
% \bl{$\underline{(b \cdot c) + (\ZERO + \ONE)}$}% |
|
217 |
% } |
|
218 |
% $\mapsto$ |
|
219 |
% \bl{$(b \cdot c) + \ONE$} |
|
220 |
% \end{center}\bigskip |
|
361
9c7eb266594c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
360
diff
changeset
|
221 |
|
528 | 222 |
% \onslide<3->{% |
223 |
% \begin{center} |
|
224 |
% \begin{tabular}{lcl} |
|
225 |
% \bl{$f_{s1}$} & \bl{$=$} & \bl{$\lambda v.v$}\\ |
|
226 |
% \bl{$f_{s2}$} & \bl{$=$} & \bl{$\lambda v. \textit{Right}(v)$} |
|
227 |
% \end{tabular} |
|
228 |
% \end{center}} |
|
361
9c7eb266594c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
360
diff
changeset
|
229 |
|
528 | 230 |
% \only<4>{% |
231 |
% \begin{center} |
|
232 |
% \begin{tabular}{@{}l@{\hspace{1mm}}l@{}} |
|
233 |
% \bl{$f_{alt}(f_{s1}, f_{s2}) \dn$}\\ |
|
234 |
% \quad \bl{$\lambda v.\,$} |
|
235 |
% case \bl{$v = Left(v')$}: |
|
236 |
% & return \bl{$Left(f_{s1}(v'))$}\\ |
|
237 |
% \quad \phantom{$\lambda v.\,$} |
|
238 |
% case \bl{$v = Right(v')$}: |
|
239 |
% & return \bl{$Right(f_{s2}(v'))$}\\ |
|
240 |
% \end{tabular} |
|
241 |
% \end{center}}% |
|
242 |
% \only<5->{% |
|
243 |
% \begin{center} |
|
244 |
% \begin{tabular}{@{}l@{\hspace{1mm}}l@{}} |
|
245 |
% \only<5->{\phantom{\bl{$f_{alt}(f_{s1}, f_{s2}) \dn$}}}\\ |
|
246 |
% \quad \bl{$\lambda v.\,$} |
|
247 |
% case \bl{$v = Left(v')$}: |
|
248 |
% & return \bl{$Left(v')$}\\ |
|
249 |
% \quad \phantom{$\lambda v.\,$} |
|
250 |
% case \bl{$v = Right(v')$}: |
|
251 |
% & return \bl{$Right(Right(v'))$}\\ |
|
252 |
% \end{tabular} |
|
253 |
% \end{center}}% |
|
361
9c7eb266594c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
360
diff
changeset
|
254 |
|
528 | 255 |
% \only<6->{% |
256 |
% \begin{center} |
|
257 |
% \begin{tabular}{@{}l@{\hspace{4mm}}l@{}} |
|
258 |
% \bl{$\textit{mkeps}$} simplified case: & |
|
259 |
% \bl{$\textit{Right}(\textit{Empty})$}\\ |
|
260 |
% rectified case: & |
|
261 |
% \bl{$\textit{Right}(\textit{Right}(\textit{Empty}))$} |
|
262 |
% \end{tabular} |
|
263 |
% \end{center}}% |
|
361
9c7eb266594c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
360
diff
changeset
|
264 |
|
528 | 265 |
% \end{frame} |
266 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
361
9c7eb266594c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
360
diff
changeset
|
267 |
|
9c7eb266594c
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
360
diff
changeset
|
268 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
289
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
269 |
\begin{frame}[c] |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
270 |
\frametitle{Records} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
271 |
|
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
272 |
\begin{itemize} |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
273 |
\item new regex: \bl{$(x:r)$}\hspace{7mm}new value: |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
274 |
\bl{$Rec(x,v)$}\medskip |
44 | 275 |
|
289
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
276 |
\item \bl{$nullable(x:r) \dn nullable(r)$} |
529 | 277 |
\item \bl{$der\,c\,(x:r) \dn der\,c\,r$} |
289
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
278 |
\item \bl{$mkeps(x:r) \dn Rec(x, mkeps(r))$} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
279 |
\item \bl{$inj\,(x:r)\,c\,v \dn Rec(x, inj\,r\,c\,v)$} |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
280 |
\end{itemize}\bigskip\bigskip |
44 | 281 |
|
289
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
282 |
\small |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
283 |
for extracting subpatterns \bl{$(z: ((x:ab) + (y:ba))$} |
44 | 284 |
|
289
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
285 |
\end{frame} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
286 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
46 | 287 |
|
148
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
288 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
289 |
\begin{frame}[c] |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
290 |
\frametitle{Environments} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
291 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
292 |
Obtaining the ``recorded'' parts of a value: |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
293 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
294 |
\begin{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
295 |
\begin{tabular}{lcl} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
296 |
\bl{$env(Empty)$} & \bl{$\dn$} & \bl{$[]$}\\ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
297 |
\bl{$env(Char(c))$} & \bl{$\dn$} & \bl{$[]$}\\ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
298 |
\bl{$env(Left(v))$} & \bl{$\dn$} & \bl{$env(v)$}\\ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
299 |
\bl{$env(Right(v))$} & \bl{$\dn$} & \bl{$env(v)$}\\ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
300 |
\bl{$env(Seq(v_1,v_2))$}& \bl{$\dn$} & \bl{$env(v_1) \,@\, env(v_2)$}\\ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
301 |
\bl{$env([v_1,\ldots ,v_n])$} & \bl{$\dn$} & |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
302 |
\bl{$env(v_1) \,@\ldots @\, env(v_n)$}\\ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
303 |
\bl{$env(Rec(x:v))$} & \bl{$\dn$} & \bl{$(x:|v|) :: env(v)$}\\ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
304 |
\end{tabular} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
305 |
\end{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
306 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
307 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
308 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
309 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
310 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
311 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
312 |
\begin{frame}[c] |
289
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
313 |
\frametitle{While Tokens} |
150
a2d792ed768e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
149
diff
changeset
|
314 |
|
148
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
315 |
\begin{center} |
289
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
316 |
\begin{tabular}{@{}r@{\hspace{2mm}}c@{\hspace{2mm}}l@{}} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
317 |
\pcode{WHILE\_REGS} & $\dn$ & \raisebox{-1mm}{\large(}\pcode{("k" : KEYWORD)} +\\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
318 |
& & \phantom{(}\pcode{("i" : ID)} +\\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
319 |
& & \phantom{(}\pcode{("o" : OP)} + \\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
320 |
& & \phantom{(}\pcode{("n" : NUM)} + \\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
321 |
& & \phantom{(}\pcode{("s" : SEMI)} +\\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
322 |
& & \phantom{(}\pcode{("p" : (LPAREN + RPAREN))} +\\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
323 |
& & \phantom{(}\pcode{("b" : (BEGIN + END))} +\\ |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
324 |
& & \phantom{(}\pcode{("w" : WHITESPACE)}\raisebox{-1mm}{\large)$^*$} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
325 |
\end{tabular} |
148
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
326 |
\end{center} |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
327 |
|
289
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
328 |
\end{frame} |
c22c8baff491
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
329 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
148
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
330 |
|
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
331 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
332 |
|
148
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
333 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
334 |
\begin{frame}[t] |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
335 |
|
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
336 |
\consolas |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
337 |
\begin{center} |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
338 |
\code{"if true then then 42 else +"} |
148
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
339 |
\end{center} |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
340 |
|
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
341 |
\only<1>{ |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
342 |
\small\begin{tabular}{l} |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
343 |
KEYWORD(if),\\ |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
344 |
WHITESPACE,\\ |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
345 |
IDENT(true),\\ |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
346 |
WHITESPACE,\\ |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
347 |
KEYWORD(then),\\ |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
348 |
WHITESPACE,\\ |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
349 |
KEYWORD(then),\\ |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
350 |
WHITESPACE,\\ |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
351 |
NUM(42),\\ |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
352 |
WHITESPACE,\\ |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
353 |
KEYWORD(else),\\ |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
354 |
WHITESPACE,\\ |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
355 |
OP(+) |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
356 |
\end{tabular}} |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
357 |
|
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
358 |
\only<2>{ |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
359 |
\small\begin{tabular}{l} |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
360 |
KEYWORD(if),\\ |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
361 |
IDENT(true),\\ |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
362 |
KEYWORD(then),\\ |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
363 |
KEYWORD(then),\\ |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
364 |
NUM(42),\\ |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
365 |
KEYWORD(else),\\ |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
366 |
OP(+) |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
367 |
\end{tabular}} |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
368 |
|
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
369 |
\end{frame} |
148
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
370 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
371 |
|
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
372 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
373 |
\begin{frame}[c] |
528 | 374 |
\frametitle{Coursework: Nullable} |
148
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
375 |
|
528 | 376 |
\begin{center} |
377 |
\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}} |
|
378 |
\bl{$nullable([c_1 c_2 \ldots c_n])$} & \bl{$\dn$} & $?$\\ |
|
379 |
\bl{$nullable(r^+)$} & \bl{$\dn$} & $?$\\ |
|
380 |
\bl{$nullable(r^?)$} & \bl{$\dn$} & $?$\\ |
|
381 |
\bl{$nullable(r^{\{n\}})$} & \bl{$\dn$} & $?$\\ |
|
382 |
\bl{$nullable(r^{\{n..\}})$} & \bl{$\dn$} & $?$\\ |
|
383 |
\bl{$nullable(r^{\{..n\}})$} & \bl{$\dn$} & $?$\\ |
|
384 |
\bl{$nullable(r^{\{n..m\}})$} & \bl{$\dn$} & $?$\\ |
|
385 |
\bl{$nullable(\sim{}r)$} & \bl{$\dn$} & $?$\\ |
|
386 |
||
387 |
\end{tabular} |
|
388 |
\end{center} |
|
148
36eb7bfb0e63
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
147
diff
changeset
|
389 |
|
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
390 |
\end{frame} |
528 | 391 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
150
a2d792ed768e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
149
diff
changeset
|
392 |
|
290
3a2fa69ea675
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
289
diff
changeset
|
393 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
3a2fa69ea675
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
289
diff
changeset
|
394 |
\begin{frame}[c] |
528 | 395 |
%%\frametitle{Coursework: der} |
290
3a2fa69ea675
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
289
diff
changeset
|
396 |
|
3a2fa69ea675
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
289
diff
changeset
|
397 |
\begin{center} |
528 | 398 |
\begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}} |
399 |
\bl{$der\, c\, ([c_1 c_2 \ldots c_n])$} & \bl{$\dn$} & $?$\\ |
|
400 |
\bl{$der\, c\, (r^+)$} & \bl{$\dn$} & $?$\\ |
|
401 |
\bl{$der\, c\, (r^?)$} & \bl{$\dn$} & $?$\\ |
|
402 |
\bl{$der\, c\, (r^{\{n\}})$} & \bl{$\dn$} & |
|
403 |
\bl{$if\;n=0\;then\;\ZERO\;else\;(der\,c\,r)\cdot r^{\{n-1\}}$}\\ |
|
404 |
\bl{$der\, c\, (r^{\{n..\}})$} & \bl{$\dn$} & |
|
405 |
\bl{$if\;n=0\;then (der\,c\,r)\cdot r^*$}\\ |
|
406 |
& & \bl{$\phantom{if\;n=0\;}else \;(der\,c\,r)\cdot r^{\{n-1..\}}$}\\ |
|
407 |
\bl{$der\, c\, (r^{\{..n\}})$} & \bl{$\dn$} & |
|
408 |
\bl{$if\;n=0\;then\;\ZERO\;else\;(der\,c\,r)\cdot r^{\{..n-1\}}$}\\ |
|
409 |
||
410 |
\bl{$der\, c\, (r^{\{n..m\}})$} & \bl{$\dn$} & |
|
411 |
\bl{$if\;n = 0 \wedge m = 0\;then\;\ZERO\; else$}\\ |
|
412 |
\multicolumn{3}{l}{\bl{$if\;n = 0 \wedge m > 0\;then\;(der\,c\,r)\cdot r^{\{..m-1\}}$}}\\ |
|
413 |
\multicolumn{3}{l}{\bl{$\phantom{if\;n = 0 \wedge m > 0\;}else |
|
414 |
\;(der\,c\,r)\cdot r^{\{n-1..m-1\}}$}}\\ |
|
415 |
\bl{$der\, c\, (\sim{}r)$} & \bl{$\dn$} & $?$\\ |
|
290
3a2fa69ea675
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
289
diff
changeset
|
416 |
\end{tabular} |
3a2fa69ea675
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
289
diff
changeset
|
417 |
\end{center} |
3a2fa69ea675
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
289
diff
changeset
|
418 |
|
3a2fa69ea675
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
289
diff
changeset
|
419 |
\end{frame} |
3a2fa69ea675
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
289
diff
changeset
|
420 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
150
a2d792ed768e
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
149
diff
changeset
|
421 |
|
528 | 422 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
423 |
\begin{frame}[c] |
|
424 |
\frametitle{Coursework: CFUN} |
|
425 |
||
426 |
\begin{center} |
|
427 |
\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}} |
|
428 |
\bl{$nullable(CFUN(\_))$} & \bl{$\dn$} & \bl{$false$}\\ |
|
429 |
\bl{$der\,c\,(CFUN(f))$} & \bl{$\dn$} & |
|
430 |
\bl{$if\;f(c)\;then\;\ONE\;else\;\ZERO$}\bigskip\\ |
|
431 |
\bl{$CHAR(c)$} & \bl{$\dn$} & \bl{$CFUN(\lambda{}d.\;c=d)$}\\ |
|
432 |
\bl{$CSET([c_1,\ldots,c_n])$} & \bl{$\dn$} & \bl{$CFUN(\lambda{}d.\;d\in [c_1,\ldots,c_n])$}\\ |
|
433 |
\bl{$ALL$} & \bl{$\dn$} & \bl{$CFUN(\lambda{}d.\;true)$}\\ |
|
434 |
\end{tabular} |
|
435 |
\end{center} |
|
436 |
||
437 |
\end{frame} |
|
438 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
439 |
||
440 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
441 |
\begin{frame}[t] |
|
442 |
\frametitle{Lexer, Parser} |
|
443 |
\mbox{}\\[-16mm]\mbox{} |
|
444 |
||
445 |
\begin{center} |
|
446 |
\begin{tikzpicture}[scale=1, |
|
447 |
node/.style={ |
|
448 |
rectangle,rounded corners=3mm, |
|
449 |
very thick,draw=black!50, |
|
450 |
minimum height=18mm, minimum width=20mm, |
|
451 |
top color=white,bottom color=black!20}] |
|
452 |
\node (0) at (-2.3,0) {}; |
|
453 |
||
454 |
\node (A) at (0,0) [node] {}; |
|
455 |
\node [below right] at (A.north west) {lexer}; |
|
456 |
||
457 |
\node (B) at (3,0) [node] {}; |
|
458 |
\node [below right=1mm] at (B.north west) |
|
459 |
{\mbox{}\hspace{-1mm}parser}; |
|
460 |
||
461 |
\node (C) at (6,0) [node] {}; |
|
462 |
\node [below right] at (C.north west) |
|
463 |
{\mbox{}\hspace{-1mm}code gen}; |
|
464 |
||
465 |
\node (1) at (8.4,0) {}; |
|
466 |
||
467 |
\draw [->,line width=4mm] (0) -- (A); |
|
468 |
\draw [->,line width=4mm] (A) -- (B); |
|
469 |
\draw [->,line width=4mm] (B) -- (C); |
|
470 |
\draw [->,line width=4mm] (C) -- (1); |
|
471 |
\end{tikzpicture} |
|
472 |
\end{center} |
|
473 |
||
474 |
Today a parser. |
|
475 |
||
476 |
\end{frame} |
|
477 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
478 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
479 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
480 |
\begin{frame}[c] |
550 | 481 |
\frametitle{What Parsing is Not} |
482 |
||
483 |
Usually parsing does not check semantic correctness, e.g. |
|
484 |
||
485 |
\begin{itemize} |
|
486 |
\item whether a function is not used before it |
|
487 |
is defined |
|
488 |
\item whether a function has the correct number of arguments |
|
489 |
or are of correct type |
|
490 |
\item whether a variable can be declared twice in a scope |
|
491 |
\end{itemize} |
|
492 |
||
493 |
\end{frame} |
|
494 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
495 |
||
496 |
||
497 |
||
498 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
499 |
\begin{frame}[c] |
|
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
500 |
\frametitle{Regular Languages} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
501 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
502 |
While regular expressions are very useful for lexing, there is |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
503 |
no regular expression that can recognise the language |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
504 |
\bl{$a^nb^n$}.\bigskip |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
505 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
506 |
\begin{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
507 |
\bl{$(((()()))())$} \;\;vs.\;\; \bl{$(((()()))()))$} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
508 |
\end{center}\bigskip\bigskip |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
509 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
510 |
\small |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
511 |
\noindent So we cannot find out with regular expressions |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
512 |
whether parentheses are matched or unmatched. Also regular |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
513 |
expressions are not recursive, e.g.~\bl{$(1 + 2) + 3$}. |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
514 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
515 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
516 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
517 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
518 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
519 |
\begin{frame}[c] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
520 |
\frametitle{Hierarchy of Languages} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
521 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
522 |
\begin{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
523 |
\begin{tikzpicture} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
524 |
[rect/.style={draw=black!50, |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
525 |
top color=white, |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
526 |
bottom color=black!20, |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
527 |
rectangle, |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
528 |
very thick, |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
529 |
rounded corners}, scale=1.2] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
530 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
531 |
\draw (0,0) node [rect, text depth=39mm, text width=68mm] {all languages}; |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
532 |
\draw (0,-0.4) node [rect, text depth=28.5mm, text width=64mm] {decidable languages}; |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
533 |
\draw (0,-0.85) node [rect, text depth=17mm] {context sensitive languages}; |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
534 |
\draw (0,-1.14) node [rect, text depth=9mm, text width=50mm] {context-free languages}; |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
535 |
\draw (0,-1.4) node [rect] {regular languages}; |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
536 |
\end{tikzpicture} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
537 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
538 |
\end{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
539 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
540 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
541 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
542 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
543 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
544 |
\begin{frame}[c] |
360
c6c574d2ca0c
update
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
358
diff
changeset
|
545 |
\frametitle{CF Grammars} |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
546 |
|
360
c6c574d2ca0c
update
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
358
diff
changeset
|
547 |
A \alert{\bf context-free grammar} \bl{$G$} consists of |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
548 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
549 |
\begin{itemize} |
451 | 550 |
\item a finite set of nonterminal symbols ($\langle$upper case$\rangle$) |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
551 |
\item a finite terminal symbols or tokens (lower case) |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
552 |
\item a start symbol (which must be a nonterminal) |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
553 |
\item a set of rules |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
554 |
\begin{center} |
451 | 555 |
\bl{$\meta{A} ::= \textit{rhs}$} |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
556 |
\end{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
557 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
558 |
where \bl{\textit{rhs}} are sequences involving terminals and nonterminals, |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
559 |
including the empty sequence \bl{$\epsilon$}.\medskip\pause |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
560 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
561 |
We also allow rules |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
562 |
\begin{center} |
451 | 563 |
\bl{$\meta{A} ::= \textit{rhs}_1 | \textit{rhs}_2 | \ldots$} |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
564 |
\end{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
565 |
\end{itemize} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
566 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
567 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
568 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
569 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
570 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
571 |
\begin{frame}[c] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
572 |
\frametitle{Palindromes} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
573 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
574 |
A grammar for palindromes over the alphabet~\bl{$\{a,b\}$}: |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
575 |
|
451 | 576 |
\bl{\begin{plstx}[margin=3cm] |
577 |
: \meta{S} ::= \epsilon\\ |
|
578 |
: \meta{S} ::= a\cdot\meta{S}\cdot a\\ |
|
579 |
: \meta{S} ::= b\cdot\meta{S}\cdot b\\ |
|
580 |
\end{plstx}}\pause |
|
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
581 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
582 |
or |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
583 |
|
451 | 584 |
\bl{\begin{plstx}[margin=2cm] |
585 |
: \meta{S} ::= \epsilon | a\cdot \meta{S}\cdot a | b\cdot \meta{S}\cdot b \\ |
|
586 |
\end{plstx}}\pause\bigskip |
|
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
587 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
588 |
\small |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
589 |
Can you find the grammar rules for matched parentheses? |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
590 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
591 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
592 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
593 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
594 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
595 |
\begin{frame}[c] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
596 |
\frametitle{Arithmetic Expressions} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
597 |
|
451 | 598 |
\bl{\begin{plstx}[margin=3cm,one per line] |
599 |
: \meta{E} ::= num\_token |
|
600 |
| \meta{E} \cdot + \cdot \meta{E} |
|
601 |
| \meta{E} \cdot - \cdot \meta{E} |
|
602 |
| \meta{E} \cdot * \cdot \meta{E} |
|
603 |
| ( \cdot \meta{E} \cdot ) \\ |
|
604 |
\end{plstx}}\pause |
|
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
605 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
606 |
\bl{\texttt{1 + 2 * 3 + 4}} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
607 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
608 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
609 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
610 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
611 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
612 |
\begin{frame}[c] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
613 |
\frametitle{A CFG Derivation} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
614 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
615 |
\begin{enumerate} |
451 | 616 |
\item Begin with a string containing only the start symbol, say \bl{\meta{S}}\bigskip |
617 |
\item Replace any nonterminal \bl{\meta{X}} in the string by the |
|
618 |
right-hand side of some production \bl{$\meta{X} ::= \textit{rhs}$}\bigskip |
|
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
619 |
\item Repeat 2 until there are no nonterminals |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
620 |
\end{enumerate} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
621 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
622 |
\begin{center} |
451 | 623 |
\bl{$\meta{S} \rightarrow \ldots \rightarrow \ldots \rightarrow \ldots \rightarrow \ldots $} |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
624 |
\end{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
625 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
626 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
627 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
628 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
629 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
451 | 630 |
\begin{frame}[t] |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
631 |
\frametitle{Example Derivation} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
632 |
|
451 | 633 |
\bl{\begin{plstx}[margin=2cm] |
634 |
: \meta{S} ::= \epsilon | a\cdot \meta{S}\cdot a | b\cdot \meta{S}\cdot b \\ |
|
635 |
\end{plstx}}\bigskip |
|
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
636 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
637 |
\begin{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
638 |
\begin{tabular}{lcl} |
451 | 639 |
\bl{\meta{S}} & \bl{$\rightarrow$} & \bl{$a\meta{S}a$}\\ |
640 |
& \bl{$\rightarrow$} & \bl{$ab\meta{S}ba$}\\ |
|
641 |
& \bl{$\rightarrow$} & \bl{$aba\meta{S}aba$}\\ |
|
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
642 |
& \bl{$\rightarrow$} & \bl{$abaaba$}\\ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
643 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
644 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
645 |
\end{tabular} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
646 |
\end{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
647 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
648 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
649 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
650 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
651 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
451 | 652 |
\begin{frame}[t] |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
653 |
\frametitle{Example Derivation} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
654 |
|
451 | 655 |
\bl{\begin{plstx}[margin=3cm,one per line] |
656 |
: \meta{E} ::= num\_token |
|
657 |
| \meta{E} \cdot + \cdot \meta{E} |
|
658 |
| \meta{E} \cdot - \cdot \meta{E} |
|
659 |
| \meta{E} \cdot * \cdot \meta{E} |
|
660 |
| ( \cdot \meta{E} \cdot ) \\ |
|
661 |
\end{plstx}} |
|
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
662 |
|
451 | 663 |
\small |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
664 |
\begin{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
665 |
\begin{tabular}{@{}c@{}c@{}} |
451 | 666 |
\begin{tabular}{@{\hspace{-2mm}}l@{\hspace{1mm}}l@{\hspace{1mm}}l@{\hspace{4mm}}} |
667 |
\bl{\meta{E}} & \bl{$\rightarrow$} & \bl{$\meta{E}*\meta{E}$}\\ |
|
668 |
& \bl{$\rightarrow$} & \bl{$\meta{E}+\meta{E}*\meta{E}$}\\ |
|
669 |
& \bl{$\rightarrow$} & \bl{$\meta{E}+\meta{E}*\meta{E}+\meta{E}$}\\ |
|
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
670 |
& \bl{$\rightarrow^+$} & \bl{$1+2*3+4$}\\ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
671 |
\end{tabular} &\pause |
451 | 672 |
\begin{tabular}{@{}l@{\hspace{0mm}}l@{\hspace{1mm}}l} |
673 |
\bl{$\meta{E}$} & \bl{$\rightarrow$} & \bl{$\meta{E}+\meta{E}$}\\ |
|
674 |
& \bl{$\rightarrow$} & \bl{$\meta{E}+\meta{E}+\meta{E}$}\\ |
|
675 |
& \bl{$\rightarrow$} & \bl{$\meta{E}+\meta{E}*\meta{E}+\meta{E}$}\\ |
|
676 |
& \bl{$\rightarrow^+$} & \bl{$1+2*3+4$}\\ |
|
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
677 |
\end{tabular} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
678 |
\end{tabular} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
679 |
\end{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
680 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
681 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
682 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
683 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
684 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
685 |
\begin{frame}[c] |
360
c6c574d2ca0c
update
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
358
diff
changeset
|
686 |
\frametitle{\begin{tabular}{c}Context Sensitive\\[-1mm] |
c6c574d2ca0c
update
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
358
diff
changeset
|
687 |
Grammars\end{tabular}} |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
688 |
|
360
c6c574d2ca0c
update
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
358
diff
changeset
|
689 |
It is much harder to find out whether a string is parsed |
c6c574d2ca0c
update
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
358
diff
changeset
|
690 |
by a context sensitive grammar: |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
691 |
|
451 | 692 |
\bl{\begin{plstx}[margin=2cm] |
693 |
: \meta{S} ::= b\meta{S}\meta{A}\meta{A} | \epsilon\\ |
|
694 |
: \meta{A} ::= a\\ |
|
695 |
: b\meta{A} ::= \meta{A}b\\ |
|
696 |
\end{plstx}}\pause |
|
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
697 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
698 |
\begin{center} |
451 | 699 |
\bl{$\meta{S} \rightarrow\ldots\rightarrow^? ababaa$} |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
700 |
\end{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
701 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
702 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
703 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
704 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
705 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
706 |
\begin{frame}[c] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
707 |
\frametitle{Language of a CFG} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
708 |
|
451 | 709 |
Let \bl{$G$} be a context-free grammar with start symbol \bl{\meta{S}}. |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
710 |
Then the language \bl{$L(G)$} is: |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
711 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
712 |
\begin{center} |
451 | 713 |
\bl{$\{c_1\ldots c_n \;|\; \forall i.\; c_i \in T \wedge \meta{S} \rightarrow^* c_1\ldots c_n \}$} |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
714 |
\end{center}\pause |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
715 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
716 |
\begin{itemize} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
717 |
\item Terminals, because there are no rules for replacing them. |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
718 |
\item Once generated, terminals are ``permanent''. |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
719 |
\item Terminals ought to be tokens of the language\\ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
720 |
(but can also be strings). |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
721 |
\end{itemize} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
722 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
723 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
724 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
725 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
726 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
451 | 727 |
\begin{frame}[t] |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
728 |
\frametitle{Parse Trees} |
451 | 729 |
\mbox{}\\[-16mm] |
730 |
||
529 | 731 |
\bl{\begin{plstx}: \meta{E} ::= \meta{F} | \meta{T} \cdot + \cdot \meta{E} | \meta{T} \cdot - \cdot \meta{E}\\ |
732 |
: \meta{T} ::= \meta{F} | \meta{F} \cdot * \cdot \meta{T}\\ |
|
733 |
: \meta{F} ::= num\_token | ( \cdot \meta{E} \cdot )\\ |
|
451 | 734 |
\end{plstx}} |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
735 |
|
451 | 736 |
\begin{center}\small |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
737 |
\begin{tikzpicture}[level distance=8mm, blue] |
451 | 738 |
\node {$\meta{E}$} |
529 | 739 |
child {node {$\meta{T}$} |
451 | 740 |
child {node {$\meta{T}$} |
741 |
child {node {(\,$\meta{E}$\,)} |
|
742 |
child {node{$\meta{F}$ *{} $\meta{F}$} |
|
743 |
child {node {$\meta{T}$} child {node {2}}} |
|
744 |
child {node {$\meta{T}$} child {node {3}}} |
|
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
745 |
} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
746 |
} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
747 |
} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
748 |
child {node {+}} |
451 | 749 |
child {node {$\meta{T}$} |
750 |
child {node {(\,$\meta{E}$\,)} |
|
751 |
child {node {$\meta{F}$} |
|
752 |
child {node {$\meta{T}$ +{} $\meta{T}$} |
|
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
753 |
child {node {3}} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
754 |
child {node {4}} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
755 |
} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
756 |
}} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
757 |
}}; |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
758 |
\end{tikzpicture} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
759 |
\end{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
760 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
761 |
\begin{textblock}{5}(1, 6.5) |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
762 |
\bl{\texttt{(2*3)+(3+4)}} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
763 |
\end{textblock} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
764 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
765 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
766 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
767 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
768 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
451 | 769 |
\begin{frame}[t] |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
770 |
\frametitle{Arithmetic Expressions} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
771 |
|
451 | 772 |
\bl{\begin{plstx}[margin=3cm,one per line] |
773 |
: \meta{E} ::= num\_token |
|
774 |
| \meta{E} \cdot + \cdot \meta{E} |
|
775 |
| \meta{E} \cdot - \cdot \meta{E} |
|
776 |
| \meta{E} \cdot * \cdot \meta{E} |
|
777 |
| ( \cdot \meta{E} \cdot ) \\ |
|
778 |
\end{plstx}}\pause\bigskip |
|
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
779 |
|
451 | 780 |
A CFG is \alert{\bf left-recursive} if it has a nonterminal \bl{$\meta{E}$} such |
781 |
that \bl{$\meta{E} \rightarrow^+ \meta{E}\cdot \ldots$} |
|
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
782 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
783 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
784 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
785 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
786 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
451 | 787 |
\begin{frame}[t] |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
788 |
\frametitle{Ambiguous Grammars} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
789 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
790 |
A grammar is \alert{\bf ambiguous} if there is a string that |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
791 |
has at least two different parse trees. |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
792 |
|
451 | 793 |
\bl{\begin{plstx}[margin=3cm,one per line]: \meta{E} ::= num\_token |
794 |
| \meta{E} \cdot + \cdot \meta{E} |
|
795 |
| \meta{E} \cdot - \cdot \meta{E} |
|
796 |
| \meta{E} \cdot * \cdot \meta{E} |
|
797 |
| ( \cdot \meta{E} \cdot ) \\ |
|
798 |
\end{plstx}} |
|
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
799 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
800 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
801 |
\bl{\texttt{1 + 2 * 3 + 4}} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
802 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
803 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
804 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
805 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
806 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
807 |
\begin{frame}[c] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
808 |
\frametitle{Dangling Else} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
809 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
810 |
Another ambiguous grammar:\bigskip |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
811 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
812 |
\begin{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
813 |
\bl{\begin{tabular}{lcl} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
814 |
$E$ & $\rightarrow$ & if $E$ then $E$\\ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
815 |
& $|$ & if $E$ then $E$ else $E$ \\ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
816 |
& $|$ & \ldots |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
817 |
\end{tabular}} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
818 |
\end{center}\bigskip |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
819 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
820 |
\bl{\texttt{if a then if x then y else c}} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
821 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
822 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
823 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
824 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
825 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
826 |
\begin{frame}[c] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
827 |
\frametitle{Parser Combinators} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
828 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
829 |
One of the simplest ways to implement a parser, see |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
830 |
{\small\url{https://vimeo.com/142341803}}\bigskip |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
831 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
832 |
Parser combinators: \bigskip |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
833 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
834 |
\begin{minipage}{1.1\textwidth} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
835 |
\begin{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
836 |
\mbox{}\hspace{-12mm}\mbox{}$\underbrace{\text{list of tokens}}_{\text{input}}$ \bl{$\Rightarrow$} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
837 |
$\underbrace{\text{set of (parsed input, unparsed input)}}_{\text{output}}$ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
838 |
\end{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
839 |
\end{minipage}\bigskip |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
840 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
841 |
\begin{itemize} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
842 |
\item atomic parsers |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
843 |
\item sequencing |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
844 |
\item alternative |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
845 |
\item semantic action |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
846 |
\end{itemize} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
847 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
848 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
849 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
850 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
851 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
852 |
\begin{frame}[c] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
853 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
854 |
Atomic parsers, for example, number tokens |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
855 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
856 |
\begin{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
857 |
\bl{$\texttt{Num(123)}::rest \;\Rightarrow\; \{(\texttt{Num(123)}, rest)\}$} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
858 |
\end{center}\bigskip |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
859 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
860 |
\begin{itemize} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
861 |
\item you consume one or more token from the\\ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
862 |
input (stream) |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
863 |
\item also works for characters and strings |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
864 |
\end{itemize} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
865 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
866 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
867 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
868 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
869 |
\begin{frame}[c] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
870 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
871 |
Alternative parser (code \bl{$p\;||\;q$})\bigskip |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
872 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
873 |
\begin{itemize} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
874 |
\item apply \bl{$p$} and also \bl{$q$}; then combine |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
875 |
the outputs |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
876 |
\end{itemize} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
877 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
878 |
\begin{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
879 |
\large \bl{$p(\text{input}) \cup q(\text{input})$} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
880 |
\end{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
881 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
882 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
883 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
884 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
885 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
886 |
\begin{frame}[c] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
887 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
888 |
Sequence parser (code \bl{$p\sim q$})\bigskip |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
889 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
890 |
\begin{itemize} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
891 |
\item apply first \bl{$p$} producing a set of pairs |
528 | 892 |
\item then apply \bl{$q$} to the unparsed part |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
893 |
\item then combine the results:\medskip |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
894 |
\begin{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
895 |
((output$_1$, output$_2$), unparsed part) |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
896 |
\end{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
897 |
\end{itemize} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
898 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
899 |
\begin{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
900 |
\begin{tabular}{l} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
901 |
\large \bl{$\{((o_1, o_2), u_2) \;|\;$}\\[2mm] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
902 |
\large\mbox{}\hspace{15mm} \bl{$(o_1, u_1) \in p(\text{input}) \wedge$}\\[2mm] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
903 |
\large\mbox{}\hspace{15mm} \bl{$(o_2, u_2) \in q(u_1)\}$} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
904 |
\end{tabular} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
905 |
\end{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
906 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
907 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
908 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
909 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
910 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
911 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
912 |
\begin{frame}[c] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
913 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
914 |
Function parser (code \bl{$p \Rightarrow f\;$})\bigskip |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
915 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
916 |
\begin{itemize} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
917 |
\item apply \bl{$p$} producing a set of pairs |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
918 |
\item then apply the function \bl{$f$} to each first component |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
919 |
\end{itemize} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
920 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
921 |
\begin{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
922 |
\begin{tabular}{l} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
923 |
\large \bl{$\{(f(o_1), u_1) \;|\; (o_1, u_1) \in p(\text{input})\}$} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
924 |
\end{tabular} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
925 |
\end{center}\bigskip\bigskip\pause |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
926 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
927 |
\bl{$f$} is the semantic action (``what to do with the parsed input'') |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
928 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
929 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
930 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
931 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
932 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
933 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
934 |
\mode<presentation>{ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
935 |
\begin{frame}[c] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
936 |
\frametitle{\begin{tabular}{c}Semantic Actions\end{tabular}} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
937 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
938 |
Addition |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
939 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
940 |
\begin{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
941 |
\bl{$T \sim + \sim E \Rightarrow \underbrace{f((x,y), z) \Rightarrow x + z}_{\text{semantic action}}$} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
942 |
\end{center}\pause |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
943 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
944 |
Multiplication |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
945 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
946 |
\begin{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
947 |
\bl{$F \sim * \sim T \Rightarrow f((x,y), z) \Rightarrow x * z$} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
948 |
\end{center}\pause |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
949 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
950 |
Parenthesis |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
951 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
952 |
\begin{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
953 |
\bl{$\text{(} \sim E \sim \text{)} \Rightarrow f((x,y), z) \Rightarrow y$} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
954 |
\end{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
955 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
956 |
\end{frame}} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
957 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
958 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
959 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
960 |
\begin{frame}[c] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
961 |
\frametitle{Types of Parsers} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
962 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
963 |
\begin{itemize} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
964 |
\item {\bf Sequencing}: if \bl{$p$} returns results of type \bl{$T$}, and \bl{$q$} results of type \bl{$S$}, |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
965 |
then \bl{$p \sim q$} returns results of type |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
966 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
967 |
\begin{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
968 |
\bl{$T \times S$} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
969 |
\end{center}\pause |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
970 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
971 |
\item {\bf Alternative}: if \bl{$p$} returns results of type \bl{$T$} then \bl{$q$} \alert{must} also have results of type \bl{$T$}, |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
972 |
and \bl{$p \;||\; q$} returns results of type |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
973 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
974 |
\begin{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
975 |
\bl{$T$} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
976 |
\end{center}\pause |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
977 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
978 |
\item {\bf Semantic Action}: if \bl{$p$} returns results of type \bl{$T$} and \bl{$f$} is a function from |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
979 |
\bl{$T$} to \bl{$S$}, then |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
980 |
\bl{$p \Rightarrow f$} returns results of type |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
981 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
982 |
\begin{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
983 |
\bl{$S$} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
984 |
\end{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
985 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
986 |
\end{itemize} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
987 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
988 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
989 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
990 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
991 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
992 |
\begin{frame}[c] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
993 |
\frametitle{Input Types of Parsers} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
994 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
995 |
\begin{itemize} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
996 |
\item input: \alert{token list} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
997 |
\item output: set of (output\_type, \alert{token list}) |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
998 |
\end{itemize}\bigskip\pause |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
999 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1000 |
actually it can be any input type as long as it is a kind of |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1001 |
sequence (for example a string) |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1002 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1003 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1004 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1005 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1006 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1007 |
\begin{frame}[c] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1008 |
\frametitle{Scannerless Parsers} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1009 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1010 |
\begin{itemize} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1011 |
\item input: \alert{string} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1012 |
\item output: set of (output\_type, \alert{string}) |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1013 |
\end{itemize}\bigskip |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1014 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1015 |
but lexers are better when whitespaces or comments need to be |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1016 |
filtered out; then input is a sequence of tokens |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1017 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1018 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1019 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1020 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1021 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1022 |
\begin{frame}[c] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1023 |
\frametitle{Successful Parses} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1024 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1025 |
\begin{itemize} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1026 |
\item input: string |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1027 |
\item output: \alert{set of} (output\_type, string) |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1028 |
\end{itemize}\bigskip |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1029 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1030 |
a parse is successful whenever the input has been fully |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1031 |
``consumed'' (that is the second component is empty) |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1032 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1033 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1034 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1035 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1036 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1037 |
\begin{frame}[c] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1038 |
\frametitle{Abstract Parser Class} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1039 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1040 |
\small |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1041 |
\lstinputlisting[language=Scala,xleftmargin=1mm] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1042 |
{../progs/app7.scala} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1043 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1044 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1045 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1046 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1047 |
\begin{frame}[c] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1048 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1049 |
\small |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1050 |
\fontsize{10}{12}\selectfont |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1051 |
\lstinputlisting[language=Scala,xleftmargin=1mm] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1052 |
{../progs/app8.scala} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1053 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1054 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1055 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1056 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1057 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1058 |
\begin{frame}[c] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1059 |
\frametitle{Two Grammars} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1060 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1061 |
Which languages are recognised by the following two grammars? |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1062 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1063 |
\begin{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1064 |
\bl{\begin{tabular}{lcl} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1065 |
$S$ & $\rightarrow$ & $1 \cdot S \cdot S$\\ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1066 |
& $|$ & $\epsilon$ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1067 |
\end{tabular}} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1068 |
\end{center}\bigskip |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1069 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1070 |
\begin{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1071 |
\bl{\begin{tabular}{lcl} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1072 |
$U$ & $\rightarrow$ & $1 \cdot U$\\ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1073 |
& $|$ & $\epsilon$ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1074 |
\end{tabular}} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1075 |
\end{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1076 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1077 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1078 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1079 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1080 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1081 |
\begin{frame}[t] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1082 |
\frametitle{Ambiguous Grammars} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1083 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1084 |
\begin{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1085 |
\begin{tikzpicture} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1086 |
\begin{axis}[xlabel={\pcode{1}s},ylabel={time in secs}, |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1087 |
enlargelimits=false, |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1088 |
xtick={0,100,...,1000}, |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1089 |
xmax=1050, |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1090 |
ymax=33, |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1091 |
ytick={0,5,...,30}, |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1092 |
scaled ticks=false, |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1093 |
axis lines=left, |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1094 |
width=11cm, |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1095 |
height=7cm, |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1096 |
legend entries={unambiguous,ambiguous}, |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1097 |
legend pos=north east, |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1098 |
legend cell align=left, |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1099 |
x tick label style={font=\small,/pgf/number format/1000 sep={}}] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1100 |
\addplot[blue,mark=*, mark options={fill=white}] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1101 |
table {s-grammar1.data}; |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1102 |
\only<2>{ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1103 |
\addplot[red,mark=triangle*, mark options={fill=white}] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1104 |
table {s-grammar2.data};} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1105 |
\end{axis} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1106 |
\end{tikzpicture} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1107 |
\end{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1108 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1109 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1110 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1111 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1112 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1113 |
\begin{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1114 |
\frametitle{While-Language} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1115 |
\mbox{}\\[-23mm]\mbox{} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1116 |
|
370
a65767fe5d71
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
361
diff
changeset
|
1117 |
\bl{\begin{plstx}[rhs style=,one per line]: \meta{Stmt} ::= skip |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1118 |
| \meta{Id} := \meta{AExp} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1119 |
| if \meta{BExp} then \meta{Block} else \meta{Block} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1120 |
| while \meta{BExp} do \meta{Block}\\ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1121 |
: \meta{Stmts} ::= \meta{Stmt} ; \meta{Stmts} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1122 |
| \meta{Stmt}\\ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1123 |
: \meta{Block} ::= \{ \meta{Stmts} \} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1124 |
| \meta{Stmt}\\ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1125 |
: \meta{AExp} ::= \ldots\\ |
370
a65767fe5d71
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
361
diff
changeset
|
1126 |
: \meta{BExp} ::= \ldots\\\end{plstx}} |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1127 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1128 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1129 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1130 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1131 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1132 |
\begin{frame}[c] |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1133 |
\frametitle{An Interpreter} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1134 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1135 |
\begin{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1136 |
\bl{\begin{tabular}{l} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1137 |
$\{$\\ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1138 |
\;\;$x := 5 \text{;}$\\ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1139 |
\;\;$y := x * 3\text{;}$\\ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1140 |
\;\;$y := x * 4\text{;}$\\ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1141 |
\;\;$x := u * 3$\\ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1142 |
$\}$ |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1143 |
\end{tabular}} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1144 |
\end{center} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1145 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1146 |
\begin{itemize} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1147 |
\item the interpreter has to record the value of \bl{$x$} before assigning a value to \bl{$y$}\pause |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1148 |
\item \bl{\texttt{eval(stmt, env)}} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1149 |
\end{itemize} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1150 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1151 |
\end{frame} |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1152 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1153 |
|
465 | 1154 |
|
1155 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1156 |
\mode<presentation>{ |
|
1157 |
\begin{frame}[c] |
|
1158 |
\frametitle{\begin{tabular}{c}Interpreter\end{tabular}} |
|
1159 |
||
1160 |
\begin{center} |
|
1161 |
\bl{\begin{tabular}{@{}lcl@{}} |
|
1162 |
$\text{eval}(n, E)$ & $\dn$ & $n$\\ |
|
1163 |
$\text{eval}(x, E)$ & $\dn$ & $E(x)$ \;\;\;\textcolor{black}{lookup \bl{$x$} in \bl{$E$}}\\ |
|
1164 |
$\text{eval}(a_1 + a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) + \text{eval}(a_2, E)$\\ |
|
1165 |
$\text{eval}(a_1 - a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) - \text{eval}(a_2, E)$\\ |
|
1166 |
$\text{eval}(a_1 * a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) * \text{eval}(a_2, E)$\bigskip\\ |
|
1167 |
$\text{eval}(a_1 = a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) = \text{eval}(a_2, E)$\\ |
|
1168 |
$\text{eval}(a_1\,!\!= a_2, E)$ & $\dn$ & $\neg(\text{eval}(a_1, E) = \text{eval}(a_2, E))$\\ |
|
1169 |
$\text{eval}(a_1 < a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) < \text{eval}(a_2, E)$\ |
|
1170 |
\end{tabular}} |
|
1171 |
\end{center} |
|
1172 |
||
1173 |
\end{frame}} |
|
1174 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1175 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1176 |
\mode<presentation>{ |
|
1177 |
\begin{frame}[c] |
|
1178 |
\frametitle{\begin{tabular}{c}Interpreter (2)\end{tabular}} |
|
1179 |
||
1180 |
\begin{center} |
|
1181 |
\bl{\begin{tabular}{@{}lcl@{}} |
|
1182 |
$\text{eval}(\text{skip}, E)$ & $\dn$ & $E$\\ |
|
1183 |
$\text{eval}(x:=a, E)$ & $\dn$ & \bl{$E(x \mapsto \text{eval}(a, E))$}\\ |
|
1184 |
\multicolumn{3}{@{}l@{}}{$\text{eval}(\text{if}\;b\;\text{then}\;cs_1\;\text{else}\;cs_2 , E) \dn$}\\ |
|
1185 |
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)\;\text{then}\; |
|
1186 |
\text{eval}(cs_1,E)$}\\ |
|
1187 |
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\phantom{\text{if}\;\text{eval}(b,E)\;}\text{else}\;\text{eval}(cs_2,E)$}\\ |
|
1188 |
\multicolumn{3}{@{}l@{}}{$\text{eval}(\text{while}\;b\;\text{do}\;cs, E) \dn$}\\ |
|
1189 |
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)$}\\ |
|
1190 |
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{then}\; |
|
1191 |
\text{eval}(\text{while}\;b\;\text{do}\;cs, \text{eval}(cs,E))$}\\ |
|
1192 |
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{else}\; E$}\\ |
|
1193 |
$\text{eval}(\text{write}\; x, E)$ & $\dn$ & $\{\;\text{println}(E(x))\; ;\;E\;\}$\\ |
|
1194 |
\end{tabular}} |
|
1195 |
\end{center} |
|
1196 |
||
1197 |
\end{frame}} |
|
1198 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1199 |
||
1200 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1201 |
\begin{frame}[c] |
|
1202 |
\frametitle{\begin{tabular}{c}Test Program\end{tabular}} |
|
1203 |
||
1204 |
\mbox{}\\[-18mm]\mbox{} |
|
1205 |
||
1206 |
{\lstset{language=While}%%\fontsize{10}{12}\selectfont |
|
1207 |
\texttt{\lstinputlisting{../progs/loops.while}}} |
|
1208 |
||
1209 |
\end{frame} |
|
1210 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1211 |
||
1212 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1213 |
\mode<presentation>{ |
|
1214 |
\begin{frame}[t] |
|
1215 |
\frametitle{\begin{tabular}{c}Interpreted Code\end{tabular}} |
|
1216 |
||
1217 |
\begin{center} |
|
1218 |
\begin{tikzpicture} |
|
1219 |
\begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small] |
|
1220 |
\addplot+[smooth] file {interpreted.data}; |
|
1221 |
\end{axis} |
|
1222 |
\end{tikzpicture} |
|
1223 |
\end{center} |
|
1224 |
||
1225 |
\end{frame}} |
|
1226 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1227 |
||
1228 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
1229 |
\mode<presentation>{ |
|
1230 |
\begin{frame}[c] |
|
1231 |
\frametitle{\begin{tabular}{c}Java Virtual Machine\end{tabular}} |
|
1232 |
||
1233 |
\begin{itemize} |
|
1234 |
\item introduced in 1995 |
|
1235 |
\item is a stack-based VM (like Postscript, CLR of .Net) |
|
1236 |
\item contains a JIT compiler |
|
1237 |
\item many languages take advantage of JVM's infrastructure (JRE) |
|
1238 |
\item is garbage collected $\Rightarrow$ no buffer overflows |
|
1239 |
\item some languages compile to the JVM: Scala, Clojure\ldots |
|
1240 |
\end{itemize} |
|
1241 |
||
1242 |
\end{frame}} |
|
1243 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1244 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
290
diff
changeset
|
1245 |
|
44 | 1246 |
\end{document} |
1247 |
||
1248 |
%%% Local Variables: |
|
1249 |
%%% mode: latex |
|
1250 |
%%% TeX-master: t |
|
1251 |
%%% End: |
|
1252 |