slides08.tex
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Wed, 21 Nov 2012 07:28:28 +0000
changeset 69 cc3f7908b942
parent 67 1419b60f6b0e
child 70 e6868bd2942b
permissions -rw-r--r--
tuned
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
\documentclass[dvipsnames,14pt,t]{beamer}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
\usepackage{beamerthemeplainculight}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
\usepackage[T1]{fontenc}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
\usepackage[latin1]{inputenc}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
\usepackage{mathpartir}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
\usepackage[absolute,overlay]{textpos}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
\usepackage{ifthen}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
\usepackage{tikz}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
\usepackage{pgf}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
\usepackage{calc} 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
\usepackage{ulem}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
\usepackage{courier}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
\usepackage{listings}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
\renewcommand{\uline}[1]{#1}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
\usetikzlibrary{arrows}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
\usetikzlibrary{automata}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
\usetikzlibrary{shapes}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
\usetikzlibrary{shadows}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
\usetikzlibrary{positioning}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
\usetikzlibrary{calc}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
\usetikzlibrary{plotmarks}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
\usepackage{graphicx} 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
\definecolor{javared}{rgb}{0.6,0,0} % for strings
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
\definecolor{javagreen}{rgb}{0.25,0.5,0.35} % comments
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
\definecolor{javapurple}{rgb}{0.5,0,0.35} % keywords
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
\definecolor{javadocblue}{rgb}{0.25,0.35,0.75} % javadoc
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
\lstset{language=Java,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
	basicstyle=\ttfamily,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
	keywordstyle=\color{javapurple}\bfseries,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
	stringstyle=\color{javagreen},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
	commentstyle=\color{javagreen},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
	morecomment=[s][\color{javadocblue}]{/**}{*/},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
	numbers=left,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
	numberstyle=\tiny\color{black},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
	stepnumber=1,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
	numbersep=10pt,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
	tabsize=2,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
	showspaces=false,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
	showstringspaces=false}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
\lstdefinelanguage{scala}{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
  morekeywords={abstract,case,catch,class,def,%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
    do,else,extends,false,final,finally,%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
    for,if,implicit,import,match,mixin,%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
    new,null,object,override,package,%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
    private,protected,requires,return,sealed,%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
    super,this,throw,trait,true,try,%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
    type,val,var,while,with,yield},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
  otherkeywords={=>,<-,<\%,<:,>:,\#,@},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
  sensitive=true,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
  morecomment=[l]{//},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
  morecomment=[n]{/*}{*/},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
  morestring=[b]",
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
  morestring=[b]',
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
  morestring=[b]"""
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
\lstset{language=Scala,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
	basicstyle=\ttfamily,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
	keywordstyle=\color{javapurple}\bfseries,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
	stringstyle=\color{javagreen},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
	commentstyle=\color{javagreen},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
	morecomment=[s][\color{javadocblue}]{/**}{*/},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
	numbers=left,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
	numberstyle=\tiny\color{black},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
	stepnumber=1,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
	numbersep=10pt,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
	tabsize=2,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
	showspaces=false,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
	showstringspaces=false}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
% beamer stuff 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
\renewcommand{\slidecaption}{AFL 08, King's College London, 21.~November 2012}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
\newcommand{\bl}[1]{\textcolor{blue}{#1}}       
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
% The data files, written on the first run.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    81
\begin{filecontents}{s-grammar1.data}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
1 0.01152
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    83
51 0.07973
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    84
101 0.09726
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    85
151 0.09320
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
201 0.10010
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
251 0.16997
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    88
301 0.26662
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
351 0.46118
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    90
401 0.62516
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
451 0.87247
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
501 1.16334
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
551 1.71152
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    94
601 2.10958
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
651 2.44360
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
701 2.98488
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
751 3.50326
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    98
801 4.11036
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    99
851 4.93394
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   100
901 5.77465
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   101
951 7.39123
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   102
\end{filecontents}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   103
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   104
\begin{filecontents}{s-grammar2.data}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   105
1 0.01280
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   106
2 0.00064
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   107
3 0.00173
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   108
4 0.00355
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   109
5 0.00965
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   110
6 0.02674
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   111
7 0.06953
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   112
8 0.11166
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   113
9 0.18707
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   114
10 0.09189
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   115
11 0.12724
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   116
12 0.24337
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   117
13 0.59304
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   118
14 1.53594
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   119
15 4.01195
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   120
16 10.73582
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   121
17 29.51587
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   122
#18 73.14163
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   123
\end{filecontents}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   124
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   125
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   126
\begin{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   128
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   129
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   130
\begin{frame}<1>[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   131
\frametitle{%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   132
  \begin{tabular}{@ {}c@ {}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   133
  \\[-3mm]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   134
  \LARGE Automata and \\[-2mm] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   135
  \LARGE Formal Languages (8)\\[3mm] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   136
  \end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   137
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   138
  \normalsize
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   139
  \begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   140
  \begin{tabular}{ll}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   141
  Email:  & christian.urban at kcl.ac.uk\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   142
  Of$\!$fice: & S1.27 (1st floor Strand Building)\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   143
  Slides: & KEATS (also home work is there)\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   144
  \end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   145
  \end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   146
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   147
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   148
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   149
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   150
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   151
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   152
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   153
\begin{frame}[c]
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   154
\frametitle{\begin{tabular}{c}Building a Web Browser\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   155
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   156
Using a lexer: assume the following regular expressions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   157
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   158
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   159
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   160
$SY\!M$ & $\dn$ & $(\text{a}..\text{zA}..\text{Z0}..\text{9}..)$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   161
$W\!O\!RD$ & $\dn$ & $SY\!M^+$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   162
$BT\!AG$ & $\dn$ & $<\!W\!O\!RD\!>$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   163
$ET\!AG$ & $\dn$ & $<\!/W\!O\!RD\!>$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   164
$W\!HIT\!E$ & $\dn$ & $\texttt{" "} + \texttt{"}\slash{}n\texttt{"}$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   165
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   166
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   167
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   168
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   169
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   170
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   171
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   172
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   173
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   174
\frametitle{\begin{tabular}{c}Interpreting a List of Token\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   175
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   176
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   177
\item text should be formatted consistently up to a specified width, say 60 characters 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   178
\item potential linebreaks are inserted by the formatter
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   179
\item repeated whitespaces are ``condensed'' to a single whitepace
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   180
\item \bl{$<\!p\!>$} \bl{$<\!\slash{}p\!>$}  start/end paragraph
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   181
\item \bl{$<\!b\!>$} \bl{$<\!\slash{}b\!>$}  start/end bold
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   182
\item \bl{$<\!red\!>$} \bl{$<\!\slash{}red\!>$}  start/end red (cyan, etc)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   183
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   184
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   185
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   186
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   187
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   188
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   189
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   190
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   191
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   192
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   193
\frametitle{\begin{tabular}{c}Interpreting a List of Token\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   194
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   195
The lexer cannot prevent errors like
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   197
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   198
\bl{$<\!b\!>$} \ldots \bl{$<\!p\!>$} \ldots \bl{$<\!\slash{}b\!>$} \ldots \bl{$<\!\slash{}p\!>$} 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   199
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   200
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   201
or
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   202
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   203
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   204
\bl{$<\!\slash{}b\!>$} \ldots \bl{$<\!b\!>$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   205
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   206
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   207
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   208
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   209
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   210
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   211
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   212
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   213
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   214
\frametitle{\begin{tabular}{c}Parser Combinators\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   215
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   216
Parser combinators: \bigskip
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   217
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   218
\begin{minipage}{1.1\textwidth}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   219
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   220
\mbox{}\hspace{-12mm}\mbox{}$\underbrace{\text{list of tokens}}_{\text{input}}$ \bl{$\Rightarrow$} 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   221
$\underbrace{\text{set of (parsed input, unparsed input)}}_{\text{output}}$
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   222
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   223
\end{minipage}\bigskip
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   224
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   225
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   226
\item sequencing
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   227
\item alternative
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   228
\item semantic action
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   229
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   230
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   231
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   232
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   233
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   234
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   235
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   236
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   237
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   238
Alternative parser (code \bl{$p\;||\;q$})\bigskip
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   239
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   240
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   241
\item apply \bl{$p$} and also \bl{$q$}; then combine the outputs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   242
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   243
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   244
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   245
\large \bl{$p(\text{input}) \cup q(\text{input})$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   246
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   247
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   248
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   249
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   250
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   251
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   252
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   253
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   254
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   255
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   256
Sequence parser (code \bl{$p\sim q$})\bigskip
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   257
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   258
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   259
\item apply \bl{$p$} first producing a set of pairs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   260
\item then apply \bl{$q$} to the unparsed parts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   261
\item the combine the results:\\ \mbox{}\;\;((input$_1$, input$_2$), unparsed part)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   262
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   263
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   264
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   265
\begin{tabular}{l}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   266
\large \bl{$\{((o_1, o_2), u_2) \;|\;$}\\[2mm] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   267
\large\mbox{}\hspace{15mm} \bl{$(o_1, u_1) \in p(\text{input}) \wedge$}\\[2mm]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   268
\large\mbox{}\hspace{15mm} \bl{$(o_2, u_2) \in q(u_1)\}$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   269
\end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   270
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   271
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   272
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   273
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   274
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   275
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   276
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   277
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   278
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   279
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   280
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   281
Function parser (code \bl{$p \Longrightarrow f$})\bigskip
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   282
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   283
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   284
\item apply \bl{$p$} producing a set of pairs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   285
\item then apply the function \bl{$f$} to each fist component
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   286
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   287
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   288
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   289
\begin{tabular}{l}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   290
\large \bl{$\{(f(o_1), u_1) \;|\; (o_1, u_1) \in p(\text{input})\}$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   291
\end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   292
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   293
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   294
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   295
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   296
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   297
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   298
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   299
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   300
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   301
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   302
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   303
Token parser:\bigskip
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   304
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   305
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   306
\item if the input is
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   307
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   308
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   309
\large \bl{$tok_1:: tok_2 :: \ldots :: tok_n$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   310
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   311
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   312
then return
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   313
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   314
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   315
\large \bl{$\{(tok_1,\; tok_2 :: \ldots :: tok_n)\}$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   316
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   317
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   318
or
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   319
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   320
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   321
\large \bl{$\{\}$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   322
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   323
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   324
if \bl{$tok_1$} is not the right token we are looking for
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   325
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   326
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   327
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   328
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   329
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   330
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   331
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   332
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   333
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   334
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   335
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   336
Number-Token parser:\bigskip
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   337
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   338
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   339
\item if the input is
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   340
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   341
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   342
\large \bl{$num\_tok(42):: tok_2 :: \ldots :: tok_n$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   343
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   344
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   345
then return
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   346
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   347
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   348
\large \bl{$\{(42,\; tok_2 :: \ldots :: tok_n)\}$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   349
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   350
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   351
or
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   352
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   353
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   354
\large \bl{$\{\}$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   355
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   356
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   357
if \bl{$tok_1$} is not the right token we are looking for
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   358
\end{itemize}\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   359
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   360
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   361
list of tokens \bl{$\Rightarrow$} set of (\alert{int}, list of tokens)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   362
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   363
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   364
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   365
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   366
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   367
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   368
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   369
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   370
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   371
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   372
\item if the input is
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   373
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   374
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   375
\begin{tabular}{l}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   376
\large \bl{$num\_tok(42)::$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   377
\hspace{7mm}\large \bl{$num\_tok(3) ::$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   378
\hspace{14mm}\large \bl{$tok_3 :: \ldots :: tok_n$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   379
\end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   380
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   381
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   382
and the parser is 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   383
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   384
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   385
\bl{$ntp \sim ntp$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   386
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   387
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   388
the successful output will be
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   389
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   390
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   391
\large \bl{$\{((42, 3),\; tok_2 :: \ldots :: tok_n)\}$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   392
\end{center}\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   393
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   394
Now we can form
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   395
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   396
\bl{$(ntp \sim ntp) \Longrightarrow f$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   397
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   398
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   399
where \bl{$f$} is the semantic action (what to do with the pair)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   400
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   401
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   402
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   403
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   404
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   405
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   406
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   407
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   408
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   409
\frametitle{\begin{tabular}{c}Semantic Actions\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   410
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   411
Addition
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   412
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   413
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   414
\bl{$T \sim + \sim E \Longrightarrow \underbrace{f((x,y), z) \Rightarrow x + z}_{\text{semantic action}}$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   415
\end{center}\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   416
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   417
Multiplication
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   418
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   419
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   420
\bl{$F \sim * \sim T \Longrightarrow f((x,y), z) \Rightarrow x * z$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   421
\end{center}\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   422
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   423
Parenthesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   424
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   425
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   426
\bl{$\text{(} \sim E \sim \text{)} \Longrightarrow f((x,y), z) \Rightarrow y$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   427
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   428
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   429
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   430
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   431
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   432
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   433
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   434
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   435
\frametitle{\begin{tabular}{c}Types of Parsers\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   436
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   437
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   438
\item {\bf Sequencing}: if \bl{$p$} returns results of type \bl{$T$}, and \bl{$q$} results of type \bl{$S$},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   439
then \bl{$p \sim q$} returns results of type
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   440
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   441
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   442
\bl{$T \times S$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   443
\end{center}\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   444
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   445
\item {\bf Alternative}: if \bl{$p$} returns results of type \bl{$T$} then  \bl{$q$} \alert{must} also have results of type \bl{$T$},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   446
and \bl{$p \;||\; q$} returns results of type
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   447
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   448
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   449
\bl{$T$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   450
\end{center}\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   451
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   452
\item {\bf Semantic Action}: if \bl{$p$} returns results of type \bl{$T$} and \bl{$f$} is a function from
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   453
\bl{$T$} to \bl{$S$}, then
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   454
\bl{$p \Longrightarrow f$} returns results of type
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   455
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   456
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   457
\bl{$S$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   458
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   459
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   460
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   461
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   462
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   463
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   464
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   465
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   466
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   467
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   468
\frametitle{\begin{tabular}{c}Input Types of Parsers\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   469
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   470
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   471
\item input: \alert{list of tokens}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   472
\item output: set of (output\_type, \alert{list of tokens})
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   473
\end{itemize}\bigskip\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   474
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   475
actually it can be any input type as long as it is a kind of sequence
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   476
(for example a string)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   477
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   478
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   479
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   480
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   481
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   482
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   483
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   484
{\lstset{language=Scala}\fontsize{10}{12}\selectfont
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   485
\texttt{\lstinputlisting{app7.scala}}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   486
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   487
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   488
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   489
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   490
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   491
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   492
{\lstset{language=Scala}\fontsize{10}{12}\selectfont
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   493
\texttt{\lstinputlisting{app7.scala}}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   494
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   495
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   496
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   497
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   498
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   499
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   500
{\lstset{language=Scala}\fontsize{10}{12}\selectfont
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   501
\texttt{\lstinputlisting{app8.scala}}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   502
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   503
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   504
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   505
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   506
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   507
\begin{frame}[c]
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   508
\frametitle{\begin{tabular}{c}Two Grammars\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   509
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   510
Which languages are recognised by the following two grammars?
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   511
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   512
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   513
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   514
$S$ & $\rightarrow$ &  $1 \cdot S \cdot S$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   515
        & $|$ & $\epsilon$
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   516
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   517
\end{center}\bigskip
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   518
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   519
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   520
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   521
$U$ & $\rightarrow$ &  $1 \cdot U$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   522
        & $|$ & $\epsilon$
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   523
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   524
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   525
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   526
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   527
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   528
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   529
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   530
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   531
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   532
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   533
\frametitle{\begin{tabular}{c}Ambiguous Grammars\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   534
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   535
\mbox{}\\[-25mm]\mbox{}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   536
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   537
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   538
\begin{tikzpicture}[y=.2cm, x=.009cm]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   539
 	%axis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   540
	\draw (0,0) -- coordinate (x axis mid) (1000,0);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   541
    	\draw (0,0) -- coordinate (y axis mid) (0,30);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   542
    	%ticks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   543
    	\foreach \x in {0, 20, 100, 200,...,1000}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   544
     		\draw (\x,1pt) -- (\x,-3pt)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   545
			node[anchor=north] {\small \x};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   546
    	\foreach \y in {0,5,...,30}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   547
     		\draw (1pt,\y) -- (-3pt,\y) 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   548
     			node[anchor=east] {\small\y}; 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   549
	%labels      
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   550
	\node[below=0.6cm] at (x axis mid) {\bl{1}s};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   551
	\node[rotate=90, left=1.2cm] at (y axis mid) {secs};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   552
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   553
	%plots
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   554
	\draw[color=blue] plot[mark=*, mark options={fill=white}] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   555
		file {s-grammar1.data};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   556
         \only<2->{\draw[color=red] plot[mark=triangle*, mark options={fill=white} ] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   557
                  file {s-grammar2.data};}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   558
	%legend
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   559
	\begin{scope}[shift={(400,20)}] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   560
	\draw[color=blue] (0,0) -- 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   561
		plot[mark=*, mark options={fill=white}] (0.25,0) -- (0.5,0) 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   562
		node[right]{\small unambiguous};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   563
	\only<2->{\draw[yshift=\baselineskip, color=red] (0,0) -- 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   564
                plot[mark=triangle*, mark options={fill=white}] (0.25,0) -- (0.5,0)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   565
                node[right]{\small ambiguous};}  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   566
	\end{scope}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   567
\end{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   568
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   569
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   570
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   571
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   572
67
1419b60f6b0e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
   573
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1419b60f6b0e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
   574
\mode<presentation>{
1419b60f6b0e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
   575
\begin{frame}[c]
1419b60f6b0e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
   576
\frametitle{\begin{tabular}{c}What about Left-Recursion?\end{tabular}}
1419b60f6b0e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
   577
1419b60f6b0e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
   578
\begin{itemize}
1419b60f6b0e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
   579
\item we record when we recursively called a parser\bigskip
1419b60f6b0e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
   580
\item whenever the is a recursion, the parser must have consumed something --- so
1419b60f6b0e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
   581
I can decrease the input string/list of token by one (at the end)
1419b60f6b0e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
   582
\end{itemize}
1419b60f6b0e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
   583
\end{frame}}
1419b60f6b0e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
   584
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
1419b60f6b0e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
   585
69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   586
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   587
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   588
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   589
\frametitle{\begin{tabular}{c}While-Language\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   590
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   591
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   592
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   593
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   594
$Stmt$ & $\rightarrow$ &  $\text{skip}$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   595
              & $|$ & $Id := AExp$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   596
              & $|$ & $\text{if}\; B\!Exp \;\text{then}\; Block \;\text{else}\; Block$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   597
              & $|$ & $\text{while}\; B\!Exp \;\text{do}\; Block$\bigskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   598
$Stmt$ & $\rightarrow$ &  $Stmt \;\text{;}\; Stmts$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   599
              & $|$ & $Stmt$\bigskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   600
$Block$ & $\rightarrow$ &  $\{ Stmts \}$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   601
                & $|$ & $Stmt$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   602
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   603
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   604
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   605
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   606
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   607
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   608
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   609
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   610
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   611
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   612
\frametitle{\begin{tabular}{c}An Interpreter\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   613
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   614
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   615
\bl{\begin{tabular}{l}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   616
$\{$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   617
\;\;$x := 5 \text{;}$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   618
\;\;$y := x * 3\text{;}$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   619
\;\;$y := x * 4\text{;}$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   620
\;\;$x := u * 3$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   621
$\}$
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   622
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   623
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   624
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   625
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   626
\item the interpreter has to record the value of \bl{$x$} before assigning a value to \bl{$y$}\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   627
\item \bl{\text{eval}(stmt, env)}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   628
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   629
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   630
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   631
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   632
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   633
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   634
\end{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   635
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   636
%%% Local Variables:  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   637
%%% mode: latex
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   638
%%% TeX-master: t
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   639
%%% End: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   640