slides/slides05.tex
author Christian Urban <urbanc@in.tum.de>
Fri, 25 Oct 2019 14:55:31 +0100
changeset 667 412556272333
parent 666 4fbdc80076cb
child 671 83e38043ed78
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
582
d236e75e1d55 updated
Christian Urban <urbanc@in.tum.de>
parents: 550
diff changeset
     1
664
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
     2
% !TEX program = xelatex
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
\documentclass[dvipsnames,14pt,t]{beamer}
270
4dbeaf43031d updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
     4
\usepackage{../slides}
4dbeaf43031d updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
     5
\usepackage{../graphics}
215
828303e8e4af updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 169
diff changeset
     6
\usepackage{../langs}
828303e8e4af updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 169
diff changeset
     7
\usepackage{../data}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
     8
\usepackage{../grammar}
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
270
4dbeaf43031d updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    10
\hfuzz=220pt 
4dbeaf43031d updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    11
4dbeaf43031d updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    12
\pgfplotsset{compat=1.11}
4dbeaf43031d updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    13
4dbeaf43031d updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    14
\newcommand{\bl}[1]{\textcolor{blue}{#1}}  
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
% beamer stuff 
445
e7d0157f0471 updated slides
Christian Urban <urbanc@in.tum.de>
parents: 370
diff changeset
    17
\renewcommand{\slidecaption}{CFL 05, King's College London}
270
4dbeaf43031d updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    18
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
\begin{document}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
270
4dbeaf43031d updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    23
\begin{frame}[t]
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
\frametitle{%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
  \begin{tabular}{@ {}c@ {}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
  \\[-3mm]
445
e7d0157f0471 updated slides
Christian Urban <urbanc@in.tum.de>
parents: 370
diff changeset
    27
  \LARGE Compilers and \\[-2mm] 
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
  \LARGE Formal Languages (5)\\[3mm] 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
  \end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
  \normalsize
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
  \begin{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
  \begin{tabular}{ll}
664
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
    34
    Email:  & christian.urban at kcl.ac.uk\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
    35
    Office Hours: & Thursdays 12 -- 14\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
    36
    Location: & N7.07 (North Wing, Bush House)\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
    37
    Slides \& Progs: & KEATS (also homework is there)\\  
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
  \end{tabular}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
  \end{center}
270
4dbeaf43031d updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    40
\end{frame}
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    41
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
667
412556272333 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
    43
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
412556272333 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
    44
\begin{frame}[c]
412556272333 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
    45
  \frametitle{Coursework 1: Submissions}
412556272333 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
    46
  
412556272333 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
    47
  \begin{itemize}
412556272333 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
    48
  \item Scala (29)
412556272333 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
    49
  \item Haskell (1)
412556272333 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
    50
  \item Kotlin (1)
412556272333 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
    51
  \item Rust (1)
412556272333 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
    52
  \end{itemize}\bigskip\bigskip  
412556272333 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
    53
  
412556272333 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
    54
  \small
412556272333 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
    55
  Please get in contact if you intend to do CW Strand 2. No zips please.
412556272333 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
    56
  Give definitions also on paper if asked. BTW, simp 
412556272333 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
    57
  can stay unchanged. Use \texttt{ders} for CW2, not \texttt{ders2}!
412556272333 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
    58
  \end{frame}
412556272333 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
    59
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
412556272333 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
    60
    
412556272333 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
    61
  
462
Christian Urban <urbanc@in.tum.de>
parents: 451
diff changeset
    62
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents: 451
diff changeset
    63
\begin{frame}[c]
666
4fbdc80076cb updated
Christian Urban <urbanc@in.tum.de>
parents: 665
diff changeset
    64
\frametitle{\begin{tabular}{c}Last Week\\[-2mm] 
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
    65
            Regexes and Values\end{tabular}}
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    67
Regular expressions and their corresponding values:
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    68
147
4725bba8ef26 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    69
\begin{center}
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    70
\begin{columns}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    71
\begin{column}{3cm}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    72
\begin{tabular}{@{}rrl@{}}
445
e7d0157f0471 updated slides
Christian Urban <urbanc@in.tum.de>
parents: 370
diff changeset
    73
  \bl{$r$} & \bl{$::=$}  & \bl{$\ZERO$}\\
e7d0157f0471 updated slides
Christian Urban <urbanc@in.tum.de>
parents: 370
diff changeset
    74
           & \bl{$\mid$} & \bl{$\ONE$}   \\
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    75
           & \bl{$\mid$} & \bl{$c$}          \\
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    76
           & \bl{$\mid$} & \bl{$r_1 \cdot r_2$}\\
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    77
           & \bl{$\mid$} & \bl{$r_1 + r_2$}   \\
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    78
  \\
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    79
           & \bl{$\mid$} & \bl{$r^*$}         \\
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    80
  \end{tabular}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    81
\end{column}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    82
\begin{column}{3cm}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    83
\begin{tabular}{@{\hspace{-7mm}}rrl@{}}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    84
  \bl{$v$} & \bl{$::=$}  & \\
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    85
           &             & \bl{$Empty$}   \\
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    86
           & \bl{$\mid$} & \bl{$Char(c)$}          \\
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    87
           & \bl{$\mid$} & \bl{$Seq(v_1,v_2)$}\\
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    88
           & \bl{$\mid$} & \bl{$Left(v)$}   \\
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    89
           & \bl{$\mid$} & \bl{$Right(v)$}  \\
664
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
    90
           & \bl{$\mid$} & \bl{$Stars [v_1,\ldots\,v_n]$} \\
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    91
  \end{tabular}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    92
\end{column}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    93
\end{columns}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    94
\end{center}
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    96
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    97
\end{frame}
147
4725bba8ef26 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    98
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
4725bba8ef26 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    99
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
272
1446bc47a294 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 270
diff changeset
   101
\begin{frame}[c]
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   103
\begin{textblock}{10}(3,5)
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   104
\begin{tikzpicture}[scale=2,node distance=1.3cm,every node/.style={minimum size=8mm}]
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   105
\node (r1)  {\bl{$r_1$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   106
\node (r2) [right=of r1] {\bl{$r_2$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   107
\draw[->,line width=1mm]  (r1) -- (r2) node[above,midway] {\bl{$der\,a$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   108
\node (r3) [right=of r2] {\bl{$r_3$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   109
\draw[->,line width=1mm]  (r2) -- (r3) node[above,midway] {\bl{$der\,b$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   110
\node (r4) [right=of r3] {\bl{$r_4$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   111
\draw[->,line width=1mm]  (r3) -- (r4) node[above,midway] {\bl{$der\,c$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   112
\draw (r4) node[anchor=west] {\;\raisebox{3mm}{\bl{$nullable$}}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   113
\node (v4) [below=of r4] {\bl{$v_4$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   114
\draw[->,line width=1mm]  (r4) -- (v4);
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   115
\node (v3) [left=of v4] {\bl{$v_3$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   116
\draw[->,line width=1mm]  (v4) -- (v3) node[below,midway] {\bl{$inj\,c$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   117
\node (v2) [left=of v3] {\bl{$v_2$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   118
\draw[->,line width=1mm]  (v3) -- (v2) node[below,midway] {\bl{$inj\,b$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   119
\node (v1) [left=of v2] {\bl{$v_1$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   120
\draw[->,line width=1mm]  (v2) -- (v1) node[below,midway] {\bl{$inj\,a$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   121
\draw[->,line width=0.5mm]  (r3) -- (v3);
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   122
\draw[->,line width=0.5mm]  (r2) -- (v2);
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   123
\draw[->,line width=0.5mm]  (r1) -- (v1);
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   124
\draw (r4) node[anchor=north west] {\;\raisebox{-8mm}{\bl{$mkeps$}}};
147
4725bba8ef26 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   125
\end{tikzpicture}
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   126
\end{textblock}
147
4725bba8ef26 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   127
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   128
\begin{textblock}{6}(1,0.8)
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   129
\begin{bubble}[6cm]
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   130
\small
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   131
\begin{tabular}{ll}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   132
\bl{$r_1$}: & \bl{$a \cdot (b \cdot c)$}\\
445
e7d0157f0471 updated slides
Christian Urban <urbanc@in.tum.de>
parents: 370
diff changeset
   133
\bl{$r_2$}: & \bl{$\ONE \cdot (b \cdot c)$}\\
e7d0157f0471 updated slides
Christian Urban <urbanc@in.tum.de>
parents: 370
diff changeset
   134
\bl{$r_3$}: & \bl{$(\ZERO \cdot (b \cdot c)) + (\ONE \cdot c)$}\\
e7d0157f0471 updated slides
Christian Urban <urbanc@in.tum.de>
parents: 370
diff changeset
   135
\bl{$r_4$}: & \bl{$(\ZERO \cdot (b \cdot c)) + ((\ZERO \cdot c) + \ONE)$}\\
147
4725bba8ef26 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   136
\end{tabular}
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   137
\end{bubble}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   138
\end{textblock}
147
4725bba8ef26 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   139
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   140
\begin{textblock}{6}(1,11.4)
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   141
\begin{bubble}[7.6cm]
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   142
\small
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   143
\begin{tabular}{ll}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   144
\bl{$v_1$}: & \bl{$Seq(Char(a), Seq(Char(b), Char(c)))$}\\
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   145
\bl{$v_2$}: & \bl{$Seq(Empty, Seq(Char(b), Char(c)))$}\\
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   146
\bl{$v_3$}: & \bl{$Right(Seq(Empty, Char(c)))$}\\
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   147
\bl{$v_4$}: & \bl{$Right(Right(Empty))$}\\
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   148
\end{tabular}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   149
\end{bubble}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   150
\end{textblock}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   151
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   152
\begin{textblock}{6}(12,11.4)
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   153
\begin{bubble}[2cm]
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   154
\small
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   155
\begin{tabular}{ll}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   156
\bl{$|v_1|$}: & \bl{$abc$}\\
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   157
\bl{$|v_2|$}: & \bl{$bc$}\\
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   158
\bl{$|v_3|$}: & \bl{$c$}\\
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   159
\bl{$|v_4|$}: & \bl{$[]$}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   160
\end{tabular}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   161
\end{bubble}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   162
\end{textblock}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   163
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
272
1446bc47a294 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 270
diff changeset
   165
\end{frame}
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   168
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   169
\begin{frame}[c]
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   170
\frametitle{Simplification}
147
4725bba8ef26 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   171
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   172
\begin{itemize}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   173
\item If we simplify after the derivative, then we are builing the
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   174
value for the simplified regular expression, but \emph{not} for the original
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   175
regular expression.
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   176
\end{itemize}
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
147
4725bba8ef26 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   178
\begin{center}
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   179
\begin{tikzpicture}[scale=2,node distance=1.3cm,every node/.style={minimum size=8mm}]
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   180
\node (r1)  {\bl{$r_1$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   181
\node (r2) [right=of r1] {\bl{$r_2$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   182
\draw[->,line width=1mm]  (r1) -- (r2) node[above,midway] {\bl{$der\,a$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   183
\node (r3) [right=of r2] {\bl{$r_3$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   184
\draw[->,line width=1mm]  (r2) -- (r3) node[above,midway] {\bl{$der\,b$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   185
\node (r4) [right=of r3] {\bl{$r_4$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   186
\draw[->,line width=1mm]  (r3) -- (r4) node[above,midway] {\bl{$der\,c$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   187
\draw (r4) node[anchor=west] {\;\raisebox{3mm}{\bl{$nullable$}}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   188
\node (v4) [below=of r4] {\bl{$v_4$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   189
\draw[->,line width=1mm]  (r4) -- (v4);
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   190
\node (v3) [left=of v4] {\bl{$v_3$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   191
\draw[->,line width=1mm]  (v4) -- (v3) node[below,midway] {\bl{$inj\,c$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   192
\node (v2) [left=of v3] {\bl{$v_2$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   193
\draw[->,line width=1mm]  (v3) -- (v2) node[below,midway] {\bl{$inj\,b$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   194
\node (v1) [left=of v2] {\bl{$v_1$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   195
\draw[->,line width=1mm]  (v2) -- (v1) node[below,midway] {\bl{$inj\,a$}};
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   196
\draw[->,line width=0.5mm]  (r3) -- (v3);
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   197
\draw[->,line width=0.5mm]  (r2) -- (v2);
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   198
\draw[->,line width=0.5mm]  (r1) -- (v1);
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   199
\draw (r4) node[anchor=north west] {\;\raisebox{-8mm}{\bl{$mkeps$}}};
147
4725bba8ef26 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   200
\end{tikzpicture}
4725bba8ef26 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   201
\end{center}
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   203
\small
445
e7d0157f0471 updated slides
Christian Urban <urbanc@in.tum.de>
parents: 370
diff changeset
   204
\hspace{4.5cm}\bl{$(b \cdot c) + (\ZERO + \ONE)$}
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   205
$\mapsto$
445
e7d0157f0471 updated slides
Christian Urban <urbanc@in.tum.de>
parents: 370
diff changeset
   206
\bl{$(b \cdot c) + \ONE$}
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   207
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   208
\end{frame}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   209
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   210
528
68fab15cd6fb updated
cu
parents: 500
diff changeset
   211
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68fab15cd6fb updated
cu
parents: 500
diff changeset
   212
% \begin{frame}[t]
361
9c7eb266594c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
   213
528
68fab15cd6fb updated
cu
parents: 500
diff changeset
   214
% \begin{center}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   215
% \bl{$\only<1>{(b \cdot c)}%
68fab15cd6fb updated
cu
parents: 500
diff changeset
   216
%      \only<2-3>{(\underline{b \cdot c})}%
68fab15cd6fb updated
cu
parents: 500
diff changeset
   217
%      \only<1-3>{+}% 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   218
%      \only<1>{(\ZERO + \ONE)}%
68fab15cd6fb updated
cu
parents: 500
diff changeset
   219
%      \only<2-3>{(\underline{\ZERO + \ONE})}$}%
68fab15cd6fb updated
cu
parents: 500
diff changeset
   220
% \only<4->{%
68fab15cd6fb updated
cu
parents: 500
diff changeset
   221
% \bl{$\underline{(b \cdot c) + (\ZERO + \ONE)}$}%
68fab15cd6fb updated
cu
parents: 500
diff changeset
   222
% }
68fab15cd6fb updated
cu
parents: 500
diff changeset
   223
% $\mapsto$
68fab15cd6fb updated
cu
parents: 500
diff changeset
   224
% \bl{$(b \cdot c) + \ONE$}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   225
% \end{center}\bigskip
361
9c7eb266594c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
   226
528
68fab15cd6fb updated
cu
parents: 500
diff changeset
   227
% \onslide<3->{%
68fab15cd6fb updated
cu
parents: 500
diff changeset
   228
% \begin{center}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   229
% \begin{tabular}{lcl}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   230
% \bl{$f_{s1}$} & \bl{$=$} & \bl{$\lambda v.v$}\\
68fab15cd6fb updated
cu
parents: 500
diff changeset
   231
% \bl{$f_{s2}$} & \bl{$=$} & \bl{$\lambda v. \textit{Right}(v)$}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   232
% \end{tabular}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   233
% \end{center}}
361
9c7eb266594c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
   234
528
68fab15cd6fb updated
cu
parents: 500
diff changeset
   235
% \only<4>{%
68fab15cd6fb updated
cu
parents: 500
diff changeset
   236
% \begin{center}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   237
% \begin{tabular}{@{}l@{\hspace{1mm}}l@{}}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   238
% \bl{$f_{alt}(f_{s1}, f_{s2}) \dn$}\\
68fab15cd6fb updated
cu
parents: 500
diff changeset
   239
% \quad \bl{$\lambda v.\,$} 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   240
%         case \bl{$v = Left(v')$}: 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   241
%       & return \bl{$Left(f_{s1}(v'))$}\\
68fab15cd6fb updated
cu
parents: 500
diff changeset
   242
% \quad \phantom{$\lambda v.\,$} 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   243
%         case \bl{$v = Right(v')$}: 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   244
%       & return \bl{$Right(f_{s2}(v'))$}\\ 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   245
% \end{tabular}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   246
% \end{center}}%
68fab15cd6fb updated
cu
parents: 500
diff changeset
   247
% \only<5->{%
68fab15cd6fb updated
cu
parents: 500
diff changeset
   248
% \begin{center}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   249
% \begin{tabular}{@{}l@{\hspace{1mm}}l@{}}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   250
% \only<5->{\phantom{\bl{$f_{alt}(f_{s1}, f_{s2}) \dn$}}}\\
68fab15cd6fb updated
cu
parents: 500
diff changeset
   251
% \quad \bl{$\lambda v.\,$} 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   252
%         case \bl{$v = Left(v')$}: 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   253
%       & return \bl{$Left(v')$}\\
68fab15cd6fb updated
cu
parents: 500
diff changeset
   254
% \quad \phantom{$\lambda v.\,$} 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   255
%         case \bl{$v = Right(v')$}: 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   256
%       & return \bl{$Right(Right(v'))$}\\ 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   257
% \end{tabular}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   258
% \end{center}}%
361
9c7eb266594c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
   259
528
68fab15cd6fb updated
cu
parents: 500
diff changeset
   260
% \only<6->{%
68fab15cd6fb updated
cu
parents: 500
diff changeset
   261
% \begin{center}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   262
% \begin{tabular}{@{}l@{\hspace{4mm}}l@{}}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   263
% \bl{$\textit{mkeps}$} simplified case: &
68fab15cd6fb updated
cu
parents: 500
diff changeset
   264
% \bl{$\textit{Right}(\textit{Empty})$}\\
68fab15cd6fb updated
cu
parents: 500
diff changeset
   265
% rectified case: &
68fab15cd6fb updated
cu
parents: 500
diff changeset
   266
% \bl{$\textit{Right}(\textit{Right}(\textit{Empty}))$}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   267
% \end{tabular}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   268
% \end{center}}%
361
9c7eb266594c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
   269
528
68fab15cd6fb updated
cu
parents: 500
diff changeset
   270
% \end{frame}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   271
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
361
9c7eb266594c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
   272
9c7eb266594c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
   273
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   274
\begin{frame}[c]
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   275
\frametitle{Records}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   276
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   277
\begin{itemize}
583
Christian Urban <urbanc@in.tum.de>
parents: 582
diff changeset
   278
\item new regex: \bl{$(x:r)$}\hspace{7mm}new value: \bl{$Rec(x,v)$}\medskip\pause
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   279
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   280
\item \bl{$nullable(x:r) \dn nullable(r)$}
583
Christian Urban <urbanc@in.tum.de>
parents: 582
diff changeset
   281
\item \bl{$der\,c\,(x:r) \dn (x:der\,c\,r)$}
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   282
\item \bl{$mkeps(x:r) \dn Rec(x, mkeps(r))$}
583
Christian Urban <urbanc@in.tum.de>
parents: 582
diff changeset
   283
\item \bl{$inj\,(x:r)\,c\,Rec(x, v) \dn Rec(x, inj\,r\,c\,v)$}
Christian Urban <urbanc@in.tum.de>
parents: 582
diff changeset
   284
\end{itemize}\bigskip\bigskip\pause
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   285
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   286
\small
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   287
for extracting subpatterns \bl{$(z: ((x:ab) + (y:ba))$}
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   288
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   289
\end{frame}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   290
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46
Christian Urban <urbanc@in.tum.de>
parents: 44
diff changeset
   291
583
Christian Urban <urbanc@in.tum.de>
parents: 582
diff changeset
   292
148
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   293
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   294
\begin{frame}[c]
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   295
\frametitle{Environments}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   296
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   297
Obtaining the ``recorded'' parts of a value: 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   298
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   299
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   300
\begin{tabular}{lcl}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   301
  \bl{$env(Empty)$}     & \bl{$\dn$} & \bl{$[]$}\\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   302
  \bl{$env(Char(c))$}   & \bl{$\dn$} & \bl{$[]$}\\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   303
  \bl{$env(Left(v))$}   & \bl{$\dn$} & \bl{$env(v)$}\\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   304
  \bl{$env(Right(v))$}  & \bl{$\dn$} & \bl{$env(v)$}\\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   305
  \bl{$env(Seq(v_1,v_2))$}& \bl{$\dn$} & \bl{$env(v_1) \,@\, env(v_2)$}\\
664
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   306
  \bl{$env(Stars [v_1,\ldots ,v_n])$} & \bl{$\dn$} & 
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   307
     \bl{$env(v_1) \,@\ldots @\, env(v_n)$}\\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   308
  \bl{$env(Rec(x:v))$} & \bl{$\dn$} & \bl{$(x:|v|) :: env(v)$}\\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   309
\end{tabular}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   310
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   311
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   312
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   313
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   314
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   315
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   316
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   317
\begin{frame}[c]
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   318
\frametitle{While Tokens}
150
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 149
diff changeset
   319
148
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   320
\begin{center}
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   321
\begin{tabular}{@{}r@{\hspace{2mm}}c@{\hspace{2mm}}l@{}}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   322
\pcode{WHILE\_REGS} & $\dn$ & \raisebox{-1mm}{\large(}\pcode{("k" : KEYWORD)} +\\ 
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   323
                  &       & \phantom{(}\pcode{("i" : ID)} +\\ 
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   324
                  &       & \phantom{(}\pcode{("o" : OP)} + \\
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   325
                  &       & \phantom{(}\pcode{("n" : NUM)} + \\
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   326
                  &       & \phantom{(}\pcode{("s" : SEMI)} +\\ 
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   327
                  &       & \phantom{(}\pcode{("p" : (LPAREN + RPAREN))} +\\ 
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   328
                  &       & \phantom{(}\pcode{("b" : (BEGIN + END))} +\\ 
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   329
                  &       & \phantom{(}\pcode{("w" : WHITESPACE)}\raisebox{-1mm}{\large)$^*$}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   330
\end{tabular}
148
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   331
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   332
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   333
\end{frame}
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
   334
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
148
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   335
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   336
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   337
148
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   338
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   339
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   340
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   341
\consolas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   342
\begin{center}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   343
\code{"if true then then 42 else +"}
148
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   344
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   345
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   346
\only<1>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   347
\small\begin{tabular}{l}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   348
KEYWORD(if),\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   349
WHITESPACE,\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   350
IDENT(true),\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   351
WHITESPACE,\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   352
KEYWORD(then),\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   353
WHITESPACE,\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   354
KEYWORD(then),\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   355
WHITESPACE,\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   356
NUM(42),\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   357
WHITESPACE,\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   358
KEYWORD(else),\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   359
WHITESPACE,\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   360
OP(+)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   361
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   362
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   363
\only<2>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   364
\small\begin{tabular}{l}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   365
KEYWORD(if),\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   366
IDENT(true),\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   367
KEYWORD(then),\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   368
KEYWORD(then),\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   369
NUM(42),\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   370
KEYWORD(else),\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   371
OP(+)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   372
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   373
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   374
\end{frame}
148
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   375
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 147
diff changeset
   376
664
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   377
582
d236e75e1d55 updated
Christian Urban <urbanc@in.tum.de>
parents: 550
diff changeset
   378
d236e75e1d55 updated
Christian Urban <urbanc@in.tum.de>
parents: 550
diff changeset
   379
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
664
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   380
%\begin{frame}[c]
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   381
%\frametitle{Coursework: PLs (16)}
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   382
%
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   383
%\begin{itemize}
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   384
%\item Java (16)
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   385
%\item C++, C, C\# (14)
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   386
%\item JavaScript (10)
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   387
%\item Scala (9)
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   388
%\item Python (9)  
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   389
%\item PHP (6)
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   390
%\item Haskell (3)
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   391
%\item Ruby (4)
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   392
%\item Bash, Perl, Powershell (2)
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   393
%\item TypeScript (1)
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   394
%\item R (1)
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   395
%\item Coconut (1)  
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   396
%\item Pascal (1)
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   397
%\end{itemize}  
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   398
%
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   399
%\end{frame}
528
68fab15cd6fb updated
cu
parents: 500
diff changeset
   400
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 149
diff changeset
   401
290
3a2fa69ea675 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 289
diff changeset
   402
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
664
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   403
%\begin{frame}[c]
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   404
%\frametitle{Coursework: Nullable}
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   405
%
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   406
%\begin{center}
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   407
%\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   408
%  \bl{$nullable([c_1 c_2 \ldots c_n])$}  & \bl{$\dn$} & $?$\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   409
%  \bl{$nullable(r^+)$}                   & \bl{$\dn$} & $?$\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   410
%  \bl{$nullable(r^?)$}                   & \bl{$\dn$} & $?$\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   411
%  \bl{$nullable(r^{\{n\}})$}              & \bl{$\dn$} & $?$\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   412
%  \bl{$nullable(r^{\{n..\}})$}            & \bl{$\dn$} & $?$\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   413
%  \bl{$nullable(r^{\{..n\}})$}            & \bl{$\dn$} & $?$\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   414
%  \bl{$nullable(r^{\{n..m\}})$}           & \bl{$\dn$} & $?$\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   415
%  \bl{$nullable(\sim{}r)$}               & \bl{$\dn$} & $?$\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   416
%                                                        
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   417
%\end{tabular}
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   418
%\end{center}
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   419
%
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   420
%\end{frame}
290
3a2fa69ea675 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 289
diff changeset
   421
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 149
diff changeset
   422
528
68fab15cd6fb updated
cu
parents: 500
diff changeset
   423
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
664
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   424
%\begin{frame}[c]
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   425
%%%\frametitle{Coursework: der}
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   426
%
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   427
%\begin{center}
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   428
%\begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}}
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   429
%  \bl{$der\, c\, ([c_1 c_2 \ldots c_n])$}  & \bl{$\dn$} & $?$\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   430
%  \bl{$der\, c\, (r^+)$}                   & \bl{$\dn$} & $?$\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   431
%  \bl{$der\, c\, (r^?)$}                   & \bl{$\dn$} & $?$\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   432
%  \bl{$der\, c\, (r^{\{n\}})$}              & \bl{$\dn$} &
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   433
%     \bl{$if\;n=0\;then\;\ZERO\;else\;(der\,c\,r)\cdot r^{\{n-\liningnums{1}\}}$}\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   434
%  \bl{$der\, c\, (r^{\{n..\}})$}            & \bl{$\dn$} &
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   435
%     \bl{$if\;n=0\;then (der\,c\,r)\cdot r^*$}\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   436
%  & & \bl{$\phantom{if\;n=0\;}else \;(der\,c\,r)\cdot r^{\{n-\liningnums{1}..\}}$}\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   437
%  \bl{$der\, c\, (r^{\{..n\}})$}            & \bl{$\dn$} &
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   438
%     \bl{$if\;n=0\;then\;\ZERO\;else\;(der\,c\,r)\cdot r^{\{..n-\liningnums{1}\}}$}\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   439
%  
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   440
%  \bl{$der\, c\, (r^{\{n..m\}})$}          & \bl{$\dn$} &
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   441
%     \bl{$if\;n = 0 \wedge m = 0\;then\;\ZERO\; else$}\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   442
%  \multicolumn{3}{l}{\bl{$if\;n = 0 \wedge m > 0\;then\;(der\,c\,r)\cdot r^{\{..m-\liningnums{1}\}}$}}\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   443
%  \multicolumn{3}{l}{\bl{$\phantom{if\;n = 0 \wedge m > 0\;}else
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   444
%          \;(der\,c\,r)\cdot r^{\{n-\liningnums{1}..m-\liningnums{1}\}}$}}\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   445
%  \bl{$der\, c\, (\sim{}r)$}              & \bl{$\dn$} & $?$\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   446
%\end{tabular}
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   447
%\end{center}
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   448
%
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   449
%\end{frame}
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   450
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
528
68fab15cd6fb updated
cu
parents: 500
diff changeset
   451
664
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   452
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   453
%\begin{frame}[c]
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   454
%\frametitle{Coursework: CFUN}
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   455
%
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   456
%\begin{center}
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   457
%\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   458
%  \bl{$nullable(CFUN(\_))$}  & \bl{$\dn$} & \bl{$false$}\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   459
%  \bl{$der\,c\,(CFUN(f))$}   & \bl{$\dn$} &
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   460
%     \bl{$if\;f(c)\;then\;\ONE\;else\;\ZERO$}\bigskip\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   461
%  \bl{$CHAR(c)$}                   & \bl{$\dn$} & \bl{$CFUN(\lambda{}d.\;c=d)$}\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   462
%  \bl{$CSET([c_1,\ldots,c_n])$} & \bl{$\dn$} & \bl{$CFUN(\lambda{}d.\;d\in [c_1,\ldots,c_n])$}\\
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   463
%  \bl{$ALL$}                   & \bl{$\dn$} & \bl{$CFUN(\lambda{}d.\;true)$}\\                                                      
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   464
%\end{tabular}
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   465
%\end{center}
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   466
%
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   467
%\end{frame}
528
68fab15cd6fb updated
cu
parents: 500
diff changeset
   468
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
582
d236e75e1d55 updated
Christian Urban <urbanc@in.tum.de>
parents: 550
diff changeset
   469
 
528
68fab15cd6fb updated
cu
parents: 500
diff changeset
   470
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68fab15cd6fb updated
cu
parents: 500
diff changeset
   471
\begin{frame}[t]
68fab15cd6fb updated
cu
parents: 500
diff changeset
   472
\frametitle{Lexer, Parser}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   473
\mbox{}\\[-16mm]\mbox{}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   474
68fab15cd6fb updated
cu
parents: 500
diff changeset
   475
\begin{center}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   476
  \begin{tikzpicture}[scale=1,
68fab15cd6fb updated
cu
parents: 500
diff changeset
   477
                      node/.style={
68fab15cd6fb updated
cu
parents: 500
diff changeset
   478
                      rectangle,rounded corners=3mm,
68fab15cd6fb updated
cu
parents: 500
diff changeset
   479
                      very thick,draw=black!50,
68fab15cd6fb updated
cu
parents: 500
diff changeset
   480
                      minimum height=18mm, minimum width=20mm,
68fab15cd6fb updated
cu
parents: 500
diff changeset
   481
                      top color=white,bottom color=black!20}]
68fab15cd6fb updated
cu
parents: 500
diff changeset
   482
  \node (0) at (-2.3,0) {}; 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   483
  
68fab15cd6fb updated
cu
parents: 500
diff changeset
   484
  \node (A) at (0,0)  [node] {};
68fab15cd6fb updated
cu
parents: 500
diff changeset
   485
  \node [below right] at (A.north west) {lexer};
68fab15cd6fb updated
cu
parents: 500
diff changeset
   486
68fab15cd6fb updated
cu
parents: 500
diff changeset
   487
  \node (B) at (3,0)  [node] {};
68fab15cd6fb updated
cu
parents: 500
diff changeset
   488
  \node [below right=1mm] at (B.north west) 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   489
    {\mbox{}\hspace{-1mm}parser};
68fab15cd6fb updated
cu
parents: 500
diff changeset
   490
68fab15cd6fb updated
cu
parents: 500
diff changeset
   491
  \node (C) at (6,0)  [node] {};
68fab15cd6fb updated
cu
parents: 500
diff changeset
   492
  \node [below right] at (C.north west) 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   493
    {\mbox{}\hspace{-1mm}code gen};
68fab15cd6fb updated
cu
parents: 500
diff changeset
   494
68fab15cd6fb updated
cu
parents: 500
diff changeset
   495
  \node (1) at (8.4,0) {}; 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   496
68fab15cd6fb updated
cu
parents: 500
diff changeset
   497
  \draw [->,line width=4mm] (0) -- (A); 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   498
  \draw [->,line width=4mm] (A) -- (B); 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   499
  \draw [->,line width=4mm] (B) -- (C); 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   500
  \draw [->,line width=4mm] (C) -- (1); 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   501
  \end{tikzpicture}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   502
  \end{center}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   503
  
68fab15cd6fb updated
cu
parents: 500
diff changeset
   504
Today a parser.  
68fab15cd6fb updated
cu
parents: 500
diff changeset
   505
  
68fab15cd6fb updated
cu
parents: 500
diff changeset
   506
\end{frame}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   507
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   508
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   509
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   510
\begin{frame}[c]
550
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   511
\frametitle{What Parsing is Not}
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   512
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   513
Usually parsing does not check semantic correctness, e.g.
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   514
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   515
\begin{itemize}
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   516
\item  whether a function is not used before it
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   517
  is defined
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   518
\item whether a function has the correct number of arguments 
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   519
  or are of correct type
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   520
\item whether a variable can be declared twice in a scope  
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   521
\end{itemize}  
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   522
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   523
\end{frame}
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   524
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   525
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   526
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   527
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   528
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   529
\begin{frame}[c]
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   530
\frametitle{Regular Languages}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   531
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   532
While regular expressions are very useful for lexing, there is
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   533
no regular expression that can recognise the language
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   534
\bl{$a^nb^n$}.\bigskip
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   535
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   536
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   537
\bl{$(((()()))())$} \;\;vs.\;\; \bl{$(((()()))()))$}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   538
\end{center}\bigskip\bigskip
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   539
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   540
\small
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   541
\noindent So we cannot find out with regular expressions
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   542
whether parentheses are matched or unmatched. Also regular
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   543
expressions are not recursive, e.g.~\bl{$(1 + 2) + 3$}.
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   544
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   545
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   546
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   547
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   548
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   549
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   550
\frametitle{Hierarchy of Languages}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   551
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   552
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   553
\begin{tikzpicture}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   554
[rect/.style={draw=black!50, 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   555
              top color=white,
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   556
              bottom color=black!20, 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   557
              rectangle, 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   558
              very thick, 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   559
              rounded corners}, scale=1.2]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   560
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   561
\draw (0,0) node [rect, text depth=39mm, text width=68mm] {all languages};
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   562
\draw (0,-0.4) node [rect, text depth=28.5mm, text width=64mm] {decidable languages};
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   563
\draw (0,-0.85) node [rect, text depth=17mm] {context sensitive languages};
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   564
\draw (0,-1.14) node [rect, text depth=9mm, text width=50mm] {context-free languages};
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   565
\draw (0,-1.4) node [rect] {regular languages};
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   566
\end{tikzpicture}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   567
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   568
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   569
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   570
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   571
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   572
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   573
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   574
\begin{frame}[c]
360
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   575
\frametitle{CF Grammars}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   576
360
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   577
A \alert{\bf context-free grammar} \bl{$G$} consists of
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   578
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   579
\begin{itemize}
664
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   580
\item a finite set of nonterminal symbols (e.g.~$\meta{A}$ upper case)
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   581
\item a finite set terminal symbols or tokens (lower case)
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   582
\item a start symbol (which must be a nonterminal)
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   583
\item a set of rules
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   584
\begin{center}
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   585
\bl{$\meta{A} ::= \textit{rhs}$}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   586
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   587
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   588
where \bl{\textit{rhs}} are sequences involving terminals and nonterminals,
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   589
including the empty sequence \bl{$\epsilon$}.\medskip\pause
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   590
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   591
We also allow rules
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   592
\begin{center}
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   593
\bl{$\meta{A} ::= \textit{rhs}_1 | \textit{rhs}_2 | \ldots$}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   594
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   595
\end{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   596
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   597
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   598
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   599
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   600
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
582
d236e75e1d55 updated
Christian Urban <urbanc@in.tum.de>
parents: 550
diff changeset
   601
\begin{frame}[t]
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   602
\frametitle{Palindromes}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   603
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   604
A grammar for palindromes over the alphabet~\bl{$\{a,b\}$}:
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   605
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   606
\bl{\begin{plstx}[margin=3cm]
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   607
: \meta{S} ::= a\cdot\meta{S}\cdot a\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   608
: \meta{S} ::= b\cdot\meta{S}\cdot b\\
588
a4646557016d updated
Christian Urban <urbanc@in.tum.de>
parents: 583
diff changeset
   609
: \meta{S} ::= a\\
a4646557016d updated
Christian Urban <urbanc@in.tum.de>
parents: 583
diff changeset
   610
: \meta{S} ::= b\\
a4646557016d updated
Christian Urban <urbanc@in.tum.de>
parents: 583
diff changeset
   611
: \meta{S} ::= \epsilon\\
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   612
\end{plstx}}\pause
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   613
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   614
or
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   615
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   616
\bl{\begin{plstx}[margin=2cm]
588
a4646557016d updated
Christian Urban <urbanc@in.tum.de>
parents: 583
diff changeset
   617
: \meta{S} ::=  a\cdot \meta{S}\cdot a | b\cdot \meta{S}\cdot b | a | b | \epsilon\\
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   618
\end{plstx}}\pause\bigskip
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   619
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   620
\small
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   621
Can you find the grammar rules for matched parentheses?
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   622
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   623
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   624
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   625
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   626
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   627
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   628
\frametitle{Arithmetic Expressions}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   629
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   630
\bl{\begin{plstx}[margin=3cm,one per line]
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   631
: \meta{E} ::=  num\_token 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   632
   | \meta{E} \cdot + \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   633
   | \meta{E} \cdot - \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   634
   | \meta{E} \cdot * \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   635
   | ( \cdot \meta{E} \cdot ) \\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   636
\end{plstx}}\pause
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   637
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   638
\bl{\texttt{1 + 2 * 3 + 4}}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   639
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   640
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   641
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   642
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   643
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   644
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   645
\frametitle{A CFG Derivation}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   646
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   647
\begin{enumerate}
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   648
\item Begin with a string containing only the start symbol, say \bl{\meta{S}}\bigskip
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   649
\item Replace any nonterminal \bl{\meta{X}} in the string by the
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   650
right-hand side of some production \bl{$\meta{X} ::= \textit{rhs}$}\bigskip
582
d236e75e1d55 updated
Christian Urban <urbanc@in.tum.de>
parents: 550
diff changeset
   651
\item Repeat 2 until there are no nonterminals left
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   652
\end{enumerate}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   653
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   654
\begin{center}
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   655
\bl{$\meta{S} \rightarrow \ldots \rightarrow \ldots  \rightarrow \ldots  \rightarrow \ldots $}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   656
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   657
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   658
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   659
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   660
  
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   661
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   662
\begin{frame}[t]
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   663
\frametitle{Example Derivation}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   664
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   665
\bl{\begin{plstx}[margin=2cm]
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   666
: \meta{S} ::=  \epsilon | a\cdot \meta{S}\cdot a | b\cdot \meta{S}\cdot b \\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   667
\end{plstx}}\bigskip
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   668
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   669
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   670
\begin{tabular}{lcl}
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   671
\bl{\meta{S}} & \bl{$\rightarrow$} & \bl{$a\meta{S}a$}\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   672
              & \bl{$\rightarrow$} & \bl{$ab\meta{S}ba$}\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   673
              & \bl{$\rightarrow$} & \bl{$aba\meta{S}aba$}\\
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   674
              & \bl{$\rightarrow$} & \bl{$abaaba$}\\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   675
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   676
 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   677
\end{tabular}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   678
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   679
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   680
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   681
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   682
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   683
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   684
\begin{frame}[t]
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   685
\frametitle{Example Derivation}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   686
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   687
\bl{\begin{plstx}[margin=3cm,one per line]
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   688
: \meta{E} ::=  num\_token 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   689
   | \meta{E} \cdot + \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   690
   | \meta{E} \cdot - \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   691
   | \meta{E} \cdot * \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   692
   | ( \cdot \meta{E} \cdot ) \\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   693
\end{plstx}}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   694
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   695
\small
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   696
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   697
\begin{tabular}{@{}c@{}c@{}}
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   698
\begin{tabular}{@{\hspace{-2mm}}l@{\hspace{1mm}}l@{\hspace{1mm}}l@{\hspace{4mm}}}
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   699
\bl{\meta{E}} & \bl{$\rightarrow$} & \bl{$\meta{E}*\meta{E}$}\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   700
              & \bl{$\rightarrow$} & \bl{$\meta{E}+\meta{E}*\meta{E}$}\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   701
              & \bl{$\rightarrow$} & \bl{$\meta{E}+\meta{E}*\meta{E}+\meta{E}$}\\
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   702
              & \bl{$\rightarrow^+$} & \bl{$1+2*3+4$}\\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   703
\end{tabular} &\pause
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   704
\begin{tabular}{@{}l@{\hspace{0mm}}l@{\hspace{1mm}}l}
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   705
\bl{$\meta{E}$} & \bl{$\rightarrow$} & \bl{$\meta{E}+\meta{E}$}\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   706
                & \bl{$\rightarrow$} & \bl{$\meta{E}+\meta{E}+\meta{E}$}\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   707
                & \bl{$\rightarrow$} & \bl{$\meta{E}+\meta{E}*\meta{E}+\meta{E}$}\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   708
                & \bl{$\rightarrow^+$} & \bl{$1+2*3+4$}\\
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   709
\end{tabular}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   710
\end{tabular}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   711
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   712
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   713
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   714
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   715
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   716
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   717
\begin{frame}[c]
664
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   718
\frametitle{Context Sensitive Grammars}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   719
360
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   720
It is much harder to find out whether a string is parsed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   721
by a context sensitive grammar:
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   722
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   723
\bl{\begin{plstx}[margin=2cm]
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   724
: \meta{S} ::= b\meta{S}\meta{A}\meta{A} | \epsilon\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   725
: \meta{A} ::= a\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   726
: b\meta{A} ::= \meta{A}b\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   727
\end{plstx}}\pause
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   728
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   729
\begin{center}
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   730
\bl{$\meta{S} \rightarrow\ldots\rightarrow^? ababaa$}
665
6d74d2a0a4b0 updated
Christian Urban <urbanc@in.tum.de>
parents: 664
diff changeset
   731
\end{center}\pause
6d74d2a0a4b0 updated
Christian Urban <urbanc@in.tum.de>
parents: 664
diff changeset
   732
6d74d2a0a4b0 updated
Christian Urban <urbanc@in.tum.de>
parents: 664
diff changeset
   733
\begin{center}
6d74d2a0a4b0 updated
Christian Urban <urbanc@in.tum.de>
parents: 664
diff changeset
   734
  \tt Time flies like an arrow;\\ 
6d74d2a0a4b0 updated
Christian Urban <urbanc@in.tum.de>
parents: 664
diff changeset
   735
  fruit flies like bananas.
6d74d2a0a4b0 updated
Christian Urban <urbanc@in.tum.de>
parents: 664
diff changeset
   736
  \end{center}  
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   737
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   738
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   739
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   740
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   741
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   742
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   743
\frametitle{Language of a CFG}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   744
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   745
Let \bl{$G$} be a context-free grammar with start symbol \bl{\meta{S}}. 
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   746
Then the language \bl{$L(G)$} is:
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   747
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   748
\begin{center}
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   749
\bl{$\{c_1\ldots c_n \;|\; \forall i.\; c_i \in T \wedge \meta{S} \rightarrow^* c_1\ldots c_n \}$}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   750
\end{center}\pause
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   751
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   752
\begin{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   753
\item Terminals, because there are no rules for replacing them.
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   754
\item Once generated, terminals are ``permanent''.
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   755
\item Terminals ought to be tokens of the language\\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   756
(but can also be strings).
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   757
\end{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   758
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   759
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   760
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   761
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   762
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   763
\begin{frame}[t]
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   764
\frametitle{Parse Trees}
582
d236e75e1d55 updated
Christian Urban <urbanc@in.tum.de>
parents: 550
diff changeset
   765
\mbox{}\\[-12mm]
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   766
593
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 588
diff changeset
   767
\bl{\begin{plstx}: \meta{E} ::= \meta{T} | \meta{T} \cdot + \cdot \meta{E} |  \meta{T} \cdot - \cdot \meta{E}\\
529
5c28e4134ee1 updated
cu
parents: 528
diff changeset
   768
: \meta{T} ::= \meta{F} | \meta{F} \cdot * \cdot \meta{T}\\
5c28e4134ee1 updated
cu
parents: 528
diff changeset
   769
: \meta{F} ::= num\_token | ( \cdot \meta{E} \cdot )\\
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   770
\end{plstx}}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   771
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   772
\begin{center}\small
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   773
\begin{tikzpicture}[level distance=8mm, blue]
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   774
  \node {$\meta{E}$}
529
5c28e4134ee1 updated
cu
parents: 528
diff changeset
   775
    child {node {$\meta{T}$} 
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   776
     child {node {$\meta{T}$} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   777
                 child {node {(\,$\meta{E}$\,)}
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   778
                            child {node{$\meta{F}$ *{} $\meta{F}$}
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   779
                                  child {node {$\meta{T}$} child {node {2}}}
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   780
                                  child {node {$\meta{T}$} child {node {3}}} 
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   781
                               }
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   782
                          }
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   783
              }
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   784
     child {node {+}}
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   785
     child {node {$\meta{T}$}
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   786
       child {node {(\,$\meta{E}$\,)} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   787
       child {node {$\meta{F}$}
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   788
       child {node {$\meta{T}$ +{} $\meta{T}$}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   789
                    child {node {3}}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   790
                    child {node {4}} 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   791
                 }
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   792
                 }}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   793
    }};
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   794
\end{tikzpicture}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   795
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   796
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   797
\begin{textblock}{5}(1, 6.5)
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   798
\bl{\texttt{(2*3)+(3+4)}}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   799
\end{textblock}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   800
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   801
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   802
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   803
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   804
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   805
\begin{frame}[t]
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   806
\frametitle{Arithmetic Expressions}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   807
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   808
\bl{\begin{plstx}[margin=3cm,one per line]
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   809
: \meta{E} ::=  num\_token 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   810
   | \meta{E} \cdot + \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   811
   | \meta{E} \cdot - \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   812
   | \meta{E} \cdot * \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   813
   | ( \cdot \meta{E} \cdot ) \\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   814
\end{plstx}}\pause\bigskip
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   815
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   816
A CFG is \alert{\bf left-recursive} if it has a nonterminal \bl{$\meta{E}$} such
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   817
that \bl{$\meta{E} \rightarrow^+ \meta{E}\cdot \ldots$}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   818
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   819
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   820
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   821
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   822
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   823
\begin{frame}[t]
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   824
\frametitle{Ambiguous Grammars}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   825
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   826
A grammar is \alert{\bf ambiguous} if there is a string that
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   827
has at least two different parse trees.
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   828
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   829
\bl{\begin{plstx}[margin=3cm,one per line]: \meta{E} ::=  num\_token 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   830
   | \meta{E} \cdot + \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   831
   | \meta{E} \cdot - \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   832
   | \meta{E} \cdot * \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   833
   | ( \cdot \meta{E} \cdot ) \\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   834
\end{plstx}}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   835
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   836
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   837
\bl{\texttt{1 + 2 * 3 + 4}}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   838
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   839
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   840
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   841
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   842
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   843
\begin{frame}[c]
582
d236e75e1d55 updated
Christian Urban <urbanc@in.tum.de>
parents: 550
diff changeset
   844
\frametitle{`Dangling' Else}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   845
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   846
Another ambiguous grammar:\bigskip
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   847
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   848
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   849
\bl{\begin{tabular}{lcl}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   850
$E$ & $\rightarrow$ &  if $E$ then $E$\\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   851
 & $|$ &  if $E$ then $E$ else $E$ \\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   852
 & $|$ &  \ldots
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   853
\end{tabular}}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   854
\end{center}\bigskip
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   855
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   856
\bl{\texttt{if a then if x then y else c}}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   857
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   858
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   859
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   860
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   861
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   862
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   863
\frametitle{Parser Combinators}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   864
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   865
One of the simplest ways to implement a parser, see
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   866
{\small\url{https://vimeo.com/142341803}}\bigskip
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   867
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   868
Parser combinators: \bigskip
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   869
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   870
\begin{minipage}{1.1\textwidth}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   871
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   872
\mbox{}\hspace{-12mm}\mbox{}$\underbrace{\text{list of tokens}}_{\text{input}}$ \bl{$\Rightarrow$} 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   873
$\underbrace{\text{set of (parsed input, unparsed input)}}_{\text{output}}$
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   874
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   875
\end{minipage}\bigskip
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   876
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   877
\begin{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   878
\item atomic parsers
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   879
\item sequencing
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   880
\item alternative
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   881
\item semantic action
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   882
\end{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   883
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   884
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   885
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   886
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   887
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   888
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   889
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   890
Atomic parsers, for example, number tokens
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   891
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   892
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   893
\bl{$\texttt{Num(123)}::rest \;\Rightarrow\; \{(\texttt{Num(123)}, rest)\}$} 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   894
\end{center}\bigskip
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   895
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   896
\begin{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   897
\item you consume one or more token from the\\ 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   898
  input (stream)
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   899
\item also works for characters and strings
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   900
\end{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   901
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   902
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   903
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   904
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   905
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   906
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   907
Alternative parser (code \bl{$p\;||\;q$})\bigskip
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   908
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   909
\begin{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   910
\item apply \bl{$p$} and also \bl{$q$}; then combine 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   911
  the outputs
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   912
\end{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   913
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   914
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   915
\large \bl{$p(\text{input}) \cup q(\text{input})$}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   916
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   917
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   918
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   919
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   920
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   921
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   922
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   923
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   924
Sequence parser (code \bl{$p\sim q$})\bigskip
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   925
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   926
\begin{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   927
\item apply first \bl{$p$} producing a set of pairs
528
68fab15cd6fb updated
cu
parents: 500
diff changeset
   928
\item then apply \bl{$q$} to the unparsed part
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   929
\item then combine the results:\medskip 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   930
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   931
((output$_1$, output$_2$), unparsed part)
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   932
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   933
\end{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   934
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   935
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   936
\begin{tabular}{l}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   937
\large \bl{$\{((o_1, o_2), u_2) \;|\;$}\\[2mm] 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   938
\large\mbox{}\hspace{15mm} \bl{$(o_1, u_1) \in p(\text{input}) \wedge$}\\[2mm]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   939
\large\mbox{}\hspace{15mm} \bl{$(o_2, u_2) \in q(u_1)\}$}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   940
\end{tabular}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   941
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   942
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   943
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   944
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   945
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   946
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   947
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   948
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   949
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   950
Function parser (code \bl{$p \Rightarrow f\;$})\bigskip
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   951
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   952
\begin{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   953
\item apply \bl{$p$} producing a set of pairs
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   954
\item then apply the function \bl{$f$} to each first component
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   955
\end{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   956
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   957
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   958
\begin{tabular}{l}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   959
\large \bl{$\{(f(o_1), u_1) \;|\; (o_1, u_1) \in p(\text{input})\}$}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   960
\end{tabular}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   961
\end{center}\bigskip\bigskip\pause
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   962
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   963
\bl{$f$} is the semantic action (``what to do with the parsed input'')
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   964
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   965
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   966
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   967
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   968
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   969
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   970
\mode<presentation>{
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   971
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   972
\frametitle{\begin{tabular}{c}Semantic Actions\end{tabular}}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   973
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   974
Addition
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   975
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   976
\begin{center}
582
d236e75e1d55 updated
Christian Urban <urbanc@in.tum.de>
parents: 550
diff changeset
   977
\bl{$\meta{T} \sim + \sim \meta{E} \Rightarrow \underbrace{f\,((x,y), z) \Rightarrow x + z}_{\text{semantic action}}$}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   978
\end{center}\pause
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   979
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   980
Multiplication
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   981
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   982
\begin{center}
582
d236e75e1d55 updated
Christian Urban <urbanc@in.tum.de>
parents: 550
diff changeset
   983
\bl{$\meta{F} \sim * \sim \meta{T} \Rightarrow f\,((x,y), z) \Rightarrow x * z$}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   984
\end{center}\pause
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   985
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   986
Parenthesis
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   987
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   988
\begin{center}
582
d236e75e1d55 updated
Christian Urban <urbanc@in.tum.de>
parents: 550
diff changeset
   989
\bl{$\text{(} \sim \meta{E} \sim \text{)} \Rightarrow f\,((x,y), z) \Rightarrow y$}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   990
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   991
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   992
\end{frame}}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   993
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   994
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   995
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   996
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   997
\frametitle{Types of Parsers}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   998
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   999
\begin{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1000
\item {\bf Sequencing}: if \bl{$p$} returns results of type \bl{$T$}, and \bl{$q$} results of type \bl{$S$},
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1001
then \bl{$p \sim q$} returns results of type
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1002
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1003
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1004
\bl{$T \times S$}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1005
\end{center}\pause
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1006
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1007
\item {\bf Alternative}: if \bl{$p$} returns results of type \bl{$T$} then  \bl{$q$} \alert{must} also have results of type \bl{$T$},
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1008
and \bl{$p \;||\; q$} returns results of type
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1009
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1010
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1011
\bl{$T$}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1012
\end{center}\pause
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1013
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1014
\item {\bf Semantic Action}: if \bl{$p$} returns results of type \bl{$T$} and \bl{$f$} is a function from
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1015
\bl{$T$} to \bl{$S$}, then
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1016
\bl{$p \Rightarrow f$} returns results of type
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1017
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1018
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1019
\bl{$S$}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1020
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1021
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1022
\end{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1023
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1024
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1025
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1026
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1027
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1028
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1029
\frametitle{Input Types of Parsers}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1030
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1031
\begin{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1032
\item input: \alert{token list}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1033
\item output: set of (output\_type, \alert{token list})
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1034
\end{itemize}\bigskip\pause
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1035
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1036
actually it can be any input type as long as it is a kind of
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1037
sequence (for example a string)
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1038
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1039
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1040
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1041
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1042
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1043
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1044
\frametitle{Scannerless Parsers}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1045
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1046
\begin{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1047
\item input: \alert{string}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1048
\item output: set of (output\_type, \alert{string})
664
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
  1049
\end{itemize}\bigskip\bigskip
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1050
664
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
  1051
but using lexers is better because whitespaces or comments can be
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1052
filtered out; then input is a sequence of tokens
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1053
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1054
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1055
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1056
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1057
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1058
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1059
\frametitle{Successful Parses}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1060
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1061
\begin{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1062
\item input: string
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1063
\item output: \alert{set of} (output\_type, string)
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1064
\end{itemize}\bigskip
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1065
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1066
a parse is successful whenever the input has been fully
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1067
``consumed'' (that is the second component is empty)
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1068
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1069
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1070
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1071
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1072
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1073
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1074
\frametitle{Abstract Parser Class}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1075
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1076
\small
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1077
\lstinputlisting[language=Scala,xleftmargin=1mm]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1078
 {../progs/app7.scala}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1079
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1080
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1081
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1082
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1083
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1084
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1085
\small
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1086
\fontsize{10}{12}\selectfont
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1087
\lstinputlisting[language=Scala,xleftmargin=1mm]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1088
  {../progs/app8.scala}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1089
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1090
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1091
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1092
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1093
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1094
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1095
\frametitle{Two Grammars}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1096
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1097
Which languages are recognised by the following two grammars?
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1098
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1099
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1100
\bl{\begin{tabular}{lcl}
582
d236e75e1d55 updated
Christian Urban <urbanc@in.tum.de>
parents: 550
diff changeset
  1101
$\meta{S}$ & $\rightarrow$ &  $1 \cdot \meta{S} \cdot \meta{S}$\\
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1102
        & $|$ & $\epsilon$
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1103
\end{tabular}}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1104
\end{center}\bigskip
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1105
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1106
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1107
\bl{\begin{tabular}{lcl}
582
d236e75e1d55 updated
Christian Urban <urbanc@in.tum.de>
parents: 550
diff changeset
  1108
$\meta{U}$ & $\rightarrow$ &  $1 \cdot \meta{U}$\\
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1109
        & $|$ & $\epsilon$
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1110
\end{tabular}}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1111
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1112
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1113
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1114
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1115
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1116
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1117
\begin{frame}[t]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1118
\frametitle{Ambiguous Grammars}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1119
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1120
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1121
\begin{tikzpicture}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1122
\begin{axis}[xlabel={\pcode{1}s},ylabel={time in secs},
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1123
    enlargelimits=false,
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1124
    xtick={0,100,...,1000},
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1125
    xmax=1050,
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1126
    ymax=33,
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1127
    ytick={0,5,...,30},
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1128
    scaled ticks=false,
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1129
    axis lines=left,
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1130
    width=11cm,
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1131
    height=7cm, 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1132
    legend entries={unambiguous,ambiguous},  
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1133
    legend pos=north east,
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1134
    legend cell align=left,
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1135
    x tick label style={font=\small,/pgf/number format/1000 sep={}}]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1136
\addplot[blue,mark=*, mark options={fill=white}] 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1137
  table {s-grammar1.data};
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1138
\only<2>{
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1139
  \addplot[red,mark=triangle*, mark options={fill=white}] 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1140
  table {s-grammar2.data};}  
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1141
\end{axis}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1142
\end{tikzpicture}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1143
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1144
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1145
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1146
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1147
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1148
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1149
\begin{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1150
\frametitle{While-Language}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1151
\mbox{}\\[-23mm]\mbox{}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1152
370
a65767fe5d71 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 361
diff changeset
  1153
\bl{\begin{plstx}[rhs style=,one per line]: \meta{Stmt} ::= skip
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1154
         | \meta{Id} := \meta{AExp}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1155
         | if \meta{BExp} then \meta{Block} else \meta{Block}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1156
         | while \meta{BExp} do \meta{Block}\\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1157
: \meta{Stmts} ::= \meta{Stmt} ; \meta{Stmts}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1158
          | \meta{Stmt}\\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1159
: \meta{Block} ::= \{ \meta{Stmts} \}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1160
          | \meta{Stmt}\\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1161
: \meta{AExp} ::= \ldots\\
370
a65767fe5d71 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 361
diff changeset
  1162
: \meta{BExp} ::= \ldots\\\end{plstx}}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1163
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1164
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1165
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1166
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1167
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1168
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1169
\frametitle{An Interpreter}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1170
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1171
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1172
\bl{\begin{tabular}{l}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1173
$\{$\\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1174
\;\;$x := 5 \text{;}$\\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1175
\;\;$y := x * 3\text{;}$\\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1176
\;\;$y := x * 4\text{;}$\\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1177
\;\;$x := u * 3$\\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1178
$\}$
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1179
\end{tabular}}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1180
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1181
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1182
\begin{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1183
\item the interpreter has to record the value of \bl{$x$} before assigning a value to \bl{$y$}\pause
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1184
\item \bl{\texttt{eval(stmt, env)}}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1185
\end{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1186
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1187
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1188
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1189
465
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1190
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1191
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1192
\mode<presentation>{
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1193
\begin{frame}[c]
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1194
\frametitle{\begin{tabular}{c}Interpreter\end{tabular}}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1195
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1196
\begin{center}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1197
\bl{\begin{tabular}{@{}lcl@{}}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1198
$\text{eval}(n, E)$ & $\dn$ & $n$\\
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1199
$\text{eval}(x, E)$ & $\dn$ & $E(x)$ \;\;\;\textcolor{black}{lookup \bl{$x$} in \bl{$E$}}\\
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1200
$\text{eval}(a_1 + a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) + \text{eval}(a_2, E)$\\
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1201
$\text{eval}(a_1 - a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) - \text{eval}(a_2, E)$\\
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1202
$\text{eval}(a_1 * a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) * \text{eval}(a_2, E)$\bigskip\\
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1203
$\text{eval}(a_1 = a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) = \text{eval}(a_2, E)$\\
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1204
$\text{eval}(a_1\,!\!= a_2, E)$ & $\dn$ & $\neg(\text{eval}(a_1, E) = \text{eval}(a_2, E))$\\
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1205
$\text{eval}(a_1 < a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) < \text{eval}(a_2, E)$\
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1206
\end{tabular}}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1207
\end{center}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1208
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1209
\end{frame}}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1210
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1211
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1212
\mode<presentation>{
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1213
\begin{frame}[c]
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1214
\frametitle{\begin{tabular}{c}Interpreter (2)\end{tabular}}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1215
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1216
\begin{center}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1217
\bl{\begin{tabular}{@{}lcl@{}}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1218
$\text{eval}(\text{skip}, E)$ & $\dn$ & $E$\\
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1219
$\text{eval}(x:=a, E)$ & $\dn$ & \bl{$E(x \mapsto \text{eval}(a, E))$}\\
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1220
\multicolumn{3}{@{}l@{}}{$\text{eval}(\text{if}\;b\;\text{then}\;cs_1\;\text{else}\;cs_2 , E) \dn$}\\
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1221
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)\;\text{then}\;
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1222
\text{eval}(cs_1,E)$}\\
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1223
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\phantom{\text{if}\;\text{eval}(b,E)\;}\text{else}\;\text{eval}(cs_2,E)$}\\
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1224
\multicolumn{3}{@{}l@{}}{$\text{eval}(\text{while}\;b\;\text{do}\;cs, E) \dn$}\\
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1225
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)$}\\
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1226
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{then}\;
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1227
\text{eval}(\text{while}\;b\;\text{do}\;cs, \text{eval}(cs,E))$}\\
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1228
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{else}\; E$}\\
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1229
$\text{eval}(\text{write}\; x, E)$ & $\dn$ & $\{\;\text{println}(E(x))\; ;\;E\;\}$\\
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1230
\end{tabular}}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1231
\end{center}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1232
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1233
\end{frame}}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1234
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1235
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1236
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1237
\begin{frame}[c]
582
d236e75e1d55 updated
Christian Urban <urbanc@in.tum.de>
parents: 550
diff changeset
  1238
\frametitle{Test Program}
465
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1239
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1240
\mbox{}\\[-18mm]\mbox{}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1241
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1242
{\lstset{language=While}%%\fontsize{10}{12}\selectfont
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1243
\texttt{\lstinputlisting{../progs/loops.while}}}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1244
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1245
\end{frame}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1246
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1247
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1248
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1249
\mode<presentation>{
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1250
\begin{frame}[t]
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1251
\frametitle{\begin{tabular}{c}Interpreted Code\end{tabular}}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1252
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1253
\begin{center}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1254
\begin{tikzpicture}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1255
\begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small]
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1256
\addplot+[smooth] file {interpreted.data};
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1257
\end{axis}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1258
\end{tikzpicture}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1259
\end{center}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1260
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1261
\end{frame}}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1262
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1263
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1264
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1265
\mode<presentation>{
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1266
\begin{frame}[c]
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1267
\frametitle{\begin{tabular}{c}Java Virtual Machine\end{tabular}}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1268
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1269
\begin{itemize}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1270
\item introduced in 1995
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1271
\item is a stack-based VM (like Postscript, CLR of .Net)
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1272
\item contains a JIT compiler
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1273
\item many languages take advantage of JVM's infrastructure (JRE)
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1274
\item is garbage collected $\Rightarrow$ no buffer overflows
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1275
\item some languages compile to the JVM: Scala, Clojure\ldots
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1276
\end{itemize}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1277
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1278
\end{frame}}
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
  1279
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1280
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
  1281
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1282
\end{document}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1283
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1284
%%% Local Variables:  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1285
%%% mode: latex
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1286
%%% TeX-master: t
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1287
%%% End: 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
  1288