slides/slides06.tex
author Christian Urban <christian.urban@kcl.ac.uk>
Mon, 30 Aug 2021 14:38:24 +0100
changeset 827 67c8a6e6a305
parent 809 2b9956d29038
child 849 3d5ecb8f1f2f
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
666
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
     1
% !TEX program = xelatex
744
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
     2
\documentclass[dvipsnames,14pt,t,xelatex,aspectratio=169,xcolor={table}]{beamer}
295
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
     3
\usepackage{../slides}
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
     4
\usepackage{../graphics}
215
828303e8e4af updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
     5
\usepackage{../langs}
828303e8e4af updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
     6
\usepackage{../data}
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
     7
\usepackage{../grammar}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
% beamer stuff 
445
e7d0157f0471 updated slides
Christian Urban <urbanc@in.tum.de>
parents: 368
diff changeset
    10
\renewcommand{\slidecaption}{CFL 06, King's College London}
e7d0157f0471 updated slides
Christian Urban <urbanc@in.tum.de>
parents: 368
diff changeset
    11
e7d0157f0471 updated slides
Christian Urban <urbanc@in.tum.de>
parents: 368
diff changeset
    12
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    13
\newcommand{\bl}[1]{\textcolor{blue}{#1}}       
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
    14
%\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
    15
\newcommand{\qq}{\mbox{\texttt{"}}}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
809
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
    17
\usepackage{tcolorbox}
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
    18
\newtcolorbox{mybox}{colback=red!5!white,colframe=red!75!black}
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
    19
\newtcolorbox{mybox2}[1]{colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries,title=#1}
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
    20
\newtcolorbox{mybox3}[1]{colback=Cyan!5!white,colframe=Cyan!75!black,fonttitle=\bfseries,title=#1}
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
    21
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
    22
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
    23
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
\begin{document}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
295
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    27
\begin{frame}[t]
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
\frametitle{%
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
  \begin{tabular}{@ {}c@ {}}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
  \\[-3mm]
445
e7d0157f0471 updated slides
Christian Urban <urbanc@in.tum.de>
parents: 368
diff changeset
    31
  \LARGE Compilers and \\[-2mm] 
744
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    32
  \LARGE Formal Languages\\[3mm] 
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
  \end{tabular}}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
  \normalsize
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
  \begin{center}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
  \begin{tabular}{ll}
683
c6c79d21f8a8 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
    38
    Email:  & christian.urban at kcl.ac.uk\\
744
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    39
    %Office Hours: & Thursdays 12 -- 14\\
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    40
    %Location: & N7.07 (North Wing, Bush House)\\
683
c6c79d21f8a8 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
    41
    Slides \& Progs: & KEATS (also homework is there)\\  
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
  \end{tabular}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
  \end{center}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
744
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    45
  \begin{center}
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    46
    \begin{tikzpicture}
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    47
      \node[drop shadow,fill=white,inner sep=0pt] 
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    48
      {\footnotesize\rowcolors{1}{capri!10}{white}
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    49
        \begin{tabular}{|p{4.8cm}|p{4.8cm}|}\hline
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    50
          1 Introduction, Languages          & \cellcolor{blue!50} 6 While-Language \\
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    51
          2 Regular Expressions, Derivatives & 7 Compilation, JVM \\
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    52
          3 Automata, Regular Languages      & 8 Compiling Functional Languages \\
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    53
          4 Lexing, Tokenising               & 9 Optimisations \\
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    54
          5 Grammars, Parsing                & 10 LLVM \\ \hline
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    55
        \end{tabular}%
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    56
      };
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    57
    \end{tikzpicture}
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    58
  \end{center}
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    59
  
295
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    60
\end{frame}
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    61
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
799
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    63
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    64
\begin{frame}[c]
803
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
    65
%%\frametitle{Test Program}
799
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    66
803
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
    67
\mbox{}\\[-18mm]\mbox{}
799
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    68
803
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
    69
{\lstset{language=While}%%\fontsize{10}{12}\selectfont
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
    70
\texttt{\lstinputlisting{../progs/while-tests/loops.while}}}
799
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    71
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    72
\end{frame}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    73
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    74
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    75
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    76
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    77
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    78
\begin{frame}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    79
\frametitle{While-Language}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    80
\mbox{}\\[-23mm]\mbox{}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    81
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    82
\bl{\begin{plstx}[rhs style=,one per line]: \meta{Stmt} ::= skip
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    83
         | \meta{Id} := \meta{AExp}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    84
         | if \meta{BExp} then \meta{Block} else \meta{Block}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    85
         | while \meta{BExp} do \meta{Block}\\
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    86
: \meta{Stmts} ::= \meta{Stmt} ; \meta{Stmts}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    87
          | \meta{Stmt}\\
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    88
: \meta{Block} ::= \{ \meta{Stmts} \}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    89
          | \meta{Stmt}\\
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    90
: \meta{AExp} ::= \ldots\\
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    91
: \meta{BExp} ::= \ldots\\\end{plstx}}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    92
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    93
\end{frame}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    94
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    95
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    96
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
803
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
    97
\mode<presentation>{
799
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
    98
\begin{frame}[c]
803
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
    99
\frametitle{\begin{tabular}{c}Aexps\end{tabular}}
799
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   100
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   101
\begin{center}
803
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   102
\bl{\begin{tabular}{@{}lcl@{}}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   103
$\text{eval}(n)$ & $\dn$ & $n$\\
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   104
$\text{eval}(a_1 + a_2)$ & $\dn$ & $\text{eval}(a_1) + \text{eval}(a_2)$\\
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   105
$\text{eval}(a_1 - a_2)$ & $\dn$ & $\text{eval}(a_1) - \text{eval}(a_2)$\\
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   106
$\text{eval}(a_1 * a_2)$ & $\dn$ & $\text{eval}(a_1) * \text{eval}(a_2)$\bigskip\\
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   107
$\text{eval}(x)$ & $\dn$ & $???$\\
799
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   108
\end{tabular}}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   109
\end{center}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   110
803
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   111
\end{frame}}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   112
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
799
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   113
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   114
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   115
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   116
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   117
\mode<presentation>{
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   118
\begin{frame}[c]
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   119
\frametitle{\begin{tabular}{c}Interpreter\end{tabular}}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   120
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   121
\begin{center}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   122
\bl{\begin{tabular}{@{}lcl@{}}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   123
$\text{eval}(n, E)$ & $\dn$ & $n$\\
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   124
$\text{eval}(x, E)$ & $\dn$ & $E(x)$ \;\;\;\textcolor{black}{lookup \bl{$x$} in \bl{$E$}}\\
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   125
$\text{eval}(a_1 + a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) + \text{eval}(a_2, E)$\\
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   126
$\text{eval}(a_1 - a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) - \text{eval}(a_2, E)$\\
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   127
$\text{eval}(a_1 * a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) * \text{eval}(a_2, E)$\bigskip\\
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   128
$\text{eval}(a_1 = a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) = \text{eval}(a_2, E)$\\
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   129
$\text{eval}(a_1\,!\!= a_2, E)$ & $\dn$ & $\neg(\text{eval}(a_1, E) = \text{eval}(a_2, E))$\\
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   130
$\text{eval}(a_1 < a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) < \text{eval}(a_2, E)$\
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   131
\end{tabular}}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   132
\end{center}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   133
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   134
\end{frame}}
803
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   135
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   136
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   137
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   138
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   139
\begin{frame}[c]
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   140
\frametitle{An Interpreter (1)}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   141
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   142
\begin{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   143
\bl{\begin{tabular}{l}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   144
$\{$\\
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   145
\;\;$x := 5 \text{;}$\\
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   146
\;\;$y := x * 3\text{;}$\\
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   147
\;\;$y := x * 4\text{;}$\\
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   148
\;\;$x := u * 3$\\
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   149
$\}$
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   150
\end{tabular}}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   151
\end{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   152
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   153
\begin{itemize}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   154
\item the interpreter has to record the value of \bl{$x$} before assigning a value to \bl{$y$}\pause
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   155
\item \bl{\texttt{eval(stmt, env)}}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   156
\end{itemize}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   157
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   158
\end{frame}
799
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   159
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
803
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   160
799
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   161
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   162
\mode<presentation>{
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   163
\begin{frame}[c]
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   164
\frametitle{\begin{tabular}{c}Interpreter (2)\end{tabular}}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   165
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   166
\begin{center}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   167
\bl{\begin{tabular}{@{}lcl@{}}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   168
$\text{eval}(\text{skip}, E)$ & $\dn$ & $E$\\
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   169
$\text{eval}(x:=a, E)$ & $\dn$ & \bl{$E(x \mapsto \text{eval}(a, E))$}\\
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   170
\multicolumn{3}{@{}l@{}}{$\text{eval}(\text{if}\;b\;\text{then}\;cs_1\;\text{else}\;cs_2 , E) \dn$}\\
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   171
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)\;\text{then}\;
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   172
\text{eval}(cs_1,E)$}\\
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   173
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\phantom{\text{if}\;\text{eval}(b,E)\;}\text{else}\;\text{eval}(cs_2,E)$}\\
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   174
\multicolumn{3}{@{}l@{}}{$\text{eval}(\text{while}\;b\;\text{do}\;cs, E) \dn$}\\
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   175
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)$}\\
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   176
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{then}\;
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   177
\text{eval}(\text{while}\;b\;\text{do}\;cs, \text{eval}(cs,E))$}\\
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   178
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{else}\; E$}\\
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   179
$\text{eval}(\text{write}\; x, E)$ & $\dn$ & $\{\;\text{println}(E(x))\; ;\;E\;\}$\\
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   180
\end{tabular}}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   181
\end{center}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   182
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   183
\end{frame}}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   184
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   185
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   186
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   187
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   188
\mode<presentation>{
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   189
\begin{frame}[t]
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   190
\frametitle{\begin{tabular}{c}Interpreted Code\end{tabular}}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   191
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   192
\begin{center}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   193
\begin{tikzpicture}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   194
\begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small]
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   195
\addplot+[smooth] file {interpreted.data};
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   196
\end{axis}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   197
\end{tikzpicture}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   198
\end{center}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   199
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   200
\end{frame}}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   201
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   202
809
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
   203
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
   204
\begin{frame}[t,fragile]
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
   205
\begin{mybox3}{}
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
   206
   In CW3, in the collatz program there is the line write "$\backslash$n" Should this print "/n" or perform the new line command /n ? Also should write be print() or println() ?
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
   207
\end{mybox3}
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
   208
\end{frame}
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
   209
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
   210
\begin{frame}[t]
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
   211
  \begin{mybox3}{}
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
   212
  When will we have the mid-term that was originally scheduled for last week? We haven't heard anything about it for 2 weeks.  
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
   213
\end{mybox3}
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
   214
\end{frame}
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
   215
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
   216
\begin{frame}<1-12>[c]
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
   217
\end{frame}
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
   218
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
   219
803
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   220
\end{document}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   221
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   222
799
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   223
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   224
\mode<presentation>{
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   225
\begin{frame}[c]
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   226
\frametitle{\begin{tabular}{c}Java Virtual Machine\end{tabular}}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   227
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   228
\begin{itemize}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   229
\item introduced in 1995
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   230
\item is a stack-based VM (like Postscript, CLR of .Net)
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   231
\item contains a JIT compiler
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   232
\item many languages take advantage of JVM's infrastructure (JRE)
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   233
\item is garbage collected $\Rightarrow$ no buffer overflows
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   234
\item some languages compile to the JVM: Scala, Clojure\ldots
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   235
\end{itemize}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   236
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   237
\end{frame}}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   238
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   239
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   240
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   241
803
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   242
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   243
% \begin{frame}[t]
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   244
% \frametitle{%
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   245
%   \begin{tabular}{@ {}c@ {}}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   246
%   \\[-3mm]
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   247
%   \LARGE Compilers and \\[-2mm] 
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   248
%   \LARGE Formal Languages\\[3mm] 
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   249
%   \end{tabular}}
799
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   250
803
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   251
%   \normalsize
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   252
%   \begin{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   253
%   \begin{tabular}{ll}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   254
%     Email:  & christian.urban at kcl.ac.uk\\
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   255
%     %Office Hours: & Thursdays 12 -- 14\\
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   256
%     %Location: & N7.07 (North Wing, Bush House)\\
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   257
%     Slides \& Progs: & KEATS (also homework is there)\\  
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   258
%   \end{tabular}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   259
%   \end{center}
799
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   260
803
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   261
%   \begin{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   262
%     \begin{tikzpicture}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   263
%       \node[drop shadow,fill=white,inner sep=0pt] 
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   264
%       {\footnotesize\rowcolors{1}{capri!10}{white}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   265
%         \begin{tabular}{|p{4.8cm}|p{4.8cm}|}\hline
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   266
%           1 Introduction, Languages          & \cellcolor{blue!50} 6 While-Language \\
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   267
%           2 Regular Expressions, Derivatives & 7 Compilation, JVM \\
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   268
%           3 Automata, Regular Languages      & 8 Compiling Functional Languages \\
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   269
%           4 Lexing, Tokenising               & 9 Optimisations \\
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   270
%           5 Grammars, Parsing                & 10 LLVM \\ \hline
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   271
%         \end{tabular}%
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   272
%       };
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   273
%     \end{tikzpicture}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   274
%   \end{center}
799
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   275
  
803
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   276
% \end{frame}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   277
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
799
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   278
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   279
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 750
diff changeset
   280
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
531
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   281
% \begin{frame}[c]
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   282
% \small
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   283
% \mbox{}\\[5mm]
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   284
% %\begin{textblock}{10}(3,5)
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   285
% \begin{tikzpicture}[scale=1.5,
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   286
%                     node distance=1cm,
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   287
%                     every node/.style={minimum size=7mm}]
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   288
% \node (r1)  {\bl{$r_1$}};
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   289
% \node (r2) [right=of r1] {\bl{$r_2$}};
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   290
% \draw[->,line width=1mm]  (r1) -- (r2) node[above,midway] {\bl{$der\,a$}};
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   291
% \node (r3) [right=of r2] {\bl{$r_3$}};
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   292
% \draw[->,line width=1mm]  (r2) -- (r3) node[above,midway] {\bl{$der\,b$}};
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   293
% \node (r4) [right=of r3] {\bl{$r_4$}};
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   294
% \draw[->,line width=1mm]  (r3) -- (r4) node[above,midway] {\bl{$der\,c$}};
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   295
% \draw (r4) node[anchor=west] {\;\raisebox{3mm}{\bl{$nullable$}}};
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   296
% \node (v4) [below=of r4] {\bl{$v_4$}};
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   297
% \draw[->,line width=1mm]  (r4) -- (v4);
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   298
% \node (v3) [left=of v4] {\bl{$v_3$}};
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   299
% \draw[->,line width=1mm]  (v4) -- (v3) node[below,midway] {\bl{$inj\,c$}};
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   300
% \node (v2) [left=of v3] {\bl{$v_2$}};
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   301
% \draw[->,line width=1mm]  (v3) -- (v2) node[below,midway] {\bl{$inj\,b$}};
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   302
% \node (v1) [left=of v2] {\bl{$v_1$}};
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   303
% \draw[->,line width=1mm]  (v2) -- (v1) node[below,midway] {\bl{$inj\,a$}};
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   304
% \draw[->,line width=0.5mm]  (r3) -- (v3);
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   305
% \draw[->,line width=0.5mm]  (r2) -- (v2);
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   306
% \draw[->,line width=0.5mm]  (r1) -- (v1);
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   307
% \draw (r4) node[anchor=north west] {\;\raisebox{-8mm}{\bl{$mkeps$}}};
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   308
% \end{tikzpicture}
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   309
% %\end{textblock}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   310
531
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   311
% \begin{center}
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   312
% \begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   313
%   \\[-10mm]
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   314
%   \bl{$inj\,(c)\,c\,Empty$} & \bl{$\dn$}  & \bl{$Char\,c$}\\
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   315
%   \bl{$inj\,(r_1 + r_2)\,c\,Left(v)$} & \bl{$\dn$}  & \bl{$Left(inj\,r_1\,c\,v)$}\\
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   316
%   \bl{$inj\,(r_1 + r_2)\,c\,Right(v)$} & \bl{$\dn$}  & \bl{$Right(inj\,r_2\,c\,v)$}\\
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   317
%   \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)$}\\
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   318
%   \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)$}\\
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   319
%   \bl{$inj\,(r_1 \cdot r_2)\,c\,Right(v)$} & \bl{$\dn$}  & \bl{$Seq(mkeps(r_1),inj\,r_2\,c\,v)$}\\
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   320
%   \bl{$inj\,(r^*)\,c\,Seq(v,vs)$} & \bl{$\dn$}  & \bl{$inj\,r\,c\,v\,::\,vs$}\\
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   321
% \end{tabular}
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   322
% \end{center}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   323
531
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   324
% \end{frame}
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   325
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   326
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   327
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
683
c6c79d21f8a8 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
   328
\begin{frame}[t]
c6c79d21f8a8 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
   329
\frametitle{Starting Symbol}
c6c79d21f8a8 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
   330
c6c79d21f8a8 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
   331
\bl{\begin{plstx}[margin=1cm]
c6c79d21f8a8 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
   332
  : \meta{S} ::= \meta{A}\cdot\meta{S}\cdot\meta{B} |
c6c79d21f8a8 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
   333
                 \meta{B}\cdot\meta{S}\cdot\meta{A} | \epsilon\\
c6c79d21f8a8 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
   334
  : \meta{A} ::= a | \epsilon\\
c6c79d21f8a8 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
   335
  : \meta{B} ::= b\\  
c6c79d21f8a8 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
   336
\end{plstx}}
c6c79d21f8a8 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
   337
750
e93a9e74ca8e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   338
e93a9e74ca8e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   339
TODO: Testcases for math expressions
e93a9e74ca8e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   340
\url{https://github.com/ArashPartow/math-parser-benchmark-project}
e93a9e74ca8e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   341
683
c6c79d21f8a8 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
   342
\end{frame}
c6c79d21f8a8 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
   343
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
c6c79d21f8a8 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
   344
c6c79d21f8a8 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
   345
c6c79d21f8a8 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
   346
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   347
\begin{frame}[c]
683
c6c79d21f8a8 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
   348
\frametitle{Hierarchy of Languages}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   349
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   350
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
   351
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   352
\begin{center}
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   353
\begin{tikzpicture}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   354
[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
   355
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   356
\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
   357
\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
   358
\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
   359
\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
   360
\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
   361
\end{tikzpicture}
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   362
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   363
\end{center}
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   364
366
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   365
\end{frame}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   366
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   367
531
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   368
   
366
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   369
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
\begin{frame}[c]
598
e3ad67cd5123 updated
Christian Urban <urbanc@in.tum.de>
parents: 597
diff changeset
   372
\frametitle{Parser Combinators}
e3ad67cd5123 updated
Christian Urban <urbanc@in.tum.de>
parents: 597
diff changeset
   373
  
366
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   374
Atomic parsers, for example
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   375
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   376
\begin{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   377
\bl{$1::rest \;\Rightarrow\; \{(1, rest)\}$} 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   378
\end{center}\bigskip
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   379
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   380
\begin{itemize}
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   381
\item you consume one or more tokens from the\\ 
366
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   382
  input (stream)
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   383
\item also works for characters and strings
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   384
\end{itemize}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   385
\end{frame}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   386
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   387
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   388
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   389
\begin{frame}[c]
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   390
686
05cfce0fdef7 updated
Christian Urban <urbanc@in.tum.de>
parents: 685
diff changeset
   391
Alternative parser (code \bl{$p\;|\;q$})\bigskip
366
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   392
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   393
\begin{itemize}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   394
\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
   395
  the outputs
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   396
\end{itemize}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   397
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   398
\begin{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   399
\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
   400
\end{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   401
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   402
\end{frame}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   403
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   404
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   405
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   406
\begin{frame}[c]
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   407
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   408
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
   409
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   410
\begin{itemize}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   411
\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
   412
\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
   413
\item then combine the results:\medskip 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   414
\begin{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   415
((output$_1$, output$_2$), unparsed part)
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   416
\end{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   417
\end{itemize}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   418
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   419
\begin{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   420
\begin{tabular}{l}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   421
\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
   422
\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
   423
\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
   424
\end{tabular}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   425
\end{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   426
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   427
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   428
\end{frame}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   429
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   430
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   431
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   432
\begin{frame}[c]
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   433
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   434
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
   435
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   436
\begin{itemize}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   437
\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
   438
\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
   439
\end{itemize}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   440
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   441
\begin{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   442
\begin{tabular}{l}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   443
\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
   444
\end{tabular}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   445
\end{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   446
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   447
\end{frame}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   448
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   449
531
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   450
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   451
\begin{frame}[c]
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   452
\frametitle{Types of Parsers}
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   453
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   454
\begin{itemize}
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   455
\item {\bf Sequencing}: if \bl{$p$} returns results of type \bl{$T$}, and \bl{$q$} results of type \bl{$S$},
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   456
then \bl{$p \sim q$} returns results of type
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   457
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   458
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   459
\bl{$T \times S$}
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   460
\end{center}\pause
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   461
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   462
\item {\bf Alternative}: if \bl{$p$} returns results of type \bl{$T$} then  \bl{$q$} \alert{must} also have results of type \bl{$T$},
686
05cfce0fdef7 updated
Christian Urban <urbanc@in.tum.de>
parents: 685
diff changeset
   463
and \bl{$p \;|\; q$} returns results of type
531
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   464
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   465
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   466
\bl{$T$}
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   467
\end{center}\pause
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   468
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   469
\item {\bf Semantic Action}: if \bl{$p$} returns results of type \bl{$T$} and \bl{$f$} is a function from
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   470
\bl{$T$} to \bl{$S$}, then
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   471
\bl{$p \Rightarrow f$} returns results of type
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   472
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   473
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   474
\bl{$S$}
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   475
\end{center}
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   476
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   477
\end{itemize}
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   478
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   479
\end{frame}
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   480
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   481
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   482
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   483
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   484
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   485
\begin{frame}[c]
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   486
\frametitle{Two Grammars}
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   487
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   488
Which languages are recognised by the following two grammars?
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   489
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   490
\bl{\begin{plstx}[margin=3cm]
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   491
: \meta{S} ::= \liningnums{1}\cdot\meta{S}\cdot \meta{S} | \epsilon\\
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   492
\end{plstx}}
531
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   493
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   494
\bl{\begin{plstx}[margin=3cm]
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   495
: \meta{U} ::= \liningnums{1}\cdot\meta{U} | \epsilon\\
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   496
\end{plstx}}
531
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   497
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   498
\end{frame}
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
   499
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
366
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   500
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   501
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   502
\begin{frame}[t]
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   503
\frametitle{Ambiguous Grammars}
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
\begin{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   506
\begin{tikzpicture}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   507
\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
   508
    enlargelimits=false,
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   509
    xtick={0,100,...,1000},
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   510
    xmax=1050,
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   511
    ymax=33,
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   512
    ytick={0,5,...,30},
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   513
    scaled ticks=false,
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   514
    axis lines=left,
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   515
    width=11cm,
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   516
    height=7cm, 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   517
    legend entries={unambiguous,ambiguous},  
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   518
    legend pos=north east,
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   519
    legend cell align=left,
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   520
    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
   521
\addplot[blue,mark=*, mark options={fill=white}] 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   522
  table {s-grammar1.data};
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   523
\only<2>{
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   524
  \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
   525
  table {s-grammar2.data};}  
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   526
\end{axis}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   527
\end{tikzpicture}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   528
\end{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   529
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   530
\end{frame}
295
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   531
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   532
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   533
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   534
\begin{frame}[c]
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   535
\frametitle{Arithmetic Expressions}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   536
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   537
A grammar for arithmetic expressions and numbers:
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   538
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   539
\bl{\begin{plstx}[margin=1cm]
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   540
    : \meta{E} ::= \meta{E} \cdot + \cdot \meta{E}
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   541
    | \meta{E} \cdot * \cdot \meta{E}
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   542
    | ( \cdot \meta{E} \cdot )  | \meta{N}\\
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   543
    : \meta{N} ::= \meta{N} \cdot \meta{N} |
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   544
    0 | 1 | \ldots | 9\\
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   545
\end{plstx}}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   546
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   547
Unfortunately it is left-recursive (and ambiguous).\medskip\\
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   548
A problem for \alert{recursive descent parsers} (e.g.~parser
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   549
combinators).  \bigskip\pause
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   550
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   551
\end{frame}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   552
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   553
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   554
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   555
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   556
\begin{frame}[t]
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   557
\frametitle{Numbers}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   558
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   559
\bl{\begin{plstx}[margin=1cm]
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   560
    : \meta{N} ::= \meta{N} \cdot \meta{N} |
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   561
    0 | 1 | \ldots | 9\\
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   562
\end{plstx}}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   563
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   564
A non-left-recursive, non-ambiguous grammar for numbers:
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   565
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   566
\bl{\begin{plstx}[margin=1cm]
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   567
    : \meta{N} ::= 0 \cdot \meta{N} | 1 \cdot \meta{N} | \ldots |
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   568
    0 | 1 | \ldots | 9\\
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   569
\end{plstx}}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   570
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   571
\end{frame}
365
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
\begin{frame}[c]
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   576
\frametitle{Removing Left-Recursion}
295
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   577
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   578
The rule for numbers is directly left-recursive:
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   579
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   580
\begin{center}
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   581
\bl{\begin{tabular}{lcl}
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   582
$\meta{N}$ & $::=$ & $\meta{N} \cdot \meta{N} \;|\; 0 \;|\; 1\;\;\;\;(\ldots)$ 
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   583
\end{tabular}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   584
\end{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   585
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   586
Translate
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   587
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   588
\begin{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   589
\begin{tabular}{ccc}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   590
\bl{\begin{tabular}{lcl}
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   591
$\meta{N}$ & $::=$ & $\meta{N} \cdot \alpha$\\
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   592
 &  $\;|\;$ & $\beta$\\
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
\end{tabular}} 
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   595
& {\Large$\Rightarrow$} &
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   596
\bl{\begin{tabular}{lcl}
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   597
$\meta{N}$ & $::=$ & $\beta \cdot \meta{N}'$\\
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   598
$\meta{N}'$ & $::=$ & $\alpha \cdot \meta{N}'$\\
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   599
 &  $\;|\;$ & $\epsilon$ 
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   600
\end{tabular}}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   601
\end{tabular}
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   602
\end{center}\pause
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   603
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   604
Which means in this case:
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   605
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   606
\begin{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   607
\bl{\begin{tabular}{lcl}
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   608
$\meta{N}$ & $\rightarrow$ & $0 \cdot \meta{N}' \;|\; 1 \cdot \meta{N}'$\\
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   609
$\meta{N}'$ & $\rightarrow$ & $\meta{N} \cdot \meta{N}' \;|\; \epsilon$\\
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   610
\end{tabular}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   611
\end{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   612
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   613
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   614
\end{frame}
365
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
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   617
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
685
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   618
%\begin{frame}[c]
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   619
%\frametitle{Operator Precedences}
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   620
%
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   621
%
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   622
%To disambiguate
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   623
%
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   624
%\begin{center}
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   625
%\bl{\begin{tabular}{lcl}
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   626
%$\meta{E}$ & $::=$ &  $\meta{E} \cdot + \cdot \meta{E} \;|\;\meta{E} \cdot * \cdot \meta{E} \;|\;( \cdot \meta{E} \cdot ) \;|\;\meta{N}$ \\
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   627
%\end{tabular}}
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   628
%\end{center}
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   629
%
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   630
%Decide on how many precedence levels, say\medskip\\
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   631
%highest for \bl{$()$}, medium for \bl{*}, lowest for \bl{+}
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   632
%
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   633
%\begin{center}
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   634
%\bl{\begin{tabular}{lcl}
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   635
%$\meta{E}_{low}$ & $::=$ & $\meta{E}_{med} \cdot + \cdot \meta{E}_{low} \;|\; \meta{E}_{med}$ \\
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   636
%$\meta{E}_{med}$ & $::=$ & $\meta{E}_{hi} \cdot * \cdot \meta{E}_{med} \;|\; \meta{E}_{hi}$\\
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   637
%$\meta{E}_{hi}$ & $::=$ &  $( \cdot \meta{E}_{low} \cdot ) \;|\;\meta{N}$ \\
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   638
%\end{tabular}}
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   639
%\end{center}\pause
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   640
%
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   641
%\small What happens with \bl{$1 + 3  + 4$}?
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   642
%\end{frame}
366
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   643
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   644
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   645
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   646
\begin{frame}[c]
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   647
\frametitle{Chomsky Normal Form}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   648
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   649
All rules must be of the form
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   650
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   651
\begin{center}
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   652
\bl{$\meta{A} ::= a$}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   653
\end{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   654
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   655
or
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   656
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   657
\begin{center}
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   658
\bl{$\meta{A} ::= \meta{B}\cdot \meta{C}$}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   659
\end{center}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   660
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   661
No rule can contain \bl{$\epsilon$}.
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   662
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   663
\end{frame}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   664
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   665
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   666
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   667
\begin{frame}[c]
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   668
\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
   669
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   670
\begin{enumerate}
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   671
\item If \bl{$A::= \alpha \cdot B \cdot \beta$} and \bl{$B ::= \epsilon$} are in the grammar,
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   672
then add \bl{$A::= \alpha \cdot \beta$} (iterate if necessary).
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   673
\item Throw out all \bl{$B ::= \epsilon$}.
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   674
\end{enumerate}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   675
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   676
\small
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   677
\begin{center}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   678
\begin{tabular}{ccc}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   679
\bl{\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   680
$N$ & $::=$ & $0 \cdot N' \;|\; 1\cdot N'$\\
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   681
$N'$ & $::=$ & $N \cdot N'\;|\;\epsilon$\\
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   682
\\ 
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   683
\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   684
\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   685
\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   686
\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   687
\end{tabular}} &
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   688
\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
   689
\\
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   690
$N$ & $::=$ & $0 \cdot N' \;|\; 1\cdot N'\;|\;0\;|\;1$\\
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   691
$N'$ & $::=$ & $N \cdot N'\;|\;N\;|\;\epsilon$\\
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   692
\\
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   693
$N$ & $::=$ & $0 \cdot N' \;|\; 1\cdot N'\;|\;0\;|\;1$\\
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   694
$N'$ & $::=$ & $N \cdot N'\;|\;N$\\
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   695
\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   696
\end{tabular}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   697
\end{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   698
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   699
\pause\normalsize
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   700
\begin{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   701
\bl{\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   702
$N$ & $::=$ & $0 \cdot N\;|\; 1\cdot N\;|\;0\;|\;1$\\
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   703
\end{tabular}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   704
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   705
\end{center}
368
a9911966c0df updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 366
diff changeset
   706
\end{frame}
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   707
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   708
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   709
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   710
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   711
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   712
\begin{frame}[c]
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   713
\frametitle{CYK Algorithm}
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   714
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   715
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
   716
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   717
\begin{center}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   718
\bl{\begin{tabular}{@ {}lcl@ {}}
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   719
$\meta{S}$ & $::=$ &  $\meta{N}\cdot \meta{P}$ \\
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   720
$\meta{P}$ & $::=$ &  $\meta{V}\cdot \meta{N}$ \\
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   721
$\meta{N}$ & $::=$ &  $\meta{N}\cdot \meta{N}$ \\
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   722
$\meta{N}$ & $::=$ &  $\texttt{students} \;|\; \texttt{Jeff} \;|\; \texttt{geometry} \;|\; \texttt{trains} $ \\
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   723
$\meta{V}$ & $::=$ &  $\texttt{trains}$ 
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   724
\end{tabular}}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   725
\end{center}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   726
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   727
\bl{\texttt{Jeff trains geometry students}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   728
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   729
\end{frame}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   730
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   731
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   732
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   733
\begin{frame}[c]
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   734
\frametitle{CYK Algorithm}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   735
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   736
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   737
\begin{itemize}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   738
\item fastest possible algorithm for recognition problem
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   739
\item runtime is \bl{$O(n^3)$}\bigskip
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   740
\item grammars need to be transformed into CNF
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   741
\end{itemize}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   742
597
ce8419e3915c updated
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   743
\end{frame}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   744
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   745
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   746
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
366
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   747
\begin{frame}[c]
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   748
\frametitle{The Goal of this Course}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   749
\mbox{}\\[-26mm]\mbox{}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   750
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   751
\begin{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   752
  \begin{tikzpicture}[scale=1,
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   753
                      node/.style={
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   754
                      rectangle,rounded corners=3mm,
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   755
                      very thick,draw=black!50,
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   756
                      minimum height=18mm, minimum width=20mm,
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   757
                      top color=white,bottom color=black!20}]
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   758
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   759
  \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
   760
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   761
  \node (0) at (-2.3,0) {}; 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   762
  
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   763
  \node (A) at (0,0)  [node] {};
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   764
  \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
   765
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   766
  \node (B) at (3,0)  [node] {};
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   767
  \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
   768
    {\mbox{}\hspace{-1mm}parser};
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   769
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   770
  \node (C) at (6,0)  [node] {};
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   771
  \node [below right] at (C.north west) 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   772
    {\mbox{}\hspace{-1mm}code gen};
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   773
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   774
  \node (1) at (8.4,0) {}; 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   775
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   776
  \draw [->,line width=4mm] (0) -- (A); 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   777
  \draw [->,line width=4mm] (A) -- (B); 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   778
  \draw [->,line width=4mm] (B) -- (C); 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   779
  \draw [->,line width=4mm] (C) -- (1); 
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   780
  \end{tikzpicture}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   781
  \end{center}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   782
  
598
e3ad67cd5123 updated
Christian Urban <urbanc@in.tum.de>
parents: 597
diff changeset
   783
We have a lexer and a parser\ldots
366
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   784
  
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   785
\end{frame}
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   786
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   787
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   788
\begin{frame}[c]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   789
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   790
\begin{center}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   791
\bl{\begin{tabular}{@{}lcl@{}}
598
e3ad67cd5123 updated
Christian Urban <urbanc@in.tum.de>
parents: 597
diff changeset
   792
\meta{Stmt} & $::=$ &  $\texttt{skip}$\\
e3ad67cd5123 updated
Christian Urban <urbanc@in.tum.de>
parents: 597
diff changeset
   793
              & $|$ & \textit{Id}\;\texttt{:=}\;\meta{AExp}\\
e3ad67cd5123 updated
Christian Urban <urbanc@in.tum.de>
parents: 597
diff changeset
   794
              & $|$ & \texttt{if}\; \meta{BExp} \;\texttt{then}\; \meta{Block} \;\texttt{else}\; \meta{Block}\\
e3ad67cd5123 updated
Christian Urban <urbanc@in.tum.de>
parents: 597
diff changeset
   795
              & $|$ & \texttt{while}\; \meta{BExp} \;\texttt{do}\; \meta{Block}\\
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   796
              & $|$ & \texttt{read}\;\textit{Id}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   797
              & $|$ & \texttt{write}\;\textit{Id}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   798
              & $|$ & \texttt{write}\;\textit{String}\medskip\\
598
e3ad67cd5123 updated
Christian Urban <urbanc@in.tum.de>
parents: 597
diff changeset
   799
\meta{Stmts} & $::=$ &  \meta{Stmt} \;\texttt{;}\; \meta{Stmts}\\
e3ad67cd5123 updated
Christian Urban <urbanc@in.tum.de>
parents: 597
diff changeset
   800
              & $|$ & \meta{Stmt}\medskip\\
e3ad67cd5123 updated
Christian Urban <urbanc@in.tum.de>
parents: 597
diff changeset
   801
\meta{Block} & $::=$ &  \texttt{\{}\,\meta{Stmts}\,\texttt{\}}\\
e3ad67cd5123 updated
Christian Urban <urbanc@in.tum.de>
parents: 597
diff changeset
   802
                & $|$ & \meta{Stmt}\medskip\\
e3ad67cd5123 updated
Christian Urban <urbanc@in.tum.de>
parents: 597
diff changeset
   803
\meta{AExp} & $::=$ & \ldots\\
e3ad67cd5123 updated
Christian Urban <urbanc@in.tum.de>
parents: 597
diff changeset
   804
\meta{BExp} & $::=$ & \ldots\\
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   805
\end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   806
\end{center}
366
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 365
diff changeset
   807
\end{frame}
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   808
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   809
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   810
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   811
\mode<presentation>{
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   812
\begin{frame}[c]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   813
744
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
   814
??%%\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
   815
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   816
\end{frame}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   817
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   818
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   819
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   820
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   821
\begin{frame}[c]
598
e3ad67cd5123 updated
Christian Urban <urbanc@in.tum.de>
parents: 597
diff changeset
   822
\frametitle{An Interpreter}
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   823
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   824
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   825
\bl{\begin{tabular}{l}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   826
$\{$\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   827
\;\;$x := 5 \text{;}$\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   828
\;\;$y := x * 3\text{;}$\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   829
\;\;$y := x * 4\text{;}$\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   830
\;\;$x := u * 3$\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   831
$\}$
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   832
\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   833
\end{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   834
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   835
\begin{itemize}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   836
\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
   837
\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
   838
\end{itemize}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   839
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   840
598
e3ad67cd5123 updated
Christian Urban <urbanc@in.tum.de>
parents: 597
diff changeset
   841
\end{frame}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   842
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   843
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   844
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   845
\begin{frame}[c]
598
e3ad67cd5123 updated
Christian Urban <urbanc@in.tum.de>
parents: 597
diff changeset
   846
\frametitle{An Interpreter}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   847
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   848
\begin{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   849
\bl{\begin{tabular}{@{}lcl@{}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   850
$\text{eval}(n, E)$ & $\dn$ & $n$\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   851
$\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
   852
$\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
   853
$\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
   854
$\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
   855
$\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
   856
$\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
   857
$\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
   858
\end{tabular}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   859
\end{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   860
598
e3ad67cd5123 updated
Christian Urban <urbanc@in.tum.de>
parents: 597
diff changeset
   861
\end{frame}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   862
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
598
e3ad67cd5123 updated
Christian Urban <urbanc@in.tum.de>
parents: 597
diff changeset
   863
e3ad67cd5123 updated
Christian Urban <urbanc@in.tum.de>
parents: 597
diff changeset
   864
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   865
\begin{frame}[c]
598
e3ad67cd5123 updated
Christian Urban <urbanc@in.tum.de>
parents: 597
diff changeset
   866
\frametitle{An Interpreter (2)}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   867
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   868
\begin{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   869
\bl{\begin{tabular}{@{}lcl@{}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   870
$\text{eval}(\text{skip}, E)$ & $\dn$ & $E$\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   871
$\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
   872
\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
   873
\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
   874
\text{eval}(cs_1,E)$}\\
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   875
\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
   876
\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
   877
\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
   878
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{then}\;
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   879
\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
   880
\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
   881
$\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
   882
\end{tabular}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   883
\end{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   884
598
e3ad67cd5123 updated
Christian Urban <urbanc@in.tum.de>
parents: 597
diff changeset
   885
\end{frame}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   886
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   887
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   888
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   889
\begin{frame}[c]
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   890
\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
   891
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   892
\mbox{}\\[-18mm]\mbox{}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   893
744
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
   894
??
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
   895
%{\lstset{language=While}%%\fontsize{10}{12}\selectfont
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
   896
%\texttt{\lstinputlisting{../progs/loops.while}}}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   897
295
19f23c4c2167 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   898
\end{frame}
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   899
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   900
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   901
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   902
\mode<presentation>{
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   903
\begin{frame}[t]
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   904
\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
   905
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   906
\begin{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   907
\begin{tikzpicture}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   908
\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
   909
\addplot+[smooth] file {interpreted.data};
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   910
\end{axis}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   911
\end{tikzpicture}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   912
\end{center}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   913
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   914
\end{frame}}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   915
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   916
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   917
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   918
\begin{frame}[c]
685
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   919
\frametitle{Java Virtual Machine}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   920
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   921
\begin{itemize}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   922
\item introduced in 1995
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   923
\item is a stack-based VM (like Postscript, CLR of .Net)
685
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   924
\item contains a JIT compiler\\
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   925
\begin{itemize}
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   926
\item From the Cradle to the Holy Graal - the JDK Story
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   927
\item \url{https://www.youtube.com/watch?v=h419kfbLhUI}
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   928
\end{itemize}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   929
\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
   930
\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
   931
\end{itemize}
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   932
685
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   933
\end{frame}
365
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   934
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
9b71dead1219 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 295
diff changeset
   935
685
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   936
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   937
\begin{frame}[c]
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   938
\frametitle{LLVM}
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   939
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   940
\begin{itemize}
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   941
\item LLVM started by academics in 2000 (University of Illinois in 
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   942
Urbana-Champaign)
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   943
\item suite of compiler tools
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   944
\item SSA-based intermediate language
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   945
\item no need to allocate registers
686
05cfce0fdef7 updated
Christian Urban <urbanc@in.tum.de>
parents: 685
diff changeset
   946
\item source languages: C, C++, Rust, Go, Swift
05cfce0fdef7 updated
Christian Urban <urbanc@in.tum.de>
parents: 685
diff changeset
   947
\item target CPUs: x86, ARM, PowerPC, \ldots
685
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   948
\end{itemize}  
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   949
\end{frame}
75d9f9e5906f updated
Christian Urban <urbanc@in.tum.de>
parents: 683
diff changeset
   950
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
702
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 686
diff changeset
   951
 
598
e3ad67cd5123 updated
Christian Urban <urbanc@in.tum.de>
parents: 597
diff changeset
   952
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
666
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   953
%\begin{frame}[c]
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   954
%  \frametitle{Coursework: MkEps}
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   955
%
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   956
%\begin{center}
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   957
%\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   958
%  \bl{$mkeps([c_1 c_2 \ldots c_n])$}  & \bl{$\dn$} & $\bl{undefined}$\\
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   959
%  \bl{$mkeps(r^*)$}                   & \bl{$\dn$} & $\bl{Stars\,[]}$\\
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   960
%  \bl{$mkeps(r^{\{n\}})$}              & \bl{$\dn$} & $\bl{Stars\,(mkeps(r))^n}$\\
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   961
%  \bl{$mkeps(r^{\{n..\}})$}            & \bl{$\dn$} & $\bl{Stars\,(mkeps(r))^n}$\\
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   962
%  \bl{$mkeps(r^{\{..n\}})$}            & \bl{$\dn$} & $\bl{Stars\,[]}$\\
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   963
%  \bl{$mkeps(r^{\{n..m\}})$}           & \bl{$\dn$} & $\bl{Stars\,(mkeps(r))^n}$\medskip\\
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   964
%  
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   965
%  \bl{$mkeps(r^+)$}                   & \bl{$\dn$} & \bl{$mkeps(r^{\{1..\}})$}\\
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   966
%  \bl{$mkeps(r^?)$}                   & \bl{$\dn$} & \bl{$mkeps(r^{\{..1\}})$}\\
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   967
%\end{tabular}
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   968
%\end{center}
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   969
%
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   970
%\end{frame}
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   971
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   972
%
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   973
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   974
%\begin{frame}[c]
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   975
%  \frametitle{Coursework: Inj}
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   976
%
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   977
%\begin{center}
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   978
%\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   979
%  \bl{$inj([c_1 c_2 \ldots c_n])\,c\,Empty$}  & \bl{$\dn$} & $\bl{Chr\,c}$\\
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   980
%  \bl{$inj(r^*)\,c\;(Seq\,v\,(Stars\,vs))$}                   & \bl{$\dn$} & $\bl{Stars\,(inj\,r\,c\,v::vs)}$\\
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   981
%  \bl{$inj(r^{\{n\}})\,c\;(Seq\,v\,(Stars\,vs))$}              & \bl{$\dn$} & $\bl{Stars\,(inj\,r\,c\,v::vs)}$\\
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   982
%  \bl{$inj(r^{\{n..\}})\,c\;(Seq\,v\,(Stars\,vs))$}            & \bl{$\dn$} & $\bl{Stars\,(inj\,r\,c\,v::vs)}$\\
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   983
%  \bl{$inj(r^{\{..n\}})\,c\;(Seq\,v\,(Stars\,vs))$}            & \bl{$\dn$} & $\bl{Stars\,(inj\,r\,c\,v::vs)}$\\
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   984
%  \bl{$inj(r^{\{n..m\}})\,c\;(Seq\,v\,(Stars\,vs))$}           & \bl{$\dn$} & $\bl{Stars\,(inj\,r\,c\,v::vs)}$\medskip\\
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   985
%  
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   986
%  \bl{$inj(r^+)\,c\,v$}                   & \bl{$\dn$} & \bl{$inj(r^{\{1..\}})\,c\,v$}\\
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   987
%  \bl{$inj(r^?)\,c\,v$}                   & \bl{$\dn$} & \bl{$inj(r^{\{..1\}})\,c\,v$}\\
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   988
%\end{tabular}
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   989
%\end{center}
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   990
%
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   991
%\end{frame}
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 599
diff changeset
   992
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
702
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 686
diff changeset
   993
%
598
e3ad67cd5123 updated
Christian Urban <urbanc@in.tum.de>
parents: 597
diff changeset
   994
809
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
   995
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
   996
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
   997
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   998
\end{document}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   999
803
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1000
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1001
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1002
\begin{frame}[c]
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1003
\frametitle{Parser Combinators}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1004
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1005
One of the simplest ways to implement a parser, see
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1006
{\small\url{https://vimeo.com/142341803}} (by Haoyi Li)\bigskip
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1007
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1008
\begin{itemize}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1009
\item[$\bullet$] build-in library in Scala
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1010
\item[$\bullet$] fastparse (2) library by Haoyi Li; is part of Ammonite
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1011
\item[$\bullet$] possible exponential runtime behaviour  
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1012
\end{itemize}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1013
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1014
\end{frame}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1015
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1016
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1017
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1018
\begin{frame}[c]
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1019
\frametitle{Parser Combinators}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1020
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1021
Parser combinators: \bigskip
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1022
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1023
\begin{minipage}{1.1\textwidth}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1024
\begin{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1025
\mbox{}\hspace{-12mm}\mbox{}$\underbrace{\text{list of tokens}}_{\text{input}}$ \bl{$\Rightarrow$} 
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1026
$\underbrace{\text{set of (parsed input, unparsed input)}}_{\text{output}}$
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1027
\end{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1028
\end{minipage}\bigskip
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1029
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1030
\begin{itemize}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1031
\item atomic parsers
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1032
\item sequencing
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1033
\item alternative
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1034
\item semantic action (map-parser)
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1035
\end{itemize}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1036
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1037
\end{frame}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1038
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1039
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1040
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1041
\begin{frame}[c]
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1042
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1043
Atomic parsers, for example, number tokens
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1044
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1045
\begin{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1046
\bl{$\texttt{Num(123)}::rest \;\Rightarrow\; \{(\texttt{Num(123)}, rest)\}$} 
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1047
\end{center}\bigskip
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1048
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1049
\begin{itemize}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1050
\item you consume one or more token from the\\ 
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1051
  input (stream)
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1052
\item also works for characters and strings
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1053
\end{itemize}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1054
\end{frame}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1055
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1056
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1057
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1058
\begin{frame}[c]
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1059
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1060
Alternative parser (code \bl{$p\;||\;q$})\bigskip
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1061
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1062
\begin{itemize}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1063
\item apply \bl{$p$} and also \bl{$q$}; then combine 
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1064
  the outputs
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1065
\end{itemize}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1066
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1067
\begin{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1068
\large \bl{$p(\text{input}) \cup q(\text{input})$}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1069
\end{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1070
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1071
\end{frame}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1072
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1073
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1074
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1075
\begin{frame}[c]
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1076
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1077
Sequence parser (code \bl{$p\sim q$})\bigskip
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1078
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1079
\begin{itemize}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1080
\item apply first \bl{$p$} producing a set of pairs
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1081
\item then apply \bl{$q$} to the unparsed part
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1082
\item then combine the results:\medskip 
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1083
\begin{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1084
((output$_1$, output$_2$), unparsed part)
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1085
\end{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1086
\end{itemize}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1087
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1088
\begin{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1089
\begin{tabular}{l}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1090
\large \bl{$\{((o_1, o_2), u_2) \;|\;$}\\[2mm] 
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1091
\large\mbox{}\hspace{15mm} \bl{$(o_1, u_1) \in p(\text{input}) \wedge$}\\[2mm]
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1092
\large\mbox{}\hspace{15mm} \bl{$(o_2, u_2) \in q(u_1)\}$}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1093
\end{tabular}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1094
\end{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1095
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1096
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1097
\end{frame}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1098
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1099
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1100
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1101
\begin{frame}[c]
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1102
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1103
Map-parser (code \bl{$p.map(f)\;$})\bigskip
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1104
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1105
\begin{itemize}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1106
\item apply \bl{$p$} producing a set of pairs
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1107
\item then apply the function \bl{$f$} to each first component
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1108
\end{itemize}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1109
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1110
\begin{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1111
\begin{tabular}{l}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1112
\large \bl{$\{(f(o_1), u_1) \;|\; (o_1, u_1) \in p(\text{input})\}$}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1113
\end{tabular}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1114
\end{center}\bigskip\bigskip\pause
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1115
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1116
\bl{$f$} is the semantic action (``what to do with the parsed input'')
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1117
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1118
\end{frame}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1119
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1120
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1121
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1122
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1123
\mode<presentation>{
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1124
\begin{frame}[c]
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1125
\frametitle{\begin{tabular}{c}Semantic Actions\end{tabular}}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1126
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1127
Addition
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1128
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1129
\begin{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1130
\bl{$\meta{T} \sim + \sim \meta{E} \Rightarrow \underbrace{f\,((x,y), z) \Rightarrow x + z}_{\text{semantic action}}$}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1131
\end{center}\pause
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1132
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1133
Multiplication
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1134
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1135
\begin{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1136
\bl{$\meta{F} \sim * \sim \meta{T} \Rightarrow f\,((x,y), z) \Rightarrow x * z$}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1137
\end{center}\pause
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1138
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1139
Parenthesis
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1140
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1141
\begin{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1142
\bl{$\text{(} \sim \meta{E} \sim \text{)} \Rightarrow f\,((x,y), z) \Rightarrow y$}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1143
\end{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1144
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1145
\end{frame}}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1146
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1147
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1148
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1149
\begin{frame}[c]
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1150
\frametitle{Types of Parsers}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1151
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1152
\begin{itemize}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1153
\item {\bf Sequencing}: if \bl{$p$} returns results of type \bl{$T$}, and \bl{$q$} results of type \bl{$S$},
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1154
then \bl{$p \sim q$} returns results of type
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1155
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1156
\begin{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1157
\bl{$T \times S$}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1158
\end{center}\pause
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1159
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1160
\item {\bf Alternative}: if \bl{$p$} returns results of type \bl{$T$} then  \bl{$q$} \alert{must} also have results of type \bl{$T$},
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1161
and \bl{$p \;||\; q$} returns results of type
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1162
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1163
\begin{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1164
\bl{$T$}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1165
\end{center}\pause
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1166
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1167
\item {\bf Semantic Action}: if \bl{$p$} returns results of type \bl{$T$} and \bl{$f$} is a function from
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1168
\bl{$T$} to \bl{$S$}, then
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1169
\bl{$p \Rightarrow f$} returns results of type
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1170
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1171
\begin{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1172
\bl{$S$}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1173
\end{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1174
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1175
\end{itemize}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1176
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1177
\end{frame}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1178
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1179
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1180
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1181
\begin{frame}[c]
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1182
\frametitle{Input Types of Parsers}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1183
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1184
\begin{itemize}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1185
\item input: \alert{token list}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1186
\item output: set of (output\_type, \alert{token list})
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1187
\end{itemize}\bigskip\pause
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1188
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1189
actually it can be any input type as long as it is a kind of
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1190
sequence (for example a string)
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1191
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1192
\end{frame}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1193
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1194
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1195
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1196
\begin{frame}[c]
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1197
\frametitle{Scannerless Parsers}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1198
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1199
\begin{itemize}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1200
\item input: \alert{string}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1201
\item output: set of (output\_type, \alert{string})
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1202
\end{itemize}\bigskip\bigskip
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1203
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1204
but using lexers is better because whitespaces or comments can be
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1205
filtered out; then input is a sequence of tokens
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1206
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1207
\end{frame}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1208
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1209
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1210
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1211
\begin{frame}[c]
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1212
\frametitle{Successful Parses}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1213
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1214
\begin{itemize}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1215
\item input: string
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1216
\item output: \alert{set of} (output\_type, string)
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1217
\end{itemize}\bigskip
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1218
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1219
a parse is successful whenever the input has been fully
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1220
``consumed'' (that is the second component is empty)
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1221
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1222
\end{frame}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1223
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1224
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1225
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1226
\begin{frame}[c]
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1227
\frametitle{Abstract Parser Class}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1228
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1229
\small
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1230
\lstinputlisting[language=Scala,xleftmargin=1mm]
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1231
 {../progs/app7.scala}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1232
\end{frame}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1233
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1234
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1235
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1236
\begin{frame}[c]
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1237
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1238
\small
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1239
\fontsize{10}{12}\selectfont
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1240
\lstinputlisting[language=Scala,xleftmargin=1mm]
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1241
  {../progs/app8.scala}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1242
\end{frame}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1243
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1244
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1245
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1246
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1247
\begin{frame}[c]
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1248
\frametitle{Two Grammars}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1249
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1250
Which languages are recognised by the following two grammars?
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1251
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1252
\begin{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1253
\bl{\begin{tabular}{lcl}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1254
$\meta{S}$ & $\rightarrow$ &  $1 \cdot \meta{S} \cdot \meta{S}$\\
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1255
        & $|$ & $\epsilon$
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1256
\end{tabular}}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1257
\end{center}\bigskip
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1258
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1259
\begin{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1260
\bl{\begin{tabular}{lcl}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1261
$\meta{U}$ & $\rightarrow$ &  $1 \cdot \meta{U}$\\
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1262
        & $|$ & $\epsilon$
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1263
\end{tabular}}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1264
\end{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1265
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1266
\end{frame}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1267
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1268
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1269
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1270
\begin{frame}[t]
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1271
\frametitle{Ambiguous Grammars}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1272
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1273
\begin{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1274
\begin{tikzpicture}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1275
\begin{axis}[xlabel={\pcode{1}s},ylabel={time in secs},
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1276
    enlargelimits=false,
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1277
    xtick={0,100,...,1000},
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1278
    xmax=1050,
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1279
    ymax=33,
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1280
    ytick={0,5,...,30},
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1281
    scaled ticks=false,
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1282
    axis lines=left,
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1283
    width=11cm,
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1284
    height=7cm, 
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1285
    legend entries={unambiguous,ambiguous},  
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1286
    legend pos=north east,
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1287
    legend cell align=left,
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1288
    x tick label style={font=\small,/pgf/number format/1000 sep={}}]
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1289
\addplot[blue,mark=*, mark options={fill=white}] 
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1290
  table {s-grammar1.data};
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1291
\only<2>{
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1292
  \addplot[red,mark=triangle*, mark options={fill=white}] 
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1293
  table {s-grammar2.data};}  
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1294
\end{axis}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1295
\end{tikzpicture}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1296
\end{center}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1297
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1298
\end{frame}
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1299
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1300
809
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
  1301
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
2b9956d29038 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 803
diff changeset
  1302
803
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1303
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1304
d4fb8c7fc3bf updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
  1305
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1306
%%% Local Variables:  
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1307
%%% mode: latex
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1308
%%% TeX-master: t
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1309
%%% End: 
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1310