slides/slides06.tex
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Sat, 24 Sep 2016 08:37:48 +0100
changeset 429 7e71c947ec69
parent 368 a9911966c0df
child 445 e7d0157f0471
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}
295
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
     2
\usepackage{../slides}
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
     3
\usepackage{../graphics}
215
828303e8e4af updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
     4
\usepackage{../langs}
828303e8e4af updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
     5
\usepackage{../data}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
% beamer stuff 
295
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
     9
\renewcommand{\slidecaption}{AFL 06, King's College London}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    10
\newcommand{\bl}[1]{\textcolor{blue}{#1}}       
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    11
%\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions
366
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
    12
\newcommand{\qq}{\mbox{\texttt{"}}}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
\begin{document}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
295
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    17
\begin{frame}[t]
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
\frametitle{%
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
  \begin{tabular}{@ {}c@ {}}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
  \\[-3mm]
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
  \LARGE Automata and \\[-2mm] 
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
  \LARGE Formal Languages (6)\\[3mm] 
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
  \end{tabular}}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
  \normalsize
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
  \begin{center}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
  \begin{tabular}{ll}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
  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
    29
  Office: & S1.27 (1st floor Strand Building)\\
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
  Slides: & KEATS (also home work is there)\\
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
  \end{tabular}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
  \end{center}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
295
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    34
\end{frame}
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    35
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
170
fa187fa5b642 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 169
diff changeset
    37
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fa187fa5b642 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 169
diff changeset
    38
\begin{frame}[c]
fa187fa5b642 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 169
diff changeset
    39
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    40
\mbox{}\\[-18mm]\mbox{}
170
fa187fa5b642 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 169
diff changeset
    41
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    42
{\lstset{language=Scala}\fontsize{10}{12}\selectfont
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    43
\texttt{\lstinputlisting[xleftmargin=0mm]{../progs/pow.scala}}}
170
fa187fa5b642 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 169
diff changeset
    44
295
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    45
\end{frame}
170
fa187fa5b642 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 169
diff changeset
    46
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
\begin{frame}[c]
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    50
\small
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    51
\mbox{}\\[5mm]
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    52
%\begin{textblock}{10}(3,5)
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    53
\begin{tikzpicture}[scale=1.5,
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    54
                    node distance=1cm,
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    55
                    every node/.style={minimum size=7mm}]
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    56
\node (r1)  {\bl{$r_1$}};
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    57
\node (r2) [right=of r1] {\bl{$r_2$}};
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    58
\draw[->,line width=1mm]  (r1) -- (r2) node[above,midway] {\bl{$der\,a$}};
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    59
\node (r3) [right=of r2] {\bl{$r_3$}};
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    60
\draw[->,line width=1mm]  (r2) -- (r3) node[above,midway] {\bl{$der\,b$}};
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    61
\node (r4) [right=of r3] {\bl{$r_4$}};
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    62
\draw[->,line width=1mm]  (r3) -- (r4) node[above,midway] {\bl{$der\,c$}};
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    63
\draw (r4) node[anchor=west] {\;\raisebox{3mm}{\bl{$nullable$}}};
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    64
\node (v4) [below=of r4] {\bl{$v_4$}};
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    65
\draw[->,line width=1mm]  (r4) -- (v4);
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    66
\node (v3) [left=of v4] {\bl{$v_3$}};
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    67
\draw[->,line width=1mm]  (v4) -- (v3) node[below,midway] {\bl{$inj\,c$}};
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    68
\node (v2) [left=of v3] {\bl{$v_2$}};
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    69
\draw[->,line width=1mm]  (v3) -- (v2) node[below,midway] {\bl{$inj\,b$}};
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    70
\node (v1) [left=of v2] {\bl{$v_1$}};
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    71
\draw[->,line width=1mm]  (v2) -- (v1) node[below,midway] {\bl{$inj\,a$}};
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    72
\draw[->,line width=0.5mm]  (r3) -- (v3);
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    73
\draw[->,line width=0.5mm]  (r2) -- (v2);
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    74
\draw[->,line width=0.5mm]  (r1) -- (v1);
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    75
\draw (r4) node[anchor=north west] {\;\raisebox{-8mm}{\bl{$mkeps$}}};
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    76
\end{tikzpicture}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    77
%\end{textblock}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    78
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    79
\begin{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    80
\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    81
  \\[-10mm]
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    82
  \bl{$inj\,(c)\,c\,Empty$} & \bl{$\dn$}  & \bl{$Char\,c$}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    83
  \bl{$inj\,(r_1 + r_2)\,c\,Left(v)$} & \bl{$\dn$}  & \bl{$Left(inj\,r_1\,c\,v)$}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    84
  \bl{$inj\,(r_1 + r_2)\,c\,Right(v)$} & \bl{$\dn$}  & \bl{$Right(inj\,r_2\,c\,v)$}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    85
  \bl{$inj\,(r_1 \cdot r_2)\,c\,Seq(v_1,v_2)$} & \bl{$\dn$}  & \bl{$Seq(inj\,r_1\,c\,v_1,v_2)$}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    86
  \bl{$inj\,(r_1 \cdot r_2)\,c\,Left(Seq(v_1,v_2))$} & \bl{$\dn$}  & \bl{$Seq(inj\,r_1\,c\,v_1,v_2)$}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    87
  \bl{$inj\,(r_1 \cdot r_2)\,c\,Right(v)$} & \bl{$\dn$}  & \bl{$Seq(mkeps(r_1),inj\,r_2\,c\,v)$}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    88
  \bl{$inj\,(r^*)\,c\,Seq(v,vs)$} & \bl{$\dn$}  & \bl{$inj\,r\,c\,v\,::\,vs$}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    89
\end{tabular}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    90
\end{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    91
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    92
\end{frame}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    93
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    94
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    95
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    96
\begin{frame}[c]
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    97
\frametitle{\begin{tabular}{c}Hierarchy of Languages\end{tabular}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    98
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    99
Recall that languages are sets of strings.
295
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   100
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   101
\begin{center}
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   102
\begin{tikzpicture}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   103
[rect/.style={draw=black!50, top color=white,bottom color=black!20, rectangle, very thick, rounded corners}]
295
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   104
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   105
\draw (0,0) node [rect, text depth=39mm, text width=68mm] {all languages};
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   106
\draw (0,-0.4) node [rect, text depth=28.5mm, text width=64mm] {decidable languages};
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   107
\draw (0,-0.85) node [rect, text depth=17mm] {context sensitive languages};
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   108
\draw (0,-1.14) node [rect, text depth=9mm, text width=50mm] {context-free languages};
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   109
\draw (0,-1.4) node [rect] {regular languages};
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   110
\end{tikzpicture}
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   111
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   112
\end{center}
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   113
366
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   114
\end{frame}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   115
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   116
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   117
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   118
\begin{frame}[c]
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   119
\frametitle{Two Grammars}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   120
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   121
Which languages are recognised by the following two grammars?
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   122
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   123
\begin{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   124
\bl{\begin{tabular}{lcl}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   125
$S$ & $\rightarrow$ &  $1 \cdot S \cdot S$\\
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   126
        & $|$ & $\epsilon$
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   127
\end{tabular}}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   128
\end{center}\bigskip
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   129
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   130
\begin{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   131
\bl{\begin{tabular}{lcl}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   132
$U$ & $\rightarrow$ &  $1 \cdot U$\\
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   133
        & $|$ & $\epsilon$
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   134
\end{tabular}}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   135
\end{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   136
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   137
\end{frame}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   138
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   139
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   140
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   141
\begin{frame}[c]
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   142
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   143
Atomic parsers, for example
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   144
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   145
\begin{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   146
\bl{$1::rest \;\Rightarrow\; \{(1, rest)\}$} 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   147
\end{center}\bigskip
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   148
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   149
\begin{itemize}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   150
\item you consume one or more token from the\\ 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   151
  input (stream)
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   152
\item also works for characters and strings
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   153
\end{itemize}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   154
\end{frame}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   155
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   156
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   157
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   158
\begin{frame}[c]
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   159
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   160
Alternative parser (code \bl{$p\;||\;q$})\bigskip
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   161
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   162
\begin{itemize}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   163
\item apply \bl{$p$} and also \bl{$q$}; then combine 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   164
  the outputs
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   165
\end{itemize}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   166
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   167
\begin{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   168
\large \bl{$p(\text{input}) \cup q(\text{input})$}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   169
\end{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   170
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   171
\end{frame}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   172
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   173
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   174
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   175
\begin{frame}[c]
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   176
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   177
Sequence parser (code \bl{$p\sim q$})\bigskip
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   178
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   179
\begin{itemize}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   180
\item apply first \bl{$p$} producing a set of pairs
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   181
\item then apply \bl{$q$} to the unparsed parts
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   182
\item then combine the results:\medskip 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   183
\begin{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   184
((output$_1$, output$_2$), unparsed part)
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   185
\end{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   186
\end{itemize}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   187
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   188
\begin{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   189
\begin{tabular}{l}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   190
\large \bl{$\{((o_1, o_2), u_2) \;|\;$}\\[2mm] 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   191
\large\mbox{}\hspace{15mm} \bl{$(o_1, u_1) \in p(\text{input}) \wedge$}\\[2mm]
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   192
\large\mbox{}\hspace{15mm} \bl{$(o_2, u_2) \in q(u_1)\}$}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   193
\end{tabular}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   194
\end{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   195
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   196
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   197
\end{frame}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   198
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   199
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   200
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   201
\begin{frame}[c]
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   202
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   203
Function parser (code \bl{$p \Rightarrow f\;$})\bigskip
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   204
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   205
\begin{itemize}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   206
\item apply \bl{$p$} producing a set of pairs
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   207
\item then apply the function \bl{$f$} to each first component
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   208
\end{itemize}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   209
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   210
\begin{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   211
\begin{tabular}{l}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   212
\large \bl{$\{(f(o_1), u_1) \;|\; (o_1, u_1) \in p(\text{input})\}$}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   213
\end{tabular}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   214
\end{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   215
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   216
\end{frame}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   217
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   218
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   219
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   220
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   221
\begin{frame}[t]
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   222
\frametitle{Ambiguous Grammars}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   223
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   224
\begin{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   225
\begin{tikzpicture}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   226
\begin{axis}[xlabel={\pcode{1}s},ylabel={time in secs},
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   227
    enlargelimits=false,
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   228
    xtick={0,100,...,1000},
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   229
    xmax=1050,
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   230
    ymax=33,
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   231
    ytick={0,5,...,30},
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   232
    scaled ticks=false,
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   233
    axis lines=left,
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   234
    width=11cm,
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   235
    height=7cm, 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   236
    legend entries={unambiguous,ambiguous},  
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   237
    legend pos=north east,
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   238
    legend cell align=left,
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   239
    x tick label style={font=\small,/pgf/number format/1000 sep={}}]
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   240
\addplot[blue,mark=*, mark options={fill=white}] 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   241
  table {s-grammar1.data};
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   242
\only<2>{
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   243
  \addplot[red,mark=triangle*, mark options={fill=white}] 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   244
  table {s-grammar2.data};}  
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   245
\end{axis}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   246
\end{tikzpicture}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   247
\end{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   248
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   249
\end{frame}
295
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   250
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   251
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   252
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   253
\mode<presentation>{
295
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   254
\begin{frame}[c]
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   255
\frametitle{\begin{tabular}{c}Arithmetic Expressions\end{tabular}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   256
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   257
A grammar for arithmetic expressions and numbers:
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   258
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   259
\begin{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   260
\bl{\begin{tabular}{lcl}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   261
$E$ & $\rightarrow$ &  $E \cdot + \cdot E \;|\;E \cdot * \cdot E \;|\;( \cdot E \cdot ) \;|\;N$ \\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   262
$N$ & $\rightarrow$ & $N \cdot N \;|\; 0 \;|\; 1 \;|\: \ldots \;|\; 9$ 
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   263
\end{tabular}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   264
\end{center}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   265
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   266
Unfortunately it is left-recursive (and ambiguous).\medskip\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   267
A problem for \alert{recursive descent parsers} (e.g.~parser combinators).
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   268
\bigskip\pause
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   269
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   270
\end{frame}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   271
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   272
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   273
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   274
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   275
\mode<presentation>{
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   276
\begin{frame}[t]
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   277
\frametitle{\begin{tabular}{c}Numbers\end{tabular}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   278
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   279
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   280
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   281
\begin{center}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   282
\bl{\begin{tabular}{lcl}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   283
$N$ & $\rightarrow$ &  $N \cdot N \;|\; 0 \;|\; 1 \;|\; \ldots \;|\; 9$\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   284
\end{tabular}}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   285
\end{center}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   286
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   287
A non-left-recursive, non-ambiguous grammar for numbers:
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   288
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   289
\begin{center}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   290
\bl{\begin{tabular}{lcl}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   291
$N$ & $\rightarrow$ &  $0 \cdot N \;|\;1 \cdot N \;|\;\ldots\;|\; 0 \;|\; 1 \;|\; \ldots \;|\; 9$\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   292
\end{tabular}}
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   293
\end{center}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   294
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   295
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   296
\end{frame}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   297
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   298
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   299
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   300
\mode<presentation>{
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   301
\begin{frame}[c]
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   302
\frametitle{\begin{tabular}{c}Removing Left-Recursion\end{tabular}}
295
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   303
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   304
The rule for numbers is directly left-recursive:
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   305
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   306
\begin{center}
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   307
\bl{\begin{tabular}{lcl}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   308
$N$ & $\rightarrow$ & $N \cdot N \;|\; 0 \;|\; 1\;\;\;\;(\ldots)$ 
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   309
\end{tabular}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   310
\end{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   311
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   312
Translate
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   313
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   314
\begin{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   315
\begin{tabular}{ccc}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   316
\bl{\begin{tabular}{lcl}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   317
$N$ & $\rightarrow$ & $N \cdot \alpha$\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   318
 &  $\;|\;$ & $\beta$\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   319
 \\ 
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   320
\end{tabular}} 
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   321
& {\Large$\Rightarrow$} &
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   322
\bl{\begin{tabular}{lcl}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   323
$N$ & $\rightarrow$ & $\beta \cdot N'$\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   324
$N'$ & $\rightarrow$ & $\alpha \cdot N'$\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   325
 &  $\;|\;$ & $\epsilon$ 
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   326
\end{tabular}}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   327
\end{tabular}
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   328
\end{center}\pause
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   329
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   330
Which means
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   331
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   332
\begin{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   333
\bl{\begin{tabular}{lcl}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   334
$N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1 \cdot N'$\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   335
$N'$ & $\rightarrow$ & $N \cdot N' \;|\; \epsilon$\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   336
\end{tabular}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   337
\end{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   338
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   339
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   340
\end{frame}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   341
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   342
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   343
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   344
\mode<presentation>{
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   345
\begin{frame}[c]
366
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   346
\frametitle{\begin{tabular}{c}Operator Precedences\end{tabular}}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   347
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   348
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   349
To disambiguate
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   350
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   351
\begin{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   352
\bl{\begin{tabular}{lcl}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   353
$E$ & $\rightarrow$ &  $E \cdot + \cdot E \;|\;E \cdot * \cdot E \;|\;( \cdot E \cdot ) \;|\;N$ \\
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   354
\end{tabular}}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   355
\end{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   356
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   357
Decide on how many precedence levels, say\medskip\\
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   358
\hspace{5mm}highest for \bl{$()$}, medium for \bl{*}, lowest for \bl{+}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   359
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   360
\begin{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   361
\bl{\begin{tabular}{lcl}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   362
$E_{low}$ & $\rightarrow$ & $E_{med} \cdot + \cdot E_{low} \;|\; E_{med}$ \\
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   363
$E_{med}$ & $\rightarrow$ & $E_{hi} \cdot * \cdot E_{med} \;|\; E_{hi}$\\
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   364
$E_{hi}$ & $\rightarrow$ &  $( \cdot E_{low} \cdot ) \;|\;N$ \\
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   365
\end{tabular}}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   366
\end{center}\pause
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   367
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   368
\small What happens with \bl{$1 + 3  + 4$}?
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   369
\end{frame}}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   370
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   371
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   372
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   373
\mode<presentation>{
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   374
\begin{frame}[c]
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   375
\frametitle{\begin{tabular}{c}Chomsky Normal Form\end{tabular}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   376
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   377
All rules must be of the form
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   378
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   379
\begin{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   380
\bl{$A \rightarrow a$}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   381
\end{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   382
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   383
or
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   384
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   385
\begin{center}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   386
\bl{$A \rightarrow B\cdot C$}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   387
\end{center}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   388
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   389
No rule can contain \bl{$\epsilon$}.
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   390
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   391
\end{frame}}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   392
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   393
169
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
\begin{frame}[c]
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   396
\frametitle{\begin{tabular}{c}$\epsilon$-Removal\end{tabular}}
169
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
\begin{enumerate}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   399
\item If \bl{$A\rightarrow \alpha \cdot B \cdot \beta$} and \bl{$B \rightarrow \epsilon$} are in the grammar,
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   400
then add \bl{$A\rightarrow \alpha \cdot \beta$} (iterate if necessary).
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   401
\item Throw out all \bl{$B \rightarrow \epsilon$}.
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   402
\end{enumerate}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   403
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   404
\small
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   405
\begin{center}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   406
\begin{tabular}{ccc}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   407
\bl{\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   408
$N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1\cdot N'$\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   409
$N'$ & $\rightarrow$ & $N \cdot N'\;|\;\epsilon$\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   410
\\ 
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   411
\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   412
\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   413
\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   414
\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   415
\end{tabular}} &
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   416
\bl{\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   417
\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   418
$N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1\cdot N'\;|\;0\;|\;1$\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   419
$N'$ & $\rightarrow$ & $N \cdot N'\;|\;N\;|\;\epsilon$\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   420
\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   421
$N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1\cdot N'\;|\;0\;|\;1$\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   422
$N'$ & $\rightarrow$ & $N \cdot N'\;|\;N$\\
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   423
\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   424
\end{tabular}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   425
\end{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   426
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   427
\pause\normalsize
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   428
\begin{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   429
\bl{\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   430
$N$ & $\rightarrow$ & $0 \cdot N\;|\; 1\cdot N\;|\;0\;|\;1$\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   431
\end{tabular}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   432
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   433
\end{center}
368
a9911966c0df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 366
diff changeset
   434
\end{frame}
169
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
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   437
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   438
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   439
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   440
\mode<presentation>{
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   441
\begin{frame}[c]
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   442
\frametitle{\begin{tabular}{c}CYK Algorithm\end{tabular}}
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   443
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   444
If grammar is in Chomsky normalform \ldots
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   445
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   446
\begin{center}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   447
\bl{\begin{tabular}{@ {}lcl@ {}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   448
$S$ & $\rightarrow$ &  $N\cdot P$ \\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   449
$P$ & $\rightarrow$ &  $V\cdot N$ \\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   450
$N$ & $\rightarrow$ &  $N\cdot N$ \\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   451
$N$ & $\rightarrow$ &  $\texttt{students} \;|\; \texttt{Jeff} \;|\; \texttt{geometry} \;|\; \texttt{trains} $ \\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   452
$V$ & $\rightarrow$ &  $\texttt{trains}$ 
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   453
\end{tabular}}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   454
\end{center}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   455
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   456
\bl{\texttt{Jeff trains geometry students}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   457
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   458
\end{frame}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   459
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   460
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   461
\mode<presentation>{
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   462
\begin{frame}[c]
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   463
\frametitle{\begin{tabular}{c}CYK Algorithm\end{tabular}}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   464
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   465
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   466
\begin{itemize}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   467
\item fastest possible algorithm for recognition problem
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   468
\item runtime is \bl{$O(n^3)$}\bigskip
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   469
\item grammars need to be transferred into CNF
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   470
\end{itemize}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   471
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   472
\end{frame}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   473
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   474
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   475
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
366
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   476
\begin{frame}[c]
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   477
\frametitle{The Goal of this Course}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   478
\mbox{}\\[-26mm]\mbox{}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   479
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   480
\begin{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   481
  \begin{tikzpicture}[scale=1,
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   482
                      node/.style={
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   483
                      rectangle,rounded corners=3mm,
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   484
                      very thick,draw=black!50,
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   485
                      minimum height=18mm, minimum width=20mm,
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   486
                      top color=white,bottom color=black!20}]
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   487
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   488
  \node at (3.05, 1.8) {\Large\bf Write a Compiler};
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   489
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   490
  \node (0) at (-2.3,0) {}; 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   491
  
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   492
  \node (A) at (0,0)  [node] {};
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   493
  \node [below right] at (A.north west) {lexer};
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   494
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   495
  \node (B) at (3,0)  [node] {};
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   496
  \node [below right=1mm] at (B.north west) 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   497
    {\mbox{}\hspace{-1mm}parser};
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   498
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   499
  \node (C) at (6,0)  [node] {};
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   500
  \node [below right] at (C.north west) 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   501
    {\mbox{}\hspace{-1mm}code gen};
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   502
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   503
  \node (1) at (8.4,0) {}; 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   504
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   505
  \draw [->,line width=4mm] (0) -- (A); 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   506
  \draw [->,line width=4mm] (A) -- (B); 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   507
  \draw [->,line width=4mm] (B) -- (C); 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   508
  \draw [->,line width=4mm] (C) -- (1); 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   509
  \end{tikzpicture}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   510
  \end{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   511
  
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   512
We have lexer and parser.
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   513
  
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   514
\end{frame}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   515
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   516
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   517
\begin{frame}[c]
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
\begin{center}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   520
\bl{\begin{tabular}{@{}lcl@{}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   521
\textit{Stmt} & $\rightarrow$ &  $\texttt{skip}$\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   522
              & $|$ & \textit{Id}\;\texttt{:=}\;\textit{AExp}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   523
              & $|$ & \texttt{if}\; \textit{BExp} \;\texttt{then}\; \textit{Block} \;\texttt{else}\; \textit{Block}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   524
              & $|$ & \texttt{while}\; \textit{BExp} \;\texttt{do}\; \textit{Block}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   525
              & $|$ & \texttt{read}\;\textit{Id}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   526
              & $|$ & \texttt{write}\;\textit{Id}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   527
              & $|$ & \texttt{write}\;\textit{String}\medskip\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   528
\textit{Stmts} & $\rightarrow$ &  \textit{Stmt} \;\texttt{;}\; \textit{Stmts}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   529
              & $|$ & \textit{Stmt}\medskip\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   530
\textit{Block} & $\rightarrow$ &  \texttt{\{}\,\textit{Stmts}\,\texttt{\}}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   531
                & $|$ & \textit{Stmt}\medskip\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   532
\textit{AExp} & $\rightarrow$ & \ldots\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   533
\textit{BExp} & $\rightarrow$ & \ldots\\
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   534
\end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   535
\end{center}
366
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   536
\end{frame}
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   537
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   538
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   539
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   540
\mode<presentation>{
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   541
\begin{frame}[c]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   542
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   543
\mbox{\lstinputlisting[language=while]{../progs/fib.while}}
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   544
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   545
\end{frame}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   546
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   547
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   548
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   549
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   550
\mode<presentation>{
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   551
\begin{frame}[c]
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   552
\frametitle{\begin{tabular}{c}An Interpreter\end{tabular}}
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   553
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   554
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   555
\bl{\begin{tabular}{l}
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
\;\;$x := 5 \text{;}$\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   558
\;\;$y := x * 3\text{;}$\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   559
\;\;$y := x * 4\text{;}$\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   560
\;\;$x := u * 3$\\
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
\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   563
\end{center}
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
\begin{itemize}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   566
\item the interpreter has to record the value of \bl{$x$} before assigning a value to \bl{$y$}\pause
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   567
\item \bl{\text{eval}(stmt, env)}
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   568
\end{itemize}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   569
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   570
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   571
\end{frame}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   572
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   573
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   574
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   575
\mode<presentation>{
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   576
\begin{frame}[c]
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   577
\frametitle{\begin{tabular}{c}Interpreter\end{tabular}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   578
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   579
\begin{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   580
\bl{\begin{tabular}{@{}lcl@{}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   581
$\text{eval}(n, E)$ & $\dn$ & $n$\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   582
$\text{eval}(x, E)$ & $\dn$ & $E(x)$ \;\;\;\textcolor{black}{lookup \bl{$x$} in \bl{$E$}}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   583
$\text{eval}(a_1 + a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) + \text{eval}(a_2, E)$\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   584
$\text{eval}(a_1 - a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) - \text{eval}(a_2, E)$\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   585
$\text{eval}(a_1 * a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) * \text{eval}(a_2, E)$\bigskip\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   586
$\text{eval}(a_1 = a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) = \text{eval}(a_2, E)$\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   587
$\text{eval}(a_1\,!\!= a_2, E)$ & $\dn$ & $\neg(\text{eval}(a_1, E) = \text{eval}(a_2, E))$\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   588
$\text{eval}(a_1 < a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) < \text{eval}(a_2, E)$\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   589
\end{tabular}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   590
\end{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   591
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   592
\end{frame}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   593
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   594
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   595
\mode<presentation>{
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   596
\begin{frame}[c]
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   597
\frametitle{\begin{tabular}{c}Interpreter (2)\end{tabular}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   598
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   599
\begin{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   600
\bl{\begin{tabular}{@{}lcl@{}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   601
$\text{eval}(\text{skip}, E)$ & $\dn$ & $E$\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   602
$\text{eval}(x:=a, E)$ & $\dn$ & \bl{$E(x \mapsto \text{eval}(a, E))$}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   603
\multicolumn{3}{@{}l@{}}{$\text{eval}(\text{if}\;b\;\text{then}\;cs_1\;\text{else}\;cs_2 , E) \dn$}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   604
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)\;\text{then}\;
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   605
\text{eval}(cs_1,E)$}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   606
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\phantom{\text{if}\;\text{eval}(b,E)\;}\text{else}\;\text{eval}(cs_2,E)$}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   607
\multicolumn{3}{@{}l@{}}{$\text{eval}(\text{while}\;b\;\text{do}\;cs, E) \dn$}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   608
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)$}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   609
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{then}\;
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   610
\text{eval}(\text{while}\;b\;\text{do}\;cs, \text{eval}(cs,E))$}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   611
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{else}\; E$}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   612
$\text{eval}(\text{write}\; x, E)$ & $\dn$ & $\{\;\text{println}(E(x))\; ;\;E\;\}$\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   613
\end{tabular}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   614
\end{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   615
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   616
\end{frame}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   617
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   618
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   619
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   620
\begin{frame}[c]
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   621
\frametitle{\begin{tabular}{c}Test Program\end{tabular}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   622
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   623
\mbox{}\\[-18mm]\mbox{}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   624
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   625
{\lstset{language=While}%%\fontsize{10}{12}\selectfont
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   626
\texttt{\lstinputlisting{../progs/loops.while}}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   627
295
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   628
\end{frame}
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   629
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   630
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   631
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   632
\mode<presentation>{
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   633
\begin{frame}[t]
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   634
\frametitle{\begin{tabular}{c}Interpreted Code\end{tabular}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   635
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   636
\begin{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   637
\begin{tikzpicture}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   638
\begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small]
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   639
\addplot+[smooth] file {interpreted.data};
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   640
\end{axis}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   641
\end{tikzpicture}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   642
\end{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   643
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   644
\end{frame}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   645
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   646
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   647
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   648
\mode<presentation>{
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   649
\begin{frame}[c]
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   650
\frametitle{\begin{tabular}{c}Java Virtual Machine\end{tabular}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   651
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   652
\begin{itemize}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   653
\item introduced in 1995
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   654
\item is a stack-based VM (like Postscript, CLR of .Net)
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   655
\item contains a JIT compiler
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   656
\item many languages take advantage of JVM's infrastructure (JRE)
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   657
\item is garbage collected $\Rightarrow$ no buffer overflows
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   658
\item some languages compile to the JVM: Scala, Clojure\ldots
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   659
\end{itemize}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   660
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   661
\end{frame}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   662
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   663
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   664
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   665
\end{document}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   666
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   667
%%% Local Variables:  
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   668
%%% mode: latex
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   669
%%% TeX-master: t
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   670
%%% End: 
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   671