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