author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Sat, 03 Oct 2015 23:30:48 +0100 | |
changeset 345 | 0922b3e01289 |
parent 295 | 19f23c4c2167 |
child 365 | 9b71dead1219 |
permissions | -rw-r--r-- |
49 | 1 |
\documentclass[dvipsnames,14pt,t]{beamer} |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
2 |
\usepackage{../slides} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
3 |
\usepackage{../graphics} |
215
828303e8e4af
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
4 |
\usepackage{../langs} |
828303e8e4af
updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
184
diff
changeset
|
5 |
\usepackage{../data} |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
6 |
\usepackage{../grammar} |
49 | 7 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
8 |
\hfuzz=220pt |
49 | 9 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
10 |
\pgfplotsset{compat=1.11} |
168
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
11 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
12 |
\newcommand{\bl}[1]{\textcolor{blue}{#1}} |
49 | 13 |
|
14 |
% beamer stuff |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
15 |
\renewcommand{\slidecaption}{AFL 06, King's College London} |
49 | 16 |
|
17 |
\begin{document} |
|
18 |
||
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
19 |
|
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
20 |
|
49 | 21 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
22 |
\begin{frame}[t] |
49 | 23 |
\frametitle{% |
24 |
\begin{tabular}{@ {}c@ {}} |
|
25 |
\\[-3mm] |
|
26 |
\LARGE Automata and \\[-2mm] |
|
27 |
\LARGE Formal Languages (6)\\[3mm] |
|
28 |
\end{tabular}} |
|
29 |
||
30 |
\normalsize |
|
31 |
\begin{center} |
|
32 |
\begin{tabular}{ll} |
|
33 |
Email: & christian.urban at kcl.ac.uk\\ |
|
168
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
34 |
Office: & S1.27 (1st floor Strand Building)\\ |
49 | 35 |
Slides: & KEATS (also home work is there)\\ |
36 |
\end{tabular} |
|
37 |
\end{center} |
|
38 |
||
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
39 |
\end{frame} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
40 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
49 | 41 |
|
170
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
42 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
43 |
\begin{frame}[c] |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
44 |
\frametitle{Regular Languages} |
170
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
45 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
46 |
While regular expressions are very useful for lexing, there is |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
47 |
no regular expression that can recognise the language |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
48 |
\bl{$a^nb^n$}.\bigskip |
170
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
49 |
|
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
50 |
\begin{center} |
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
51 |
\bl{$(((()()))())$} \;\;vs.\;\; \bl{$(((()()))()))$} |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
52 |
\end{center}\bigskip\bigskip |
170
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
53 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
54 |
\small |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
55 |
\noindent So we cannot find out with regular expressions |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
56 |
whether parentheses are matched or unmatched. |
170
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
57 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
58 |
\end{frame} |
170
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
59 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
49 | 60 |
|
61 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
62 |
\begin{frame}[c] |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
63 |
\frametitle{Hierarchy of Languages} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
64 |
|
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
65 |
\begin{center} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
66 |
\begin{tikzpicture} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
67 |
[rect/.style={draw=black!50, |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
68 |
top color=white, |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
69 |
bottom color=black!20, |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
70 |
rectangle, |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
71 |
very thick, |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
72 |
rounded corners}] |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
73 |
|
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
74 |
\draw (0,0) node [rect, text depth=39mm, text width=68mm] {all languages}; |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
75 |
\draw (0,-0.4) node [rect, text depth=28.5mm, text width=64mm] {decidable languages}; |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
76 |
\draw (0,-0.85) node [rect, text depth=17mm] {context sensitive languages}; |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
77 |
\draw (0,-1.14) node [rect, text depth=9mm, text width=50mm] {context-free languages}; |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
78 |
\draw (0,-1.4) node [rect] {regular languages}; |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
79 |
\end{tikzpicture} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
80 |
|
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
81 |
\end{center} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
82 |
|
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
83 |
\end{frame} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
84 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
85 |
|
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
86 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
87 |
\begin{frame}[c] |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
88 |
\frametitle{Grammars} |
50 | 89 |
|
53 | 90 |
A (context-free) grammar \bl{$G$} consists of |
49 | 91 |
|
92 |
\begin{itemize} |
|
50 | 93 |
\item a finite set of nonterminal symbols (upper case) |
94 |
\item a finite terminal symbols or tokens (lower case) |
|
95 |
\item a start symbol (which must be a nonterminal) |
|
96 |
\item a set of rules |
|
49 | 97 |
\begin{center} |
50 | 98 |
\bl{$A \rightarrow \text{rhs}$} |
49 | 99 |
\end{center} |
100 |
||
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
101 |
where \bl{rhs} are sequences involving terminals and nonterminals, |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
102 |
including the empty sequence \bl{$\epsilon$}.\medskip\pause |
49 | 103 |
|
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
104 |
We also allow rules |
50 | 105 |
\begin{center} |
106 |
\bl{$A \rightarrow \text{rhs}_1 | \text{rhs}_2 | \ldots$} |
|
107 |
\end{center} |
|
108 |
\end{itemize} |
|
49 | 109 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
110 |
\end{frame} |
49 | 111 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
112 |
||
113 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
114 |
\begin{frame}[c] |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
115 |
\frametitle{Palindromes} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
116 |
|
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
117 |
A grammar for palindromes over the alphabet~\bl{$\{a,b\}$}: |
49 | 118 |
|
119 |
\begin{center} |
|
50 | 120 |
\bl{\begin{tabular}{lcl} |
121 |
$S$ & $\rightarrow$ & $\epsilon$ \\ |
|
53 | 122 |
$S$ & $\rightarrow$ & $a\cdot S\cdot a$ \\ |
123 |
$S$ & $\rightarrow$ & $b\cdot S\cdot b$ \\ |
|
50 | 124 |
\end{tabular}} |
125 |
\end{center}\pause |
|
126 |
||
127 |
or |
|
128 |
||
129 |
\begin{center} |
|
130 |
\bl{\begin{tabular}{lcl} |
|
53 | 131 |
$S$ & $\rightarrow$ & $\epsilon \;|\; a\cdot S\cdot a \;|\;b\cdot S\cdot b$ \\ |
50 | 132 |
\end{tabular}} |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
133 |
\end{center}\pause\bigskip |
49 | 134 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
135 |
\small |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
136 |
Can you find the grammar rules for matched parentheses? |
49 | 137 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
138 |
\end{frame} |
49 | 139 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
140 |
||
141 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
142 |
\begin{frame}[c] |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
143 |
\frametitle{Arithmetic Expressions} |
49 | 144 |
|
145 |
\begin{center} |
|
146 |
\bl{\begin{tabular}{lcl} |
|
50 | 147 |
$E$ & $\rightarrow$ & $num\_token$ \\ |
53 | 148 |
$E$ & $\rightarrow$ & $E \cdot + \cdot E$ \\ |
149 |
$E$ & $\rightarrow$ & $E \cdot - \cdot E$ \\ |
|
150 |
$E$ & $\rightarrow$ & $E \cdot * \cdot E$ \\ |
|
151 |
$E$ & $\rightarrow$ & $( \cdot E \cdot )$ |
|
49 | 152 |
\end{tabular}} |
50 | 153 |
\end{center}\pause |
49 | 154 |
|
50 | 155 |
\bl{\texttt{1 + 2 * 3 + 4}} |
49 | 156 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
157 |
\end{frame} |
49 | 158 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
159 |
||
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
160 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
161 |
\begin{frame}[c] |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
162 |
\frametitle{A CFG Derivation} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
163 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
164 |
\begin{enumerate} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
165 |
\item Begin with a string containing only the start symbol, say \bl{$S$}\bigskip |
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
170
diff
changeset
|
166 |
\item Replace any nonterminal \bl{$X$} in the string by the |
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
170
diff
changeset
|
167 |
right-hand side of some production \bl{$X \rightarrow \text{rhs}$}\bigskip |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
168 |
\item Repeat 2 until there are no nonterminals |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
169 |
\end{enumerate} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
170 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
171 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
172 |
\bl{$S \rightarrow \ldots \rightarrow \ldots \rightarrow \ldots \rightarrow \ldots $} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
173 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
174 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
175 |
\end{frame} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
176 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
177 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
178 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
179 |
\begin{frame}[c] |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
180 |
\frametitle{Example Derivation} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
181 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
182 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
183 |
\bl{\begin{tabular}{lcl} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
184 |
$S$ & $\rightarrow$ & $\epsilon \;|\; a\cdot S\cdot a \;|\;b\cdot S\cdot b$ \\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
185 |
\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
186 |
\end{center}\bigskip |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
187 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
188 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
189 |
\begin{tabular}{lcl} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
190 |
\bl{$S$} & \bl{$\rightarrow$} & \bl{$aSa$}\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
191 |
& \bl{$\rightarrow$} & \bl{$abSba$}\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
192 |
& \bl{$\rightarrow$} & \bl{$abaSaba$}\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
193 |
& \bl{$\rightarrow$} & \bl{$abaaba$}\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
194 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
195 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
196 |
\end{tabular} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
197 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
198 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
199 |
\end{frame} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
200 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
201 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
202 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
203 |
\begin{frame}[c] |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
204 |
\frametitle{Example Derivation} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
205 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
206 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
207 |
\bl{\begin{tabular}{lcl} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
208 |
$E$ & $\rightarrow$ & $num\_token$ \\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
209 |
$E$ & $\rightarrow$ & $E \cdot + \cdot E$ \\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
210 |
$E$ & $\rightarrow$ & $E \cdot - \cdot E$ \\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
211 |
$E$ & $\rightarrow$ & $E \cdot * \cdot E$ \\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
212 |
$E$ & $\rightarrow$ & $( \cdot E \cdot )$ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
213 |
\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
214 |
\end{center}\bigskip |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
215 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
216 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
217 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
218 |
\begin{tabular}{@{}c@{}c@{}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
219 |
\begin{tabular}{l@{\hspace{1mm}}l@{\hspace{1mm}}l} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
220 |
\bl{$E$} & \bl{$\rightarrow$} & \bl{$E*E$}\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
221 |
& \bl{$\rightarrow$} & \bl{$E+E*E$}\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
222 |
& \bl{$\rightarrow$} & \bl{$E+E*E+E$}\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
223 |
& \bl{$\rightarrow^+$} & \bl{$1+2*3+4$}\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
224 |
\end{tabular} &\pause |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
225 |
\begin{tabular}{l@{\hspace{1mm}}l@{\hspace{1mm}}l} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
226 |
\bl{$E$} & \bl{$\rightarrow$} & \bl{$E+E$}\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
227 |
& \bl{$\rightarrow$} & \bl{$E+E+E$}\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
228 |
& \bl{$\rightarrow$} & \bl{$E+E*E+E$}\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
229 |
& \bl{$\rightarrow^+$} & \bl{$1+2*3+4$}\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
230 |
\end{tabular} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
231 |
\end{tabular} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
232 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
233 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
234 |
\end{frame} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
235 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
236 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
237 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
238 |
\begin{frame}[c] |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
239 |
\frametitle{Language of a CFG} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
240 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
241 |
Let \bl{$G$} be a context-free grammar with start symbol \bl{$S$}. |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
242 |
Then the language \bl{$L(G)$} is: |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
243 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
244 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
245 |
\bl{$\{c_1\ldots c_n \;|\; \forall i.\; c_i \in T \wedge S \rightarrow^* c_1\ldots c_n \}$} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
246 |
\end{center}\pause |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
247 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
248 |
\begin{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
249 |
\item Terminals, because there are no rules for replacing them. |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
250 |
\item Once generated, terminals are ``permanent''. |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
251 |
\item Terminals ought to be tokens of the language\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
252 |
(but can also be strings). |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
253 |
\end{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
254 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
255 |
\end{frame} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
256 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
257 |
|
49 | 258 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
259 |
\begin{frame}[c] |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
260 |
\frametitle{Parse Trees} |
49 | 261 |
|
262 |
\begin{center} |
|
263 |
\bl{\begin{tabular}{lcl} |
|
53 | 264 |
$E$ & $\rightarrow$ & $F \;|\; F \cdot * \cdot F$\\ |
265 |
$F$ & $\rightarrow$ & $T \;|\; T \cdot + \cdot T \;|\; T \cdot - \cdot T$\\ |
|
266 |
$T$ & $\rightarrow$ & $num\_token \;|\; ( \cdot E \cdot )$\\ |
|
49 | 267 |
\end{tabular}} |
268 |
\end{center} |
|
269 |
||
270 |
\begin{center} |
|
271 |
\begin{tikzpicture}[level distance=8mm, blue] |
|
50 | 272 |
\node {$E$} |
273 |
child {node {$F$} |
|
274 |
child {node {$T$} |
|
275 |
child {node {(\,$E$\,)} |
|
276 |
child {node{$F$ *{} $F$} |
|
277 |
child {node {$T$} child {node {2}}} |
|
278 |
child {node {$T$} child {node {3}}} |
|
49 | 279 |
} |
280 |
} |
|
281 |
} |
|
50 | 282 |
child {node {+}} |
283 |
child {node {$T$} |
|
284 |
child {node {(\,$E$\,)} |
|
285 |
child {node {$F$} |
|
286 |
child {node {$T$ +{} $T$} |
|
49 | 287 |
child {node {3}} |
288 |
child {node {4}} |
|
289 |
} |
|
290 |
}} |
|
291 |
}}; |
|
292 |
\end{tikzpicture} |
|
293 |
\end{center} |
|
294 |
||
50 | 295 |
\begin{textblock}{5}(1, 6.5) |
49 | 296 |
\bl{\texttt{(2*3)+(3+4)}} |
297 |
\end{textblock} |
|
298 |
||
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
299 |
\end{frame} |
49 | 300 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
301 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
302 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
303 |
\begin{frame}[c] |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
304 |
\frametitle{Arithmetic Expressions} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
305 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
306 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
307 |
\bl{\begin{tabular}{lcl} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
308 |
$E$ & $\rightarrow$ & $num\_token$ \\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
309 |
$E$ & $\rightarrow$ & $E \cdot + \cdot E$ \\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
310 |
$E$ & $\rightarrow$ & $E \cdot - \cdot E$ \\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
311 |
$E$ & $\rightarrow$ & $E \cdot * \cdot E$ \\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
312 |
$E$ & $\rightarrow$ & $( \cdot E \cdot )$ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
313 |
\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
314 |
\end{center}\pause\bigskip |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
315 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
316 |
A CFG is \alert{left-recursive} if it has a nonterminal \bl{$E$} such |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
317 |
that \bl{$E \rightarrow^+ E\cdot \ldots$} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
318 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
319 |
\end{frame} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
320 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
321 |
|
50 | 322 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
323 |
\begin{frame}[c] |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
324 |
\frametitle{Ambiguous Grammars} |
50 | 325 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
326 |
A grammar is \alert{ambiguous} if there is a string that has |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
327 |
at least two different parse trees. |
50 | 328 |
|
329 |
||
330 |
\begin{center} |
|
331 |
\bl{\begin{tabular}{lcl} |
|
332 |
$E$ & $\rightarrow$ & $num\_token$ \\ |
|
53 | 333 |
$E$ & $\rightarrow$ & $E \cdot + \cdot E$ \\ |
334 |
$E$ & $\rightarrow$ & $E \cdot - \cdot E$ \\ |
|
335 |
$E$ & $\rightarrow$ & $E \cdot * \cdot E$ \\ |
|
336 |
$E$ & $\rightarrow$ & $( \cdot E \cdot )$ |
|
50 | 337 |
\end{tabular}} |
338 |
\end{center} |
|
339 |
||
340 |
\bl{\texttt{1 + 2 * 3 + 4}} |
|
341 |
||
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
342 |
\end{frame} |
50 | 343 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
344 |
||
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
345 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
346 |
\begin{frame}[c] |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
347 |
\frametitle{Dangling Else} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
348 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
349 |
Another ambiguous grammar:\bigskip |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
350 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
351 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
352 |
\bl{\begin{tabular}{lcl} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
353 |
$E$ & $\rightarrow$ & if $E$ then $E$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
354 |
& $|$ & if $E$ then $E$ else $E$ \\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
355 |
& $|$ & \ldots |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
356 |
\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
357 |
\end{center}\bigskip |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
358 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
359 |
\bl{\texttt{if a then if x then y else c}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
360 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
361 |
\end{frame} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
362 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
363 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
364 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
365 |
\begin{frame}[c] |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
366 |
\frametitle{Parser Combinators} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
367 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
368 |
Parser combinators: \bigskip |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
369 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
370 |
\begin{minipage}{1.1\textwidth} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
371 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
372 |
\mbox{}\hspace{-12mm}\mbox{}$\underbrace{\text{list of tokens}}_{\text{input}}$ \bl{$\Rightarrow$} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
373 |
$\underbrace{\text{set of (parsed input, unparsed input)}}_{\text{output}}$ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
374 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
375 |
\end{minipage}\bigskip |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
376 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
377 |
\begin{itemize} |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
378 |
\item atomic parsers |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
379 |
\item sequencing |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
380 |
\item alternative |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
381 |
\item semantic action |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
382 |
\end{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
383 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
384 |
\end{frame} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
385 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
386 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
387 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
388 |
\begin{frame}[c] |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
389 |
|
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
390 |
Atomic parsers, for example, number tokens |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
391 |
|
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
392 |
\begin{center} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
393 |
\bl{$\texttt{Num(123)}::rest \;\Rightarrow\; \{(\texttt{Num(123)}, rest)\}$} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
394 |
\end{center}\bigskip |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
395 |
|
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
396 |
\begin{itemize} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
397 |
\item you consume one or more token from the\\ |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
398 |
input (stream) |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
399 |
\item also works for characters and strings |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
400 |
\end{itemize} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
401 |
\end{frame} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
402 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
403 |
|
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
404 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
405 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
406 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
407 |
Alternative parser (code \bl{$p\;||\;q$})\bigskip |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
408 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
409 |
\begin{itemize} |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
410 |
\item apply \bl{$p$} and also \bl{$q$}; then combine |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
411 |
the outputs |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
412 |
\end{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
413 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
414 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
415 |
\large \bl{$p(\text{input}) \cup q(\text{input})$} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
416 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
417 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
418 |
\end{frame} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
419 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
420 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
421 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
422 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
423 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
424 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
425 |
Sequence parser (code \bl{$p\sim q$})\bigskip |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
426 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
427 |
\begin{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
428 |
\item apply first \bl{$p$} producing a set of pairs |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
429 |
\item then apply \bl{$q$} to the unparsed parts |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
430 |
\item then combine the results:\medskip |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
431 |
\begin{center} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
432 |
((output$_1$, output$_2$), unparsed part) |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
433 |
\end{center} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
434 |
\end{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
435 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
436 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
437 |
\begin{tabular}{l} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
438 |
\large \bl{$\{((o_1, o_2), u_2) \;|\;$}\\[2mm] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
439 |
\large\mbox{}\hspace{15mm} \bl{$(o_1, u_1) \in p(\text{input}) \wedge$}\\[2mm] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
440 |
\large\mbox{}\hspace{15mm} \bl{$(o_2, u_2) \in q(u_1)\}$} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
441 |
\end{tabular} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
442 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
443 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
444 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
445 |
\end{frame}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
446 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
447 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
448 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
449 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
450 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
451 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
452 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
453 |
Function parser (code \bl{$p \Rightarrow f$})\bigskip |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
454 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
455 |
\begin{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
456 |
\item apply \bl{$p$} producing a set of pairs |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
457 |
\item then apply the function \bl{$f$} to each first component |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
458 |
\end{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
459 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
460 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
461 |
\begin{tabular}{l} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
462 |
\large \bl{$\{(f(o_1), u_1) \;|\; (o_1, u_1) \in p(\text{input})\}$} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
463 |
\end{tabular} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
464 |
\end{center}\bigskip\bigskip\pause |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
465 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
466 |
\bl{$f$} is the semantic action (``what to do with the parsed input'') |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
467 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
468 |
\end{frame}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
469 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
470 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
471 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
472 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
473 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
474 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
475 |
\frametitle{\begin{tabular}{c}Semantic Actions\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
476 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
477 |
Addition |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
478 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
479 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
480 |
\bl{$T \sim + \sim E \Rightarrow \underbrace{f((x,y), z) \Rightarrow x + z}_{\text{semantic action}}$} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
481 |
\end{center}\pause |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
482 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
483 |
Multiplication |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
484 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
485 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
486 |
\bl{$F \sim * \sim T \Rightarrow f((x,y), z) \Rightarrow x * z$} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
487 |
\end{center}\pause |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
488 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
489 |
Parenthesis |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
490 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
491 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
492 |
\bl{$\text{(} \sim E \sim \text{)} \Rightarrow f((x,y), z) \Rightarrow y$} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
493 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
494 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
495 |
\end{frame}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
496 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
497 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
498 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
499 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
500 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
501 |
\frametitle{\begin{tabular}{c}Types of Parsers\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
502 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
503 |
\begin{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
504 |
\item {\bf Sequencing}: if \bl{$p$} returns results of type \bl{$T$}, and \bl{$q$} results of type \bl{$S$}, |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
505 |
then \bl{$p \sim q$} returns results of type |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
506 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
507 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
508 |
\bl{$T \times S$} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
509 |
\end{center}\pause |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
510 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
511 |
\item {\bf Alternative}: if \bl{$p$} returns results of type \bl{$T$} then \bl{$q$} \alert{must} also have results of type \bl{$T$}, |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
512 |
and \bl{$p \;||\; q$} returns results of type |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
513 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
514 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
515 |
\bl{$T$} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
516 |
\end{center}\pause |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
517 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
518 |
\item {\bf Semantic Action}: if \bl{$p$} returns results of type \bl{$T$} and \bl{$f$} is a function from |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
519 |
\bl{$T$} to \bl{$S$}, then |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
520 |
\bl{$p \Rightarrow f$} returns results of type |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
521 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
522 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
523 |
\bl{$S$} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
524 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
525 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
526 |
\end{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
527 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
528 |
\end{frame}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
529 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
530 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
531 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
532 |
\begin{frame}[c] |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
533 |
\frametitle{Input Types of Parsers} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
534 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
535 |
\begin{itemize} |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
536 |
\item input: \alert{token list} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
537 |
\item output: set of (output\_type, \alert{token list}) |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
538 |
\end{itemize}\bigskip\pause |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
539 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
540 |
actually it can be any input type as long as it is a kind of |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
541 |
sequence (for example a string) |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
542 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
543 |
\end{frame} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
544 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
545 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
546 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
547 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
548 |
\begin{frame}[c] |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
549 |
\frametitle{Scannerless Parsers} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
550 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
551 |
\begin{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
552 |
\item input: \alert{string} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
553 |
\item output: set of (output\_type, \alert{string}) |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
554 |
\end{itemize}\bigskip |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
555 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
556 |
but lexers are better when whitespaces or comments need to be |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
557 |
filtered out; then input is a sequence of tokens |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
558 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
559 |
\end{frame} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
560 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
561 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
562 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
563 |
\begin{frame}[c] |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
564 |
\frametitle{Successful Parses} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
565 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
566 |
\begin{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
567 |
\item input: string |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
568 |
\item output: \alert{set of} (output\_type, string) |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
569 |
\end{itemize}\bigskip |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
570 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
571 |
a parse is successful whenever the input has been fully |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
572 |
``consumed'' (that is the second component is empty) |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
573 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
574 |
\end{frame} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
575 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
576 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
577 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
578 |
\begin{frame}[c] |
170
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
579 |
\frametitle{Abstract Parser Class} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
580 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
581 |
\small |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
582 |
\lstinputlisting[language=Scala,xleftmargin=1mm]{../progs/app7.scala} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
583 |
\end{frame} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
584 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
585 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
586 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
587 |
\begin{frame}[c] |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
588 |
|
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
589 |
\small |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
590 |
\fontsize{10}{12}\selectfont |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
591 |
\lstinputlisting[language=Scala,xleftmargin=1mm]{../progs/app8.scala} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
592 |
\end{frame} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
593 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
594 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
595 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
596 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
597 |
\begin{frame}[c] |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
598 |
\frametitle{Two Grammars} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
599 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
600 |
Which languages are recognised by the following two grammars? |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
601 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
602 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
603 |
\bl{\begin{tabular}{lcl} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
604 |
$S$ & $\rightarrow$ & $1 \cdot S \cdot S$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
605 |
& $|$ & $\epsilon$ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
606 |
\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
607 |
\end{center}\bigskip |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
608 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
609 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
610 |
\bl{\begin{tabular}{lcl} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
611 |
$U$ & $\rightarrow$ & $1 \cdot U$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
612 |
& $|$ & $\epsilon$ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
613 |
\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
614 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
615 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
616 |
\end{frame} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
617 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
618 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
619 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
620 |
\begin{frame}[t] |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
621 |
\frametitle{Ambiguous Grammars} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
622 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
623 |
\begin{center} |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
624 |
\begin{tikzpicture} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
625 |
\begin{axis}[xlabel={\pcode{1}s},ylabel={time in secs}, |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
626 |
enlargelimits=false, |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
627 |
xtick={0,100,...,1000}, |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
628 |
xmax=1050, |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
629 |
ymax=33, |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
630 |
ytick={0,5,...,30}, |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
631 |
scaled ticks=false, |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
632 |
axis lines=left, |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
633 |
width=11cm, |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
634 |
height=7cm, |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
635 |
legend entries={unambiguous,ambiguous}, |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
636 |
legend pos=north east, |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
637 |
legend cell align=left, |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
638 |
x tick label style={font=\small,/pgf/number format/1000 sep={}}] |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
639 |
\addplot[blue,mark=*, mark options={fill=white}] |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
640 |
table {s-grammar1.data}; |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
641 |
\only<2>{ |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
642 |
\addplot[red,mark=triangle*, mark options={fill=white}] |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
643 |
table {s-grammar2.data};} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
644 |
\end{axis} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
645 |
\end{tikzpicture} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
646 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
647 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
648 |
\end{frame} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
649 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
650 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
651 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
652 |
\begin{frame} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
653 |
\frametitle{While-Language} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
654 |
\mbox{}\\[-23mm]\mbox{} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
655 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
656 |
\bl{\begin{plstx}[rhs style=,one per line] : \meta{Stmt} ::= skip |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
657 |
| \meta{Id} := \meta{AExp} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
658 |
| if \meta{BExp} then \meta{Block} else \meta{Block} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
659 |
| while \meta{BExp} do \meta{Block}\\ |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
660 |
: \meta{Stmts} ::= \meta{Stmt} ; \meta{Stmts} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
661 |
| \meta{Stmt}\\ |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
662 |
: \meta{Block} ::= \{ \meta{Stmts} \} |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
663 |
| \meta{Stmt}\\ |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
664 |
: \meta{AExp} ::= \ldots\\ |
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
665 |
: \meta{BExp} ::= \ldots\\ \end{plstx}} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
666 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
667 |
\end{frame} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
668 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
669 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
670 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
671 |
\begin{frame}[c] |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
672 |
\frametitle{An Interpreter} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
673 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
674 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
675 |
\bl{\begin{tabular}{l} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
676 |
$\{$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
677 |
\;\;$x := 5 \text{;}$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
678 |
\;\;$y := x * 3\text{;}$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
679 |
\;\;$y := x * 4\text{;}$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
680 |
\;\;$x := u * 3$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
681 |
$\}$ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
682 |
\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
683 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
684 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
685 |
\begin{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
686 |
\item the interpreter has to record the value of \bl{$x$} before assigning a value to \bl{$y$}\pause |
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
687 |
\item \bl{\texttt{eval(stmt, env)}} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
688 |
\end{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
689 |
|
295
19f23c4c2167
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
215
diff
changeset
|
690 |
\end{frame} |
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
691 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
692 |
|
50 | 693 |
|
49 | 694 |
\end{document} |
695 |
||
696 |
%%% Local Variables: |
|
697 |
%%% mode: latex |
|
698 |
%%% TeX-master: t |
|
699 |
%%% End: |
|
700 |