author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Fri, 22 Nov 2013 16:59:17 +0000 | |
changeset 199 | 89cafeb66f40 |
parent 184 | 2e9134d25a2b |
child 215 | 828303e8e4af |
permissions | -rw-r--r-- |
49 | 1 |
\documentclass[dvipsnames,14pt,t]{beamer} |
168
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
2 |
\usepackage{beamerthemeplaincu} |
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
3 |
%\usepackage[T1]{fontenc} |
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
4 |
%\usepackage[latin1]{inputenc} |
49 | 5 |
\usepackage{mathpartir} |
6 |
\usepackage[absolute,overlay]{textpos} |
|
7 |
\usepackage{ifthen} |
|
8 |
\usepackage{tikz} |
|
9 |
\usepackage{pgf} |
|
10 |
\usepackage{calc} |
|
11 |
\usepackage{ulem} |
|
12 |
\usepackage{courier} |
|
13 |
\usepackage{listings} |
|
14 |
\renewcommand{\uline}[1]{#1} |
|
15 |
\usetikzlibrary{arrows} |
|
16 |
\usetikzlibrary{automata} |
|
17 |
\usetikzlibrary{shapes} |
|
18 |
\usetikzlibrary{shadows} |
|
19 |
\usetikzlibrary{positioning} |
|
20 |
\usetikzlibrary{calc} |
|
21 |
\usetikzlibrary{plotmarks} |
|
22 |
\usepackage{graphicx} |
|
168
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
23 |
\setmonofont{Consolas} |
49 | 24 |
|
25 |
\definecolor{javared}{rgb}{0.6,0,0} % for strings |
|
26 |
\definecolor{javagreen}{rgb}{0.25,0.5,0.35} % comments |
|
27 |
\definecolor{javapurple}{rgb}{0.5,0,0.35} % keywords |
|
28 |
\definecolor{javadocblue}{rgb}{0.25,0.35,0.75} % javadoc |
|
29 |
||
168
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
30 |
\makeatletter |
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
31 |
\lst@CCPutMacro\lst@ProcessOther {"2D}{\lst@ttfamily{-{}}{-{}}} |
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
32 |
\@empty\z@\@empty |
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
33 |
\makeatother |
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
34 |
|
49 | 35 |
|
36 |
\lstdefinelanguage{scala}{ |
|
37 |
morekeywords={abstract,case,catch,class,def,% |
|
38 |
do,else,extends,false,final,finally,% |
|
39 |
for,if,implicit,import,match,mixin,% |
|
40 |
new,null,object,override,package,% |
|
41 |
private,protected,requires,return,sealed,% |
|
42 |
super,this,throw,trait,true,try,% |
|
43 |
type,val,var,while,with,yield}, |
|
44 |
otherkeywords={=>,<-,<\%,<:,>:,\#,@}, |
|
45 |
sensitive=true, |
|
46 |
morecomment=[l]{//}, |
|
47 |
morecomment=[n]{/*}{*/}, |
|
48 |
morestring=[b]", |
|
49 |
morestring=[b]', |
|
50 |
morestring=[b]""" |
|
51 |
} |
|
52 |
||
168
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
53 |
\lstdefinelanguage{while}{ |
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
54 |
morekeywords={while, if, then. else, read, write}, |
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
55 |
otherkeywords={=>,<-,<\%,<:,>:,\#,@}, |
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
56 |
sensitive=true, |
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
57 |
morecomment=[l]{//}, |
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
58 |
morecomment=[n]{/*}{*/}, |
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
59 |
morestring=[b]", |
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
60 |
morestring=[b]', |
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
61 |
morestring=[b]""" |
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
62 |
} |
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
63 |
|
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
64 |
|
49 | 65 |
\lstset{language=Scala, |
66 |
basicstyle=\ttfamily, |
|
67 |
keywordstyle=\color{javapurple}\bfseries, |
|
68 |
stringstyle=\color{javagreen}, |
|
69 |
commentstyle=\color{javagreen}, |
|
70 |
morecomment=[s][\color{javadocblue}]{/**}{*/}, |
|
71 |
numbers=left, |
|
72 |
numberstyle=\tiny\color{black}, |
|
73 |
stepnumber=1, |
|
74 |
numbersep=10pt, |
|
75 |
tabsize=2, |
|
76 |
showspaces=false, |
|
77 |
showstringspaces=false} |
|
168
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
78 |
|
49 | 79 |
|
80 |
% beamer stuff |
|
168
e60c4a9ba340
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
93
diff
changeset
|
81 |
\renewcommand{\slidecaption}{AFL 06, King's College London, 30.~October 2013} |
49 | 82 |
\newcommand{\bl}[1]{\textcolor{blue}{#1}} |
83 |
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions |
|
84 |
||
85 |
||
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
86 |
\begin{filecontents}{s-grammar1.data} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
87 |
1 0.01152 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
88 |
51 0.07973 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
89 |
101 0.09726 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
90 |
151 0.09320 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
91 |
201 0.10010 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
92 |
251 0.16997 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
93 |
301 0.26662 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
94 |
351 0.46118 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
95 |
401 0.62516 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
96 |
451 0.87247 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
97 |
501 1.16334 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
98 |
551 1.71152 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
99 |
601 2.10958 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
100 |
651 2.44360 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
101 |
701 2.98488 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
102 |
751 3.50326 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
103 |
801 4.11036 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
104 |
851 4.93394 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
105 |
901 5.77465 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
106 |
951 7.39123 |
49 | 107 |
\end{filecontents} |
108 |
||
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
109 |
\begin{filecontents}{s-grammar2.data} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
110 |
1 0.01280 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
111 |
2 0.00064 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
112 |
3 0.00173 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
113 |
4 0.00355 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
114 |
5 0.00965 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
115 |
6 0.02674 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
116 |
7 0.06953 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
117 |
8 0.11166 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
118 |
9 0.18707 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
119 |
10 0.09189 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
120 |
11 0.12724 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
121 |
12 0.24337 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
122 |
13 0.59304 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
123 |
14 1.53594 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
124 |
15 4.01195 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
125 |
16 10.73582 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
126 |
17 29.51587 |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
127 |
#18 73.14163 |
49 | 128 |
\end{filecontents} |
129 |
||
130 |
||
131 |
\begin{document} |
|
132 |
||
133 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
134 |
\mode<presentation>{ |
|
135 |
\begin{frame}<1>[t] |
|
136 |
\frametitle{% |
|
137 |
\begin{tabular}{@ {}c@ {}} |
|
138 |
\\[-3mm] |
|
139 |
\LARGE Automata and \\[-2mm] |
|
140 |
\LARGE Formal Languages (6)\\[3mm] |
|
141 |
\end{tabular}} |
|
142 |
||
143 |
\normalsize |
|
144 |
\begin{center} |
|
145 |
\begin{tabular}{ll} |
|
146 |
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
|
147 |
Office: & S1.27 (1st floor Strand Building)\\ |
49 | 148 |
Slides: & KEATS (also home work is there)\\ |
149 |
\end{tabular} |
|
150 |
\end{center} |
|
151 |
||
152 |
||
153 |
\end{frame}} |
|
154 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
170
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
155 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
156 |
\mode<presentation>{ |
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
157 |
\begin{frame}[c] |
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
158 |
\frametitle{\begin{tabular}{c}Regular Languages\end{tabular}} |
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
159 |
|
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
160 |
While regular expressions are very useful for lexing, |
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
161 |
there is no regular expression that can recognise the language \bl{$a^nb^n$}.\bigskip |
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
162 |
|
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
163 |
\begin{center} |
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
164 |
\bl{$(((()()))())$} \;\;vs.\;\; \bl{$(((()()))()))$} |
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
165 |
\end{center} |
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
166 |
|
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
167 |
|
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
168 |
\end{frame}} |
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
169 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
49 | 170 |
|
171 |
||
50 | 172 |
\newcommand{\qq}{\mbox{\texttt{"}}} |
49 | 173 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
174 |
\mode<presentation>{ |
|
175 |
\begin{frame}[c] |
|
50 | 176 |
\frametitle{\begin{tabular}{c}Grammars\end{tabular}} |
177 |
||
53 | 178 |
A (context-free) grammar \bl{$G$} consists of |
49 | 179 |
|
180 |
\begin{itemize} |
|
50 | 181 |
\item a finite set of nonterminal symbols (upper case) |
182 |
\item a finite terminal symbols or tokens (lower case) |
|
183 |
\item a start symbol (which must be a nonterminal) |
|
184 |
\item a set of rules |
|
49 | 185 |
\begin{center} |
50 | 186 |
\bl{$A \rightarrow \text{rhs}$} |
49 | 187 |
\end{center} |
188 |
||
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
189 |
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
|
190 |
including the empty sequence \bl{$\epsilon$}.\medskip\pause |
49 | 191 |
|
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
192 |
We also allow rules |
50 | 193 |
\begin{center} |
194 |
\bl{$A \rightarrow \text{rhs}_1 | \text{rhs}_2 | \ldots$} |
|
195 |
\end{center} |
|
196 |
\end{itemize} |
|
49 | 197 |
|
198 |
||
199 |
\end{frame}} |
|
200 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
201 |
||
202 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
203 |
\mode<presentation>{ |
|
204 |
\begin{frame}[c] |
|
50 | 205 |
\frametitle{\begin{tabular}{c}Palindromes\end{tabular}} |
49 | 206 |
|
207 |
\begin{center} |
|
50 | 208 |
\bl{\begin{tabular}{lcl} |
209 |
$S$ & $\rightarrow$ & $\epsilon$ \\ |
|
53 | 210 |
$S$ & $\rightarrow$ & $a\cdot S\cdot a$ \\ |
211 |
$S$ & $\rightarrow$ & $b\cdot S\cdot b$ \\ |
|
50 | 212 |
\end{tabular}} |
213 |
\end{center}\pause |
|
214 |
||
215 |
or |
|
216 |
||
217 |
\begin{center} |
|
218 |
\bl{\begin{tabular}{lcl} |
|
53 | 219 |
$S$ & $\rightarrow$ & $\epsilon \;|\; a\cdot S\cdot a \;|\;b\cdot S\cdot b$ \\ |
50 | 220 |
\end{tabular}} |
49 | 221 |
\end{center} |
222 |
||
223 |
||
224 |
\end{frame}} |
|
225 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
226 |
||
227 |
||
228 |
||
229 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
230 |
\mode<presentation>{ |
|
231 |
\begin{frame}[c] |
|
50 | 232 |
\frametitle{\begin{tabular}{c}Arithmetic Expressions\end{tabular}} |
49 | 233 |
|
234 |
\begin{center} |
|
235 |
\bl{\begin{tabular}{lcl} |
|
50 | 236 |
$E$ & $\rightarrow$ & $num\_token$ \\ |
53 | 237 |
$E$ & $\rightarrow$ & $E \cdot + \cdot E$ \\ |
238 |
$E$ & $\rightarrow$ & $E \cdot - \cdot E$ \\ |
|
239 |
$E$ & $\rightarrow$ & $E \cdot * \cdot E$ \\ |
|
240 |
$E$ & $\rightarrow$ & $( \cdot E \cdot )$ |
|
49 | 241 |
\end{tabular}} |
50 | 242 |
\end{center}\pause |
49 | 243 |
|
50 | 244 |
\bl{\texttt{1 + 2 * 3 + 4}} |
49 | 245 |
|
246 |
\end{frame}} |
|
247 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
248 |
||
249 |
||
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
250 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
251 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
252 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
253 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
254 |
\frametitle{\begin{tabular}{c}A CFG Derivation\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
255 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
256 |
\begin{enumerate} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
257 |
\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
|
258 |
\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
|
259 |
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
|
260 |
\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
|
261 |
\end{enumerate} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
262 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
263 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
264 |
\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
|
265 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
266 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
267 |
\end{frame}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
268 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
269 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
270 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
271 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
272 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
273 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
274 |
\frametitle{\begin{tabular}{c}Example Derivation\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
275 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
276 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
277 |
\bl{\begin{tabular}{lcl} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
278 |
$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
|
279 |
\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
280 |
\end{center}\bigskip |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
281 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
282 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
283 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
284 |
\begin{tabular}{lcl} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
285 |
\bl{$S$} & \bl{$\rightarrow$} & \bl{$aSa$}\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
286 |
& \bl{$\rightarrow$} & \bl{$abSba$}\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
287 |
& \bl{$\rightarrow$} & \bl{$abaSaba$}\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
288 |
& \bl{$\rightarrow$} & \bl{$abaaba$}\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
289 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
290 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
291 |
\end{tabular} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
292 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
293 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
294 |
\end{frame}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
295 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
296 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
297 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
298 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
299 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
300 |
\frametitle{\begin{tabular}{c}Example Derivation\end{tabular}} |
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 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
303 |
\bl{\begin{tabular}{lcl} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
304 |
$E$ & $\rightarrow$ & $num\_token$ \\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
305 |
$E$ & $\rightarrow$ & $E \cdot + \cdot E$ \\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
306 |
$E$ & $\rightarrow$ & $E \cdot - \cdot E$ \\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
307 |
$E$ & $\rightarrow$ & $E \cdot * \cdot E$ \\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
308 |
$E$ & $\rightarrow$ & $( \cdot E \cdot )$ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
309 |
\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
310 |
\end{center}\bigskip |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
311 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
312 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
313 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
314 |
\begin{tabular}{@{}c@{}c@{}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
315 |
\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
|
316 |
\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
|
317 |
& \bl{$\rightarrow$} & \bl{$E+E*E$}\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
318 |
& \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
|
319 |
& \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
|
320 |
\end{tabular} &\pause |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
321 |
\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
|
322 |
\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
|
323 |
& \bl{$\rightarrow$} & \bl{$E+E+E$}\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
324 |
& \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
|
325 |
& \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
|
326 |
\end{tabular} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
327 |
\end{tabular} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
328 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
329 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
330 |
\end{frame}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
331 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
332 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
333 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
334 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
335 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
336 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
337 |
\frametitle{\begin{tabular}{c}Language of a CFG\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
338 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
339 |
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
|
340 |
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
|
341 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
342 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
343 |
\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
|
344 |
\end{center}\pause |
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{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
347 |
\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
|
348 |
\item Once generated, terminals are ``permanent''. |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
349 |
\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
|
350 |
(but can also be strings). |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
351 |
\end{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
352 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
353 |
\end{frame}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
354 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
355 |
|
49 | 356 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
357 |
\mode<presentation>{ |
|
358 |
\begin{frame}[c] |
|
50 | 359 |
\frametitle{\begin{tabular}{c}Parse Trees\end{tabular}} |
49 | 360 |
|
361 |
\begin{center} |
|
362 |
\bl{\begin{tabular}{lcl} |
|
53 | 363 |
$E$ & $\rightarrow$ & $F \;|\; F \cdot * \cdot F$\\ |
364 |
$F$ & $\rightarrow$ & $T \;|\; T \cdot + \cdot T \;|\; T \cdot - \cdot T$\\ |
|
365 |
$T$ & $\rightarrow$ & $num\_token \;|\; ( \cdot E \cdot )$\\ |
|
49 | 366 |
\end{tabular}} |
367 |
\end{center} |
|
368 |
||
369 |
\begin{center} |
|
370 |
\begin{tikzpicture}[level distance=8mm, blue] |
|
50 | 371 |
\node {$E$} |
372 |
child {node {$F$} |
|
373 |
child {node {$T$} |
|
374 |
child {node {(\,$E$\,)} |
|
375 |
child {node{$F$ *{} $F$} |
|
376 |
child {node {$T$} child {node {2}}} |
|
377 |
child {node {$T$} child {node {3}}} |
|
49 | 378 |
} |
379 |
} |
|
380 |
} |
|
50 | 381 |
child {node {+}} |
382 |
child {node {$T$} |
|
383 |
child {node {(\,$E$\,)} |
|
384 |
child {node {$F$} |
|
385 |
child {node {$T$ +{} $T$} |
|
49 | 386 |
child {node {3}} |
387 |
child {node {4}} |
|
388 |
} |
|
389 |
}} |
|
390 |
}}; |
|
391 |
\end{tikzpicture} |
|
392 |
\end{center} |
|
393 |
||
50 | 394 |
\begin{textblock}{5}(1, 6.5) |
49 | 395 |
\bl{\texttt{(2*3)+(3+4)}} |
396 |
\end{textblock} |
|
397 |
||
398 |
\end{frame}} |
|
399 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
400 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
401 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
402 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
403 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
404 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
405 |
\frametitle{\begin{tabular}{c}Arithmetic Expressions\end{tabular}} |
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 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
408 |
\bl{\begin{tabular}{lcl} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
409 |
$E$ & $\rightarrow$ & $num\_token$ \\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
410 |
$E$ & $\rightarrow$ & $E \cdot + \cdot E$ \\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
411 |
$E$ & $\rightarrow$ & $E \cdot - \cdot E$ \\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
412 |
$E$ & $\rightarrow$ & $E \cdot * \cdot E$ \\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
413 |
$E$ & $\rightarrow$ & $( \cdot E \cdot )$ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
414 |
\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
415 |
\end{center}\pause\bigskip |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
416 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
417 |
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
|
418 |
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
|
419 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
420 |
\end{frame}} |
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 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
423 |
|
50 | 424 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
425 |
\mode<presentation>{ |
|
426 |
\begin{frame}[c] |
|
427 |
\frametitle{\begin{tabular}{c}Ambiguous Grammars\end{tabular}} |
|
428 |
||
169
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
429 |
A grammar is \alert{ambiguous} if there is a string that has at least two different parse trees. |
50 | 430 |
|
431 |
||
432 |
\begin{center} |
|
433 |
\bl{\begin{tabular}{lcl} |
|
434 |
$E$ & $\rightarrow$ & $num\_token$ \\ |
|
53 | 435 |
$E$ & $\rightarrow$ & $E \cdot + \cdot E$ \\ |
436 |
$E$ & $\rightarrow$ & $E \cdot - \cdot E$ \\ |
|
437 |
$E$ & $\rightarrow$ & $E \cdot * \cdot E$ \\ |
|
438 |
$E$ & $\rightarrow$ & $( \cdot E \cdot )$ |
|
50 | 439 |
\end{tabular}} |
440 |
\end{center} |
|
441 |
||
442 |
\bl{\texttt{1 + 2 * 3 + 4}} |
|
443 |
||
444 |
\end{frame}} |
|
445 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
446 |
||
169
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 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
449 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
450 |
\frametitle{\begin{tabular}{c}Dangling Else\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
451 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
452 |
Another ambiguous grammar:\bigskip |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
453 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
454 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
455 |
\bl{\begin{tabular}{lcl} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
456 |
$E$ & $\rightarrow$ & if $E$ then $E$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
457 |
& $|$ & if $E$ then $E$ else $E$ \\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
458 |
& $|$ & \ldots |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
459 |
\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
460 |
\end{center}\bigskip |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
461 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
462 |
\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
|
463 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
464 |
\end{frame}} |
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 |
|
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 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
469 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
470 |
\frametitle{\begin{tabular}{c}Parser Combinators\end{tabular}} |
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 |
Parser combinators: \bigskip |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
473 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
474 |
\begin{minipage}{1.1\textwidth} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
475 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
476 |
\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
|
477 |
$\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
|
478 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
479 |
\end{minipage}\bigskip |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
480 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
481 |
\begin{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
482 |
\item sequencing |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
483 |
\item alternative |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
484 |
\item semantic action |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
485 |
\end{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
486 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
487 |
\end{frame}} |
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 |
|
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 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
492 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
493 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
494 |
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
|
495 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
496 |
\begin{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
497 |
\item apply \bl{$p$} and also \bl{$q$}; then combine the outputs |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
498 |
\end{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
499 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
500 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
501 |
\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
|
502 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
503 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
504 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
505 |
\end{frame}} |
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 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
508 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
509 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
510 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
511 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
512 |
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
|
513 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
514 |
\begin{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
515 |
\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
|
516 |
\item then apply \bl{$q$} to the unparsed parts |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
517 |
\item then combine the results:\\ \mbox{}\;\;((output$_1$, output$_2$), unparsed part) |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
518 |
\end{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
519 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
520 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
521 |
\begin{tabular}{l} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
522 |
\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
|
523 |
\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
|
524 |
\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
|
525 |
\end{tabular} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
526 |
\end{center} |
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 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
529 |
\end{frame}} |
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 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
533 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
534 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
535 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
536 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
537 |
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
|
538 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
539 |
\begin{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
540 |
\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
|
541 |
\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
|
542 |
\end{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
543 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
544 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
545 |
\begin{tabular}{l} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
546 |
\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
|
547 |
\end{tabular} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
548 |
\end{center}\bigskip\bigskip\pause |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
549 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
550 |
\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
|
551 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
552 |
\end{frame}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
553 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
554 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
555 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
556 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
557 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
558 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
559 |
\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
|
560 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
561 |
Addition |
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{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
564 |
\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
|
565 |
\end{center}\pause |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
566 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
567 |
Multiplication |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
568 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
569 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
570 |
\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
|
571 |
\end{center}\pause |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
572 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
573 |
Parenthesis |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
574 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
575 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
576 |
\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
|
577 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
578 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
579 |
\end{frame}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
580 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
581 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
582 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
583 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
584 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
585 |
\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
|
586 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
587 |
\begin{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
588 |
\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
|
589 |
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
|
590 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
591 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
592 |
\bl{$T \times S$} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
593 |
\end{center}\pause |
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 |
\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
|
596 |
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
|
597 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
598 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
599 |
\bl{$T$} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
600 |
\end{center}\pause |
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 |
\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
|
603 |
\bl{$T$} to \bl{$S$}, then |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
604 |
\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
|
605 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
606 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
607 |
\bl{$S$} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
608 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
609 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
610 |
\end{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
611 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
612 |
\end{frame}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
613 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
614 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
615 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
616 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
617 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
618 |
\frametitle{\begin{tabular}{c}Input Types of Parsers\end{tabular}} |
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{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
621 |
\item input: \alert{string} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
622 |
\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
|
623 |
\end{itemize}\bigskip\pause |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
624 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
625 |
actually it can be any input type as long as it is a kind of sequence |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
626 |
(for example a string) |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
627 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
628 |
\end{frame}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
629 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
630 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
631 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
632 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
633 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
634 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
635 |
\frametitle{\begin{tabular}{c}Scannerless Parsers\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
636 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
637 |
\begin{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
638 |
\item input: \alert{string} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
639 |
\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
|
640 |
\end{itemize}\bigskip |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
641 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
642 |
but lexers are better when whitespaces or comments need to be filtered out; |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
643 |
then input is a sequence of tokens |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
644 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
645 |
\end{frame}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
646 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
647 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
648 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
649 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
650 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
651 |
\frametitle{\begin{tabular}{c}Successful Parses\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
652 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
653 |
\begin{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
654 |
\item input: string |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
655 |
\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
|
656 |
\end{itemize}\bigskip |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
657 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
658 |
a parse is successful whenever the input has been |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
659 |
fully ``consumed'' (that is the second component is empty) |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
660 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
661 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
662 |
\end{frame}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
663 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
664 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
665 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
666 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
667 |
\begin{frame}[c] |
170
fa187fa5b642
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
169
diff
changeset
|
668 |
\frametitle{Abstract Parser Class} |
169
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 |
\mbox{\lstset{language=Scala}\fontsize{10}{12}\selectfont |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
671 |
\texttt{\lstinputlisting{../progs/app7.scala}}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
672 |
\end{frame}} |
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 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
675 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
676 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
677 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
678 |
{\lstset{language=Scala}\fontsize{10}{12}\selectfont |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
679 |
\texttt{\lstinputlisting{../progs/app8.scala}}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
680 |
\end{frame}} |
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 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
683 |
|
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 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
686 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
687 |
\frametitle{\begin{tabular}{c}Two Grammars\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
688 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
689 |
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
|
690 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
691 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
692 |
\bl{\begin{tabular}{lcl} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
693 |
$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
|
694 |
& $|$ & $\epsilon$ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
695 |
\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
696 |
\end{center}\bigskip |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
697 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
698 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
699 |
\bl{\begin{tabular}{lcl} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
700 |
$U$ & $\rightarrow$ & $1 \cdot U$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
701 |
& $|$ & $\epsilon$ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
702 |
\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
703 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
704 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
705 |
\end{frame}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
706 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
707 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
708 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
709 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
710 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
711 |
\begin{frame}[t] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
712 |
\frametitle{\begin{tabular}{c}Ambiguous Grammars\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
713 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
714 |
\mbox{}\\[-25mm]\mbox{} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
715 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
716 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
717 |
\begin{tikzpicture}[y=.2cm, x=.009cm] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
718 |
%axis |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
719 |
\draw (0,0) -- coordinate (x axis mid) (1000,0); |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
720 |
\draw (0,0) -- coordinate (y axis mid) (0,30); |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
721 |
%ticks |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
722 |
\foreach \x in {0, 20, 100, 200,...,1000} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
723 |
\draw (\x,1pt) -- (\x,-3pt) |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
724 |
node[anchor=north] {\small \x}; |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
725 |
\foreach \y in {0,5,...,30} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
726 |
\draw (1pt,\y) -- (-3pt,\y) |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
727 |
node[anchor=east] {\small\y}; |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
728 |
%labels |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
729 |
\node[below=0.6cm] at (x axis mid) {\bl{1}s}; |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
730 |
\node[rotate=90, left=1.2cm] at (y axis mid) {secs}; |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
731 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
732 |
%plots |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
733 |
\draw[color=blue] plot[mark=*, mark options={fill=white}] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
734 |
file {s-grammar1.data}; |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
735 |
\only<2->{\draw[color=red] plot[mark=triangle*, mark options={fill=white} ] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
736 |
file {s-grammar2.data};} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
737 |
%legend |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
738 |
\begin{scope}[shift={(400,20)}] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
739 |
\draw[color=blue] (0,0) -- |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
740 |
plot[mark=*, mark options={fill=white}] (0.25,0) -- (0.5,0) |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
741 |
node[right]{\small unambiguous}; |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
742 |
\only<2->{\draw[yshift=\baselineskip, color=red] (0,0) -- |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
743 |
plot[mark=triangle*, mark options={fill=white}] (0.25,0) -- (0.5,0) |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
744 |
node[right]{\small ambiguous};} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
745 |
\end{scope} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
746 |
\end{tikzpicture} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
747 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
748 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
749 |
\end{frame}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
750 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
751 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
752 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
753 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
754 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
755 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
756 |
\frametitle{\begin{tabular}{c}While-Language\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
757 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
758 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
759 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
760 |
\bl{\begin{tabular}{@{}lcl@{}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
761 |
$Stmt$ & $\rightarrow$ & $\text{skip}$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
762 |
& $|$ & $Id := AExp$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
763 |
& $|$ & $\text{if}\; B\!Exp \;\text{then}\; Block \;\text{else}\; Block$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
764 |
& $|$ & $\text{while}\; B\!Exp \;\text{do}\; Block$\medskip\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
765 |
$Stmts$ & $\rightarrow$ & $Stmt \;\text{;}\; Stmts$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
766 |
& $|$ & $Stmt$\medskip\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
767 |
$Block$ & $\rightarrow$ & $\{ Stmts \}$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
768 |
& $|$ & $Stmt$\medskip\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
769 |
$AExp$ & $\rightarrow$ & \ldots\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
770 |
$BExp$ & $\rightarrow$ & \ldots\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
771 |
\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
772 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
773 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
774 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
775 |
\end{frame}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
776 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
777 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
778 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
779 |
\mode<presentation>{ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
780 |
\begin{frame}[c] |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
781 |
\frametitle{\begin{tabular}{c}An Interpreter\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
782 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
783 |
\begin{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
784 |
\bl{\begin{tabular}{l} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
785 |
$\{$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
786 |
\;\;$x := 5 \text{;}$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
787 |
\;\;$y := x * 3\text{;}$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
788 |
\;\;$y := x * 4\text{;}$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
789 |
\;\;$x := u * 3$\\ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
790 |
$\}$ |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
791 |
\end{tabular}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
792 |
\end{center} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
793 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
794 |
\begin{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
795 |
\item the interpreter has to record the value of \bl{$x$} before assigning a value to \bl{$y$}\pause |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
796 |
\item \bl{\text{eval}(stmt, env)} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
797 |
\end{itemize} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
798 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
799 |
|
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
800 |
\end{frame}} |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
801 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
57df3d7b4a25
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
168
diff
changeset
|
802 |
|
50 | 803 |
|
184
2e9134d25a2b
added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
170
diff
changeset
|
804 |
|
53 | 805 |
|
51 | 806 |
|
49 | 807 |
\end{document} |
808 |
||
809 |
%%% Local Variables: |
|
810 |
%%% mode: latex |
|
811 |
%%% TeX-master: t |
|
812 |
%%% End: |
|
813 |