slides/slides05.tex
author Christian Urban <christian.urban@kcl.ac.uk>
Fri, 11 Oct 2024 19:13:00 +0100
changeset 967 ce5de01b9632
parent 945 5070392a1bd7
child 971 51e00f223792
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
743
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
     3
\documentclass[dvipsnames,14pt,t,xelatex,aspectratio=169,xcolor={table}]{beamer}
270
4dbeaf43031d updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
     4
\usepackage{../slides}
871
94b84d880c2b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 849
diff changeset
     5
\usepackage{../graphicss}
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
796
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
    19
\usepackage{tcolorbox}
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
    20
\newtcolorbox{mybox}{colback=red!5!white,colframe=red!75!black}
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
    21
\newtcolorbox{mybox2}[1]{colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries,title=#1}
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
    22
\newtcolorbox{mybox3}[1]{colback=Cyan!5!white,colframe=Cyan!75!black,fonttitle=\bfseries,title=#1}
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
    23
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
    24
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
\begin{document}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
270
4dbeaf43031d updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    29
\begin{frame}[t]
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
\frametitle{%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
  \begin{tabular}{@ {}c@ {}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
  \\[-3mm]
893
54a483a33763 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
    33
  \LARGE Compilers and \\[-1mm] 
54a483a33763 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
    34
  \LARGE Formal Languages\\[-5mm] 
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
  \end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
  \normalsize
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
  \begin{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
  \begin{tabular}{ll}
893
54a483a33763 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
    40
  Email:  & christian.urban at kcl.ac.uk\\
940
46eee459a999 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 893
diff changeset
    41
Office Hour: & Thurdays 15 -- 16\\  
893
54a483a33763 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
    42
  Location: & N7.07 (North Wing, Bush House)\\
54a483a33763 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
    43
  Slides \& Progs: & KEATS\\
54a483a33763 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
    44
  Pollev: & \texttt{\alert{https://pollev.com/cfltutoratki576}}\\  
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
  \end{tabular}
893
54a483a33763 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
    46
  \end{center}
743
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    47
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    48
  \begin{center}
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    49
    \begin{tikzpicture}
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    50
      \node[drop shadow,fill=white,inner sep=0pt] 
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    51
      {\footnotesize\rowcolors{1}{capri!10}{white}
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    52
        \begin{tabular}{|p{4.8cm}|p{4.8cm}|}\hline
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    53
          1 Introduction, Languages          & 6 While-Language \\
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    54
          2 Regular Expressions, Derivatives & 7 Compilation, JVM \\
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    55
          3 Automata, Regular Languages      & 8 Compiling Functional Languages \\
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    56
          4 Lexing, Tokenising               & 9 Optimisations \\
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    57
          \cellcolor{blue!50}
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    58
          5 Grammars, Parsing                & 10 LLVM \\ \hline
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    59
        \end{tabular}%
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    60
      };
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    61
    \end{tikzpicture}
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
  \end{center}
270
4dbeaf43031d updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    63
\end{frame}
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    64
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
667
412556272333 updated
Christian Urban <urbanc@in.tum.de>
parents: 666
diff changeset
    66
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
743
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    67
%\begin{frame}[c]
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    68
%  \frametitle{Coursework 1: Submissions}
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    69
%  
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    70
%  \begin{itemize}
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    71
%  \item Scala (29)
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    72
%  \item Haskell (1)
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    73
%  \item Kotlin (1)
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    74
%  \item Rust (1)
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    75
%  \end{itemize}\bigskip\bigskip  
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    76
%  
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    77
%  \small
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    78
%  Please get in contact if you intend to do CW Strand 2. No zips please.
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    79
%  Give definitions also on paper if asked. BTW, simp 
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    80
%  can stay unchanged. Use \texttt{ders} for CW2, not \texttt{ders2}!
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    81
%  \end{frame}
289
c22c8baff491 updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 272
diff changeset
    82
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
945
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    83
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    84
{
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    85
\setbeamercolor{background canvas}{bg=cream}
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    86
\begin{frame}<1-10>[c]
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    87
\end{frame}
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    88
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    89
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    90
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    91
\begin{frame}[c]
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    92
  \frametitle{Coursework 1: Submissions}
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    93
  
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    94
  \begin{itemize}
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    95
  \item Scala (162)
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    96
  \item Ocaml (1)
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    97
  \item Java (1)  \ldots uses new features of Java 21  
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    98
  \item Rust (6)
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    99
  \end{itemize}\bigskip\bigskip  
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   100
  
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   101
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   102
\end{frame}
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   103
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   104
}
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   105
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   106
528
68fab15cd6fb updated
cu
parents: 500
diff changeset
   107
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68fab15cd6fb updated
cu
parents: 500
diff changeset
   108
\begin{frame}[t]
795
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   109
\frametitle{Parser}
528
68fab15cd6fb updated
cu
parents: 500
diff changeset
   110
\mbox{}\\[-16mm]\mbox{}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   111
68fab15cd6fb updated
cu
parents: 500
diff changeset
   112
\begin{center}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   113
  \begin{tikzpicture}[scale=1,
68fab15cd6fb updated
cu
parents: 500
diff changeset
   114
                      node/.style={
68fab15cd6fb updated
cu
parents: 500
diff changeset
   115
                      rectangle,rounded corners=3mm,
68fab15cd6fb updated
cu
parents: 500
diff changeset
   116
                      very thick,draw=black!50,
68fab15cd6fb updated
cu
parents: 500
diff changeset
   117
                      minimum height=18mm, minimum width=20mm,
743
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
   118
                      top color=white,bottom color=black!20,drop shadow}]
528
68fab15cd6fb updated
cu
parents: 500
diff changeset
   119
  \node (0) at (-2.3,0) {}; 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   120
  
68fab15cd6fb updated
cu
parents: 500
diff changeset
   121
  \node (A) at (0,0)  [node] {};
68fab15cd6fb updated
cu
parents: 500
diff changeset
   122
  \node [below right] at (A.north west) {lexer};
68fab15cd6fb updated
cu
parents: 500
diff changeset
   123
68fab15cd6fb updated
cu
parents: 500
diff changeset
   124
  \node (B) at (3,0)  [node] {};
68fab15cd6fb updated
cu
parents: 500
diff changeset
   125
  \node [below right=1mm] at (B.north west) 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   126
    {\mbox{}\hspace{-1mm}parser};
68fab15cd6fb updated
cu
parents: 500
diff changeset
   127
68fab15cd6fb updated
cu
parents: 500
diff changeset
   128
  \node (C) at (6,0)  [node] {};
68fab15cd6fb updated
cu
parents: 500
diff changeset
   129
  \node [below right] at (C.north west) 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   130
    {\mbox{}\hspace{-1mm}code gen};
68fab15cd6fb updated
cu
parents: 500
diff changeset
   131
68fab15cd6fb updated
cu
parents: 500
diff changeset
   132
  \node (1) at (8.4,0) {}; 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   133
68fab15cd6fb updated
cu
parents: 500
diff changeset
   134
  \draw [->,line width=4mm] (0) -- (A); 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   135
  \draw [->,line width=4mm] (A) -- (B); 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   136
  \draw [->,line width=4mm] (B) -- (C); 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   137
  \draw [->,line width=4mm] (C) -- (1); 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   138
  \end{tikzpicture}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   139
  \end{center}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   140
  
795
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   141
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   142
\only<2>{
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   143
\begin{textblock}{1}(3,6)
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   144
\begin{bubble}[8.5cm]
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   145
\normalsize
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   146
parser input: a sequence of tokens\smallskip\\
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   147
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   148
{\small\hspace{5mm}\code{key(read) lpar id(n) rpar semi}}\smallskip\\
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   149
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   150
parser output: an abstract syntax tree\smallskip\\
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   151
\footnotesize
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   152
\hspace{2cm}\begin{tikzpicture}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   153
  \node {\code{read}}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   154
    child {node {\code{lpar}}}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   155
    child {node {\code{n}}}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   156
    child {node {\code{rpar}}};
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   157
\end{tikzpicture}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   158
\end{bubble}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   159
\end{textblock}}
528
68fab15cd6fb updated
cu
parents: 500
diff changeset
   160
\end{frame}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   161
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   162
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   163
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   164
\begin{frame}[c]
550
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   165
\frametitle{What Parsing is Not}
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   166
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   167
Usually parsing does not check semantic correctness, e.g.
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   168
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   169
\begin{itemize}
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   170
\item  whether a function is not used before it
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   171
  is defined
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   172
\item whether a function has the correct number of arguments 
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   173
  or are of correct type
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   174
\item whether a variable can be declared twice in a scope  
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   175
\end{itemize}  
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   176
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   177
\end{frame}
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   178
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   179
945
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   180
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   181
{
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   182
\setbeamercolor{background canvas}{bg=cream}
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   183
\begin{frame}[c]
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   184
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   185
\begin{center}
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   186
\begin{tikzpicture}[scale=1.5,>=stealth',very thick,
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   187
                    every state/.style={minimum size=0pt,
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   188
                    draw=blue!50,very thick,fill=blue!20}]
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   189
  \node[state,initial]   (q0) at (0,2) {$q_0$};
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   190
  \node[state,accepting] (q1) at (2,2) {$q_1$};
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   191
  \node[state]           (q2) at (0,0) {$q_2$};
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   192
  \node[state]           (q3) at (2,0) {$q_3$};
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   193
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   194
  \path[->] (q0) edge[bend left] node[above] {\alert{$a$}} (q1)
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   195
            (q1) edge[bend left] node[above] {\alert{$a$}} (q0)
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   196
            (q2) edge[bend left] node[above] {\alert{$a$}} (q3)
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   197
            (q3) edge[bend left] node[above] {\alert{$a$}} (q2)
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   198
            (q0) edge[bend left] node[right] {\alert{$b$}} (q2)
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   199
            (q2) edge[bend left] node[left]  {\alert{$b$}} (q0)
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   200
            (q1) edge[bend left] node[right] {\alert{$b$}} (q3)
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   201
            (q3) edge[bend left] node[left]  {\alert{$b$}} (q1);
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   202
\end{tikzpicture}
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   203
\end{center}
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   204
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   205
\hfill{}Which language?
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   206
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   207
\end{frame}
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   208
}
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   209
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
550
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   210
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   211
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   212
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   213
\begin{frame}[c]
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   214
\frametitle{Regular Languages}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   215
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   216
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
   217
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
   218
\bl{$a^nb^n$}.\bigskip
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   219
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   220
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   221
\bl{$(((()()))())$} \;\;vs.\;\; \bl{$(((()()))()))$}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   222
\end{center}\bigskip\bigskip
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   223
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   224
\small
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   225
\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
   226
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
   227
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
   228
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   229
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   230
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   231
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   232
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   233
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   234
\frametitle{Hierarchy of Languages}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   235
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   236
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   237
\begin{tikzpicture}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   238
[rect/.style={draw=black!50, 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   239
              top color=white,
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   240
              bottom color=black!20, 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   241
              rectangle, 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   242
              very thick, 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   243
              rounded corners}, scale=1.2]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   244
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   245
\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
   246
\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
   247
\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
   248
\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
   249
\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
   250
\end{tikzpicture}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   251
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   252
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   253
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   254
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   255
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   256
795
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   257
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   258
\begin{frame}[c]
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   259
  \LARGE
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   260
  \begin{center}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   261
  Time flies like an arrow.\\ 
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   262
  Fruit flies like bananas.
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   263
  \end{center}  
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   264
\end{frame}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   265
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   266
  
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   267
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   268
\begin{frame}[c]
792
34132a854d03 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 743
diff changeset
   269
\frametitle{CFGs}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   270
360
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   271
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
   272
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   273
\begin{itemize}
664
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   274
\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
   275
\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
   276
\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
   277
\item a set of rules
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   278
\begin{center}
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   279
\bl{$\meta{A} ::= \textit{rhs}$}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   280
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   281
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   282
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
   283
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
   284
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   285
We also allow rules
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   286
\begin{center}
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   287
\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
   288
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   289
\end{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   290
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   291
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   292
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   293
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   294
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
582
d236e75e1d55 updated
Christian Urban <urbanc@in.tum.de>
parents: 550
diff changeset
   295
\begin{frame}[t]
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   296
\frametitle{Palindromes}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   297
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   298
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
   299
795
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   300
\only<1>{%
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   301
\bl{\begin{plstx}[margin=1cm]
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   302
: \meta{S} ::= a\cdot\meta{S}\cdot a\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   303
: \meta{S} ::= b\cdot\meta{S}\cdot b\\
588
a4646557016d updated
Christian Urban <urbanc@in.tum.de>
parents: 583
diff changeset
   304
: \meta{S} ::= a\\
a4646557016d updated
Christian Urban <urbanc@in.tum.de>
parents: 583
diff changeset
   305
: \meta{S} ::= b\\
a4646557016d updated
Christian Urban <urbanc@in.tum.de>
parents: 583
diff changeset
   306
: \meta{S} ::= \epsilon\\
795
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   307
\end{plstx}}}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   308
%
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   309
\only<2>{%
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   310
\bl{\begin{plstx}[margin=1cm]
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   311
: \meta{S} ::=  a\cdot \meta{S}\cdot a | b\cdot \meta{S}\cdot b | a | b | \epsilon\\
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   312
\end{plstx}}}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   313
795
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   314
%\small
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   315
%Can you find the grammar rules for matched parentheses?
358
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
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   318
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   319
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   320
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   321
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   322
\frametitle{Arithmetic Expressions}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   323
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   324
\bl{\begin{plstx}[margin=3cm,one per line]
795
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   325
: \meta{E} ::=  0 \mid 1 \mid 2 \mid ... \mid 9
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   326
   | \meta{E} \cdot + \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   327
   | \meta{E} \cdot - \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   328
   | \meta{E} \cdot * \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   329
   | ( \cdot \meta{E} \cdot ) \\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   330
\end{plstx}}\pause
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   331
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   332
\bl{\texttt{1 + 2 * 3 + 4}}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   333
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   334
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   335
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   338
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   339
\frametitle{A CFG Derivation}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   340
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   341
\begin{enumerate}
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   342
\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
   343
\item Replace any nonterminal \bl{\meta{X}} in the string by the
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   344
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
   345
\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
   346
\end{enumerate}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   347
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   348
\begin{center}
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   349
\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
   350
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   351
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   352
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   353
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   354
  
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   355
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   356
\begin{frame}[t]
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   357
\frametitle{Example Derivation}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   358
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   359
\bl{\begin{plstx}[margin=2cm]
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   360
: \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
   361
\end{plstx}}\bigskip
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   362
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   363
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   364
\begin{tabular}{lcl}
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   365
\bl{\meta{S}} & \bl{$\rightarrow$} & \bl{$a\meta{S}a$}\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   366
              & \bl{$\rightarrow$} & \bl{$ab\meta{S}ba$}\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   367
              & \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
   368
              & \bl{$\rightarrow$} & \bl{$abaaba$}\\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   369
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   370
 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   371
\end{tabular}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   372
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   373
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   374
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   375
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   376
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   377
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   378
\begin{frame}[t]
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   379
\frametitle{Example Derivation}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   380
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   381
\bl{\begin{plstx}[margin=3cm,one per line]
795
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   382
: \meta{E} ::=  0 \mid 1 \mid 2 \mid ... \mid 9
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   383
   | \meta{E} \cdot + \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   384
   | \meta{E} \cdot - \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   385
   | \meta{E} \cdot * \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   386
   | ( \cdot \meta{E} \cdot ) \\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   387
\end{plstx}}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   388
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   389
\small
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   390
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   391
\begin{tabular}{@{}c@{}c@{}}
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   392
\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
   393
\bl{\meta{E}} & \bl{$\rightarrow$} & \bl{$\meta{E}*\meta{E}$}\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   394
              & \bl{$\rightarrow$} & \bl{$\meta{E}+\meta{E}*\meta{E}$}\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   395
              & \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
   396
              & \bl{$\rightarrow^+$} & \bl{$1+2*3+4$}\\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   397
\end{tabular} &\pause
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   398
\begin{tabular}{@{}l@{\hspace{0mm}}l@{\hspace{1mm}}l}
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   399
\bl{$\meta{E}$} & \bl{$\rightarrow$} & \bl{$\meta{E}+\meta{E}$}\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   400
                & \bl{$\rightarrow$} & \bl{$\meta{E}+\meta{E}+\meta{E}$}\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   401
                & \bl{$\rightarrow$} & \bl{$\meta{E}+\meta{E}*\meta{E}+\meta{E}$}\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   402
                & \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
   403
\end{tabular}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   404
\end{tabular}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   405
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   406
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   407
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   408
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   409
796
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   410
   
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   411
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   412
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   413
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   414
\frametitle{Language of a CFG}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   415
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   416
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
   417
Then the language \bl{$L(G)$} is:
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   418
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   419
\begin{center}
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   420
\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
   421
\end{center}\pause
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   422
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   423
\begin{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   424
\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
   425
\item Once generated, terminals are ``permanent''.
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   426
\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
   427
(but can also be strings).
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   428
\end{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   429
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   430
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   431
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   432
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   433
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   434
\begin{frame}[t]
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   435
\frametitle{Parse Trees}
582
d236e75e1d55 updated
Christian Urban <urbanc@in.tum.de>
parents: 550
diff changeset
   436
\mbox{}\\[-12mm]
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   437
593
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 588
diff changeset
   438
\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
   439
: \meta{T} ::= \meta{F} | \meta{F} \cdot * \cdot \meta{T}\\
795
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   440
: \meta{F} ::= 0 ... 9 | ( \cdot \meta{E} \cdot )\\
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   441
\end{plstx}}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   442
795
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   443
\begin{textblock}{5}(6, 5)
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   444
\small
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   445
\begin{tikzpicture}[level distance=10mm, blue]
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   446
  \node {$\meta{E}$}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   447
  child {node {$\meta{T}$}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   448
    child {node {$\meta{F}$} child {node {1}}}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   449
  }
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   450
  child {node {+}}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   451
  child {node {$\meta{E}$}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   452
    child[sibling distance=10mm] {node {$\meta{T}$}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   453
      child {node {$\meta{F}$} child {node {2}}}
798
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   454
      child {node {*}}
795
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   455
      child {node {$\meta{T}$} child {node {$\meta{F}$} child {node {3}}}}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   456
    }
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   457
    child {node {+}}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   458
    child {node {$\meta{E}$} child {node {$\meta{T}$}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   459
        child {node {$\meta{F}$} child {node {4}}}}}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   460
  } 
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   461
  ;
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   462
\end{tikzpicture}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   463
\end{textblock}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   464
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   465
\begin{textblock}{5}(1, 10)
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   466
\bl{\texttt{1 + 2 * 3 + 4}}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   467
\end{textblock}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   468
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   469
\end{frame}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   470
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   471
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   472
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   473
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   474
\begin{frame}[t]
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   475
\frametitle{Arithmetic Expressions}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   476
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   477
\bl{\begin{plstx}[margin=3cm,one per line]
795
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   478
: \meta{E} ::=  0..9 
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   479
   | \meta{E} \cdot + \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   480
   | \meta{E} \cdot - \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   481
   | \meta{E} \cdot * \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   482
   | ( \cdot \meta{E} \cdot ) \\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   483
\end{plstx}}\pause\bigskip
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   484
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   485
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
   486
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
   487
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   488
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   489
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   490
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   491
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   492
\begin{frame}[t]
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   493
\frametitle{Ambiguous Grammars}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   494
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   495
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
   496
has at least two different parse trees.
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   497
796
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   498
\bl{\begin{plstx}[margin=3cm,one per line]: \meta{E} ::=  0 ... 9 
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   499
   | \meta{E} \cdot + \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   500
   | \meta{E} \cdot - \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   501
   | \meta{E} \cdot * \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   502
   | ( \cdot \meta{E} \cdot ) \\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   503
\end{plstx}}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   504
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   505
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   506
\bl{\texttt{1 + 2 * 3 + 4}}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   507
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   508
\end{frame}
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
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   511
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   512
\begin{frame}[c]
582
d236e75e1d55 updated
Christian Urban <urbanc@in.tum.de>
parents: 550
diff changeset
   513
\frametitle{`Dangling' Else}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   514
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   515
Another ambiguous grammar:\bigskip
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   516
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   517
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   518
\bl{\begin{tabular}{lcl}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   519
$E$ & $\rightarrow$ &  if $E$ then $E$\\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   520
 & $|$ &  if $E$ then $E$ else $E$ \\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   521
 & $|$ &  \ldots
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   522
\end{tabular}}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   523
\end{center}\bigskip
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   524
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   525
\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
   526
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   527
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   528
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   529
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   530
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   531
\begin{frame}[c]
798
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   532
\frametitle{CYK Algorithm}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   533
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   534
Suppose the grammar:
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   535
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   536
\begin{center}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   537
\bl{\begin{tabular}{@ {}lcl@ {}}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   538
$\meta{S}$ & $::=$ &  $\meta{N}\cdot \meta{P}$ \\
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   539
$\meta{P}$ & $::=$ &  $\meta{V}\cdot \meta{N}$ \\
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   540
$\meta{N}$ & $::=$ &  $\meta{N}\cdot \meta{N}$ \\
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   541
$\meta{N}$ & $::=$ &  $\texttt{students} \;|\; \texttt{Jeff} \;|\; \texttt{geometry} \;|\; \texttt{trains} $ \\
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   542
$\meta{V}$ & $::=$ &  $\texttt{trains}$ 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   543
\end{tabular}}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   544
\end{center}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   545
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   546
\bl{\texttt{Jeff trains geometry students}}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   547
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   548
\end{frame}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   549
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   550
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   551
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   552
\begin{frame}[c]
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   553
\frametitle{CYK Algorithm}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   554
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   555
\begin{center}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   556
  \begin{tikzpicture}[scale=1,line width=0.8mm]
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   557
  \draw (-2,0) -- (2,0);
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   558
  \draw (-2,1) -- (2,1);
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   559
  \draw (-2,2) -- (1,2);
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   560
  \draw (-2,3) -- (0,3);
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   561
  \draw (-2,4) -- (-1,4);
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   562
  
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   563
  \draw (0,0) -- (0, 3);
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   564
  \draw (1,0) -- (1, 2);
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   565
  \draw (2,0) -- (2, 1);
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   566
  \draw (-1,0) -- (-1, 4);
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   567
  \draw (-2,0) -- (-2, 4);
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   568
  
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   569
  \draw (-1.5,-0.5) node {\footnotesize{}\texttt{Jeff}}; 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   570
  \draw (-0.5,-1.0) node {\footnotesize{}\texttt{trains}}; 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   571
  \draw ( 0.5,-0.5) node {\footnotesize{}\texttt{geometry}}; 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   572
  \draw ( 1.5,-1.0) node {\footnotesize{}\texttt{students}}; 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   573
  
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   574
  \draw (-1.5,0.5) node {$N$}; 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   575
  \draw (-0.5,0.5) node {$N,V$}; 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   576
  \draw ( 0.5,0.5) node {$N$}; 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   577
  \draw ( 1.5,0.5) node {$N$}; 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   578
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   579
  \draw (-2.4, 3.5) node {$1$}; 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   580
  \draw (-2.4, 2.5) node {$2$}; 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   581
  \draw (-2.4, 1.5) node {$3$}; 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   582
  \draw (-2.4, 0.5) node {$4$}; 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   583
  \end{tikzpicture}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   584
  \end{center}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   585
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   586
\begin{textblock}{5}(10,10)
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   587
\small\bl{\begin{tabular}{@ {}lcl@ {}}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   588
$\meta{S}$ & $::=$ &  $\meta{N}\cdot \meta{P}$ \\
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   589
$\meta{P}$ & $::=$ &  $\meta{V}\cdot \meta{N}$ \\
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   590
$\meta{N}$ & $::=$ &  $\meta{N}\cdot \meta{N}$ \\
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   591
            $\meta{N}$ & $::=$ &  $\texttt{students} \;|\; \texttt{Jeff}$\\
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   592
            & & $\;|\; \texttt{geometry} \;|\; \texttt{trains} $ \\
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   593
$\meta{V}$ & $::=$ &  $\texttt{trains}$ 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   594
\end{tabular}}  
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   595
\end{textblock}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   596
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   597
\end{frame}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   598
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   599
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   600
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   601
\begin{frame}[t]
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   602
\frametitle{Chomsky Normal Form}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   603
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   604
A grammar for palindromes over the alphabet~\bl{$\{a,b\}$}:
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   605
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   606
\bl{\begin{plstx}[margin=0cm]
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   607
: \meta{S} ::=  a\cdot \meta{S}\cdot a | b\cdot \meta{S}\cdot b | a\cdot a | b\cdot b | a | b \\
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   608
\end{plstx}}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   609
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   610
\end{frame}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   611
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   612
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   613
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   614
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   615
\begin{frame}[c]
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   616
\frametitle{CYK Algorithm}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   617
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   618
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   619
\begin{itemize}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   620
\item fastest possible algorithm for recognition problem
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   621
\item runtime is \bl{$O(n^3)$}\bigskip
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   622
\item grammars need to be transformed into CNF
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   623
\end{itemize}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   624
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   625
\end{frame}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   626
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   627
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   628
799
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   629
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   630
\begin{frame}[c,fragile]
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   631
  \begin{mybox3}{}\it 
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   632
    "The C++ grammar is ambiguous, context-dependent and potentially
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   633
    requires infinite lookahead to resolve some ambiguities."
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   634
  \end{mybox3}\bigskip
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   635
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   636
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   637
  \hfill from the \href{http://www.computing.surrey.ac.uk/research/dsrg/fog/FogThesis.pdf}{PhD thesis} by Willink (2001)
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   638
  
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   639
  \small
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   640
  \begin{center}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   641
  \begin{lstlisting}[language={},numbers=none]
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   642
    int(x), y, *const z;
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   643
    int(x), y, new int;
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   644
  \end{lstlisting}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   645
  \end{center}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   646
\end{frame}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   647
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
798
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   648
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   649
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   650
\begin{frame}[c]
796
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   651
\frametitle{Context Sensitive Grammars}
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   652
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   653
It is much harder to find out whether a string is parsed
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   654
by a context sensitive grammar:
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   655
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   656
\bl{\begin{plstx}[margin=2cm]
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   657
: \meta{S} ::= b\meta{S}\meta{A}\meta{A} | \epsilon\\
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   658
: \meta{A} ::= a\\
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   659
: b\meta{A} ::= \meta{A}b\\
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   660
\end{plstx}}\pause
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   661
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   662
\begin{center}
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   663
\bl{$\meta{S} \rightarrow\ldots\rightarrow^? ababaa$}
799
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   664
\end{center}
796
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   665
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   666
\end{frame}
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   667
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   668
465
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
   669
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   670
798
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   671
\begin{frame}[t,fragile]
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   672
\begin{mybox3}{}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   673
  For CW2, please include '$\backslash$' as a symbol in strings, because
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   674
  the collatz program contains
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   675
  \begin{lstlisting}[language=Scala, numbers=none]
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   676
  write "\n";\end{lstlisting}  
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   677
\end{mybox3}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   678
\end{frame}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   679
796
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   680
\begin{frame}[t]
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   681
\begin{mybox3}{}
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   682
  val (r1s, f1s) = simp(r1)\\
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   683
  val (r2s, f2s) = simp(r2)\\
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   684
  how are the
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   685
  first rectification functions f1s and f2s made? could you maybe
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   686
  show an example?
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   687
\end{mybox3}
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   688
\end{frame}
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   689
849
3d5ecb8f1f2f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   690
\begin{frame}<1-24>[c]
796
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   691
\end{frame}
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   692
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   693
945
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   694
\begin{frame}[t]
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   695
\begin{minipage}{1.2\textwidth}  
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   696
  \begin{mybox3}{}\small
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   697
    \textbf{Questions regarding CFL CW1}
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   698
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   699
Dear Dr Urban    
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   700
    
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   701
 Regarding CW1, I am stuck on finding the nullable and derivative rules for some important regexes.\smallskip
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   702
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   703
The NOT Regex nullable rule: I am not sure how to approach this, I am inclined to simply put this as the negation of the nullable function on the input regex (e.g !nullable(r)). However I have found instances where negating a nullable does not make it un-nullable. For example the negation of r* can still match regex ab (which is not nullable). So I would like some actual clarification, pointers and help in this area.\smallskip
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   704
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   705
The NOT Regex derivation rule: again I am dumbfounded here, I am inclined to think that I should derive the regex and then negate that derivation. But none of this ever works. Please provide some helpful information so I can solve this.
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   706
\end{mybox3}
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   707
\end{minipage}
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   708
\end{frame}
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   709
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   710
5070392a1bd7 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   711
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   712
\end{document}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   713
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   714
%%% Local Variables:  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   715
%%% mode: latex
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   716
%%% TeX-master: t
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   717
%%% End: 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   718