slides/slides08.tex
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Mon, 11 Nov 2013 15:26:20 +0000
changeset 184 2e9134d25a2b
parent 93 4794759139ea
child 196 7182786d9c68
permissions -rw-r--r--
added slides
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]
70
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   154
\frametitle{\begin{tabular}{c}Building a ``Web Browser''\end{tabular}}
66
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]
70
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   174
\frametitle{\begin{tabular}{c}Interpreting a List of Tokens\end{tabular}}
66
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}
70
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   177
\item the 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: 69
diff changeset
   178
\item potential linebreaks are inserted by the formatter (not the input)
66
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]
70
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   193
\frametitle{\begin{tabular}{c}Interpreting a List of Tokens\end{tabular}}
66
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}
70
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   259
\item apply first \bl{$p$} producing a set of pairs
66
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
70
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   261
\item then combine the results:\\ \mbox{}\;\;((output$_1$, output$_2$), unparsed part)
66
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
70
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   285
\item then apply the function \bl{$f$} to each first component
66
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}
70
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   292
\end{center}\bigskip\bigskip\pause
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   293
70
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   294
\bl{$f$} is the semantic action (``what to do with the parsed input'')
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   295
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   296
\end{frame}}
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   301
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   302
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   303
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   304
Token parser:\bigskip
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   305
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   306
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   307
\item if the input is
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   308
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   309
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   310
\large \bl{$tok_1:: tok_2 :: \ldots :: tok_n$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   311
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   312
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   313
then return
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   314
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   315
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   316
\large \bl{$\{(tok_1,\; tok_2 :: \ldots :: tok_n)\}$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   317
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   318
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   319
or
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   320
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   321
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   322
\large \bl{$\{\}$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   323
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   324
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   325
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
   326
\end{itemize}
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
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   330
\end{frame}}
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   334
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   335
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   336
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   337
Number-Token parser:\bigskip
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   338
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   339
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   340
\item if the input is
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   341
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   342
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   343
\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
   344
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   345
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   346
then return
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   347
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   348
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   349
\large \bl{$\{(42,\; tok_2 :: \ldots :: tok_n)\}$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   350
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   351
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   352
or
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   353
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   354
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   355
\large \bl{$\{\}$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   356
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   357
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   358
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
   359
\end{itemize}\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   360
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   361
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   362
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
   363
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   364
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   365
\end{frame}}
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   369
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   370
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   371
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   372
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   373
\item if the input is
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   374
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   375
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   376
\begin{tabular}{l}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   377
\large \bl{$num\_tok(42)::$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   378
\hspace{7mm}\large \bl{$num\_tok(3) ::$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   379
\hspace{14mm}\large \bl{$tok_3 :: \ldots :: tok_n$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   380
\end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   381
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   382
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   383
and the parser is 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   384
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   385
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   386
\bl{$ntp \sim ntp$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   387
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   388
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   389
the successful output will be
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   390
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   391
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   392
\large \bl{$\{((42, 3),\; tok_2 :: \ldots :: tok_n)\}$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   393
\end{center}\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   394
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   395
Now we can form
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   396
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   397
\bl{$(ntp \sim ntp) \Longrightarrow f$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   398
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   399
70
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   400
where \bl{$f$} is the semantic action (``what to do with the pair'')
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   401
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   402
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   403
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   404
\end{frame}}
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   408
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   409
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   410
\frametitle{\begin{tabular}{c}Semantic Actions\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   411
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   412
Addition
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   413
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   414
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   415
\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
   416
\end{center}\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   417
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   418
Multiplication
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   419
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   420
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   421
\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
   422
\end{center}\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   423
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   424
Parenthesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   425
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   426
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   427
\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
   428
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   429
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   430
\end{frame}}
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   434
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   435
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   436
\frametitle{\begin{tabular}{c}Types of Parsers\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   437
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   438
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   439
\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
   440
then \bl{$p \sim q$} returns results of type
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   441
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   442
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   443
\bl{$T \times S$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   444
\end{center}\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   445
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   446
\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
   447
and \bl{$p \;||\; q$} returns results of type
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   448
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   449
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   450
\bl{$T$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   451
\end{center}\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   452
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   453
\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
   454
\bl{$T$} to \bl{$S$}, then
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   455
\bl{$p \Longrightarrow f$} returns results of type
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   456
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   457
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   458
\bl{$S$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   459
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   460
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   461
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   462
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   463
\end{frame}}
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   467
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   468
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   469
\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
   470
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   471
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   472
\item input: \alert{list of tokens}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   473
\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
   474
\end{itemize}\bigskip\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   475
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   476
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
   477
(for example a string)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   478
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   479
\end{frame}}
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
70
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   482
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   483
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   484
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   485
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   486
\frametitle{\begin{tabular}{c}Scannerless Parsers\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   487
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   488
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   489
\item input: \alert{string}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   490
\item output: set of (output\_type, \alert{string})
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   491
\end{itemize}\bigskip
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   492
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   493
but lexers are better when whitespaces or comments need to be filtered out
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   494
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   495
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   496
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   497
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   498
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   499
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   500
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   501
\frametitle{\begin{tabular}{c}Successful Parses\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   502
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   503
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   504
\item input: string
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   505
\item output: \alert{set of} (output\_type, string)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   506
\end{itemize}\bigskip
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   507
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   508
a parse is successful whenever the input has been
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   509
fully ``consumed'' (that is the second component is empty)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   510
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   511
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   512
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   513
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   514
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   515
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   516
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   517
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   518
{\lstset{language=Scala}\fontsize{10}{12}\selectfont
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   519
\texttt{\lstinputlisting{app7.scala}}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   520
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   521
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   522
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   523
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   524
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   525
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   526
{\lstset{language=Scala}\fontsize{10}{12}\selectfont
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   527
\texttt{\lstinputlisting{app7.scala}}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   528
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   529
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   530
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   531
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   532
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   533
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   534
{\lstset{language=Scala}\fontsize{10}{12}\selectfont
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   535
\texttt{\lstinputlisting{app8.scala}}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   536
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   537
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   538
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   539
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   540
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   541
\begin{frame}[c]
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   542
\frametitle{\begin{tabular}{c}Two Grammars\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   543
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   544
Which languages are recognised by the following two grammars?
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   545
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   546
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   547
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   548
$S$ & $\rightarrow$ &  $1 \cdot S \cdot S$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   549
        & $|$ & $\epsilon$
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   550
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   551
\end{center}\bigskip
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
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   554
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   555
$U$ & $\rightarrow$ &  $1 \cdot U$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   556
        & $|$ & $\epsilon$
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   557
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   558
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   559
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   560
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   561
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   562
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   563
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   564
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   565
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   566
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   567
\frametitle{\begin{tabular}{c}Ambiguous Grammars\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   568
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   569
\mbox{}\\[-25mm]\mbox{}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   570
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   571
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   572
\begin{tikzpicture}[y=.2cm, x=.009cm]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   573
 	%axis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   574
	\draw (0,0) -- coordinate (x axis mid) (1000,0);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   575
    	\draw (0,0) -- coordinate (y axis mid) (0,30);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   576
    	%ticks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   577
    	\foreach \x in {0, 20, 100, 200,...,1000}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   578
     		\draw (\x,1pt) -- (\x,-3pt)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   579
			node[anchor=north] {\small \x};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   580
    	\foreach \y in {0,5,...,30}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   581
     		\draw (1pt,\y) -- (-3pt,\y) 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   582
     			node[anchor=east] {\small\y}; 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   583
	%labels      
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   584
	\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
   585
	\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
   586
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   587
	%plots
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   588
	\draw[color=blue] plot[mark=*, mark options={fill=white}] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   589
		file {s-grammar1.data};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   590
         \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
   591
                  file {s-grammar2.data};}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   592
	%legend
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   593
	\begin{scope}[shift={(400,20)}] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   594
	\draw[color=blue] (0,0) -- 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   595
		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
   596
		node[right]{\small unambiguous};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   597
	\only<2->{\draw[yshift=\baselineskip, color=red] (0,0) -- 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   598
                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
   599
                node[right]{\small ambiguous};}  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   600
	\end{scope}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   601
\end{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   602
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   603
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   604
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   605
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   606
67
1419b60f6b0e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
   607
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1419b60f6b0e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
   608
\mode<presentation>{
1419b60f6b0e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
   609
\begin{frame}[c]
1419b60f6b0e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
   610
\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
   611
1419b60f6b0e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
   612
\begin{itemize}
1419b60f6b0e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
   613
\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
   614
\item whenever the is a recursion, the parser must have consumed something --- so
70
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   615
we can decrease the input string/list of token by one (at the end)
67
1419b60f6b0e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
   616
\end{itemize}
1419b60f6b0e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
   617
\end{frame}}
1419b60f6b0e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
   618
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
1419b60f6b0e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
   619
69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   620
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   621
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   622
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   623
\frametitle{\begin{tabular}{c}While-Language\end{tabular}}
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
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   626
\begin{center}
70
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   627
\bl{\begin{tabular}{@{}lcl@{}}
69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   628
$Stmt$ & $\rightarrow$ &  $\text{skip}$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   629
              & $|$ & $Id := AExp$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   630
              & $|$ & $\text{if}\; B\!Exp \;\text{then}\; Block \;\text{else}\; Block$\\
70
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   631
              & $|$ & $\text{while}\; B\!Exp \;\text{do}\; Block$\medskip\\
76
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 70
diff changeset
   632
$Stmts$ & $\rightarrow$ &  $Stmt \;\text{;}\; Stmts$\\
70
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   633
              & $|$ & $Stmt$\medskip\\
69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   634
$Block$ & $\rightarrow$ &  $\{ Stmts \}$\\
70
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   635
                & $|$ & $Stmt$\medskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   636
$AExp$ & $\rightarrow$ & \ldots\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   637
$BExp$ & $\rightarrow$ & \ldots\\
69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   638
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   639
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   640
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   641
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   642
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   643
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   644
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   645
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   646
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   647
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   648
\frametitle{\begin{tabular}{c}An Interpreter\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   649
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   650
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   651
\bl{\begin{tabular}{l}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   652
$\{$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   653
\;\;$x := 5 \text{;}$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   654
\;\;$y := x * 3\text{;}$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   655
\;\;$y := x * 4\text{;}$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   656
\;\;$x := u * 3$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   657
$\}$
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   658
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   659
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   660
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   661
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   662
\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
   663
\item \bl{\text{eval}(stmt, env)}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   664
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   665
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   666
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   667
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   668
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   669
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   670
\end{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   671
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   672
%%% Local Variables:  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   673
%%% mode: latex
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   674
%%% TeX-master: t
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   675
%%% End: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   676