slides/slides05.tex
author Christian Urban <christian.urban@kcl.ac.uk>
Fri, 28 Oct 2022 09:08:13 +0100
changeset 893 54a483a33763
parent 871 94b84d880c2b
child 940 46eee459a999
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\\
54a483a33763 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
    41
  Office Hour: & Fridays 11 -- 12\\
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
743
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    83
    
528
68fab15cd6fb updated
cu
parents: 500
diff changeset
    84
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68fab15cd6fb updated
cu
parents: 500
diff changeset
    85
\begin{frame}[t]
795
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
    86
\frametitle{Parser}
528
68fab15cd6fb updated
cu
parents: 500
diff changeset
    87
\mbox{}\\[-16mm]\mbox{}
68fab15cd6fb updated
cu
parents: 500
diff changeset
    88
68fab15cd6fb updated
cu
parents: 500
diff changeset
    89
\begin{center}
68fab15cd6fb updated
cu
parents: 500
diff changeset
    90
  \begin{tikzpicture}[scale=1,
68fab15cd6fb updated
cu
parents: 500
diff changeset
    91
                      node/.style={
68fab15cd6fb updated
cu
parents: 500
diff changeset
    92
                      rectangle,rounded corners=3mm,
68fab15cd6fb updated
cu
parents: 500
diff changeset
    93
                      very thick,draw=black!50,
68fab15cd6fb updated
cu
parents: 500
diff changeset
    94
                      minimum height=18mm, minimum width=20mm,
743
6acabeecdf75 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 671
diff changeset
    95
                      top color=white,bottom color=black!20,drop shadow}]
528
68fab15cd6fb updated
cu
parents: 500
diff changeset
    96
  \node (0) at (-2.3,0) {}; 
68fab15cd6fb updated
cu
parents: 500
diff changeset
    97
  
68fab15cd6fb updated
cu
parents: 500
diff changeset
    98
  \node (A) at (0,0)  [node] {};
68fab15cd6fb updated
cu
parents: 500
diff changeset
    99
  \node [below right] at (A.north west) {lexer};
68fab15cd6fb updated
cu
parents: 500
diff changeset
   100
68fab15cd6fb updated
cu
parents: 500
diff changeset
   101
  \node (B) at (3,0)  [node] {};
68fab15cd6fb updated
cu
parents: 500
diff changeset
   102
  \node [below right=1mm] at (B.north west) 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   103
    {\mbox{}\hspace{-1mm}parser};
68fab15cd6fb updated
cu
parents: 500
diff changeset
   104
68fab15cd6fb updated
cu
parents: 500
diff changeset
   105
  \node (C) at (6,0)  [node] {};
68fab15cd6fb updated
cu
parents: 500
diff changeset
   106
  \node [below right] at (C.north west) 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   107
    {\mbox{}\hspace{-1mm}code gen};
68fab15cd6fb updated
cu
parents: 500
diff changeset
   108
68fab15cd6fb updated
cu
parents: 500
diff changeset
   109
  \node (1) at (8.4,0) {}; 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   110
68fab15cd6fb updated
cu
parents: 500
diff changeset
   111
  \draw [->,line width=4mm] (0) -- (A); 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   112
  \draw [->,line width=4mm] (A) -- (B); 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   113
  \draw [->,line width=4mm] (B) -- (C); 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   114
  \draw [->,line width=4mm] (C) -- (1); 
68fab15cd6fb updated
cu
parents: 500
diff changeset
   115
  \end{tikzpicture}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   116
  \end{center}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   117
  
795
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   118
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   119
\only<2>{
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   120
\begin{textblock}{1}(3,6)
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   121
\begin{bubble}[8.5cm]
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   122
\normalsize
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   123
parser input: a sequence of tokens\smallskip\\
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   124
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   125
{\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
   126
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   127
parser output: an abstract syntax tree\smallskip\\
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   128
\footnotesize
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   129
\hspace{2cm}\begin{tikzpicture}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   130
  \node {\code{read}}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   131
    child {node {\code{lpar}}}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   132
    child {node {\code{n}}}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   133
    child {node {\code{rpar}}};
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   134
\end{tikzpicture}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   135
\end{bubble}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   136
\end{textblock}}
528
68fab15cd6fb updated
cu
parents: 500
diff changeset
   137
\end{frame}
68fab15cd6fb updated
cu
parents: 500
diff changeset
   138
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   139
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   140
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   141
\begin{frame}[c]
550
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   142
\frametitle{What Parsing is Not}
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   143
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   144
Usually parsing does not check semantic correctness, e.g.
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   145
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   146
\begin{itemize}
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   147
\item  whether a function is not used before it
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   148
  is defined
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   149
\item whether a function has the correct number of arguments 
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   150
  or are of correct type
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   151
\item whether a variable can be declared twice in a scope  
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   152
\end{itemize}  
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   153
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   154
\end{frame}
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   155
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   156
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   157
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   158
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   159
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71fc4a7a7039 updated
Christian Urban <urbanc@in.tum.de>
parents: 529
diff changeset
   160
\begin{frame}[c]
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   161
\frametitle{Regular Languages}
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
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
   164
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
   165
\bl{$a^nb^n$}.\bigskip
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   166
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   167
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   168
\bl{$(((()()))())$} \;\;vs.\;\; \bl{$(((()()))()))$}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   169
\end{center}\bigskip\bigskip
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   170
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   171
\small
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   172
\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
   173
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
   174
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
   175
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   176
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   177
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   178
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   179
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   180
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   181
\frametitle{Hierarchy of Languages}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   182
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   183
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   184
\begin{tikzpicture}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   185
[rect/.style={draw=black!50, 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   186
              top color=white,
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   187
              bottom color=black!20, 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   188
              rectangle, 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   189
              very thick, 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   190
              rounded corners}, scale=1.2]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   191
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   192
\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
   193
\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
   194
\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
   195
\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
   196
\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
   197
\end{tikzpicture}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   198
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   199
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   200
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   201
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   202
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   203
795
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   204
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   205
\begin{frame}[c]
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   206
  \LARGE
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   207
  \begin{center}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   208
  Time flies like an arrow.\\ 
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   209
  Fruit flies like bananas.
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   210
  \end{center}  
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   211
\end{frame}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   212
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   213
  
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   214
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   215
\begin{frame}[c]
792
34132a854d03 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 743
diff changeset
   216
\frametitle{CFGs}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   217
360
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   218
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
   219
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   220
\begin{itemize}
664
dc2f5eb33a9a updated
Christian Urban <urbanc@in.tum.de>
parents: 593
diff changeset
   221
\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
   222
\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
   223
\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
   224
\item a set of rules
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   225
\begin{center}
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   226
\bl{$\meta{A} ::= \textit{rhs}$}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   227
\end{center}
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
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
   230
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
   231
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   232
We also allow rules
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   233
\begin{center}
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   234
\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
   235
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   236
\end{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   237
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   238
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   239
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   240
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   241
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
582
d236e75e1d55 updated
Christian Urban <urbanc@in.tum.de>
parents: 550
diff changeset
   242
\begin{frame}[t]
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   243
\frametitle{Palindromes}
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
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
   246
795
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   247
\only<1>{%
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   248
\bl{\begin{plstx}[margin=1cm]
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   249
: \meta{S} ::= a\cdot\meta{S}\cdot a\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   250
: \meta{S} ::= b\cdot\meta{S}\cdot b\\
588
a4646557016d updated
Christian Urban <urbanc@in.tum.de>
parents: 583
diff changeset
   251
: \meta{S} ::= a\\
a4646557016d updated
Christian Urban <urbanc@in.tum.de>
parents: 583
diff changeset
   252
: \meta{S} ::= b\\
a4646557016d updated
Christian Urban <urbanc@in.tum.de>
parents: 583
diff changeset
   253
: \meta{S} ::= \epsilon\\
795
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   254
\end{plstx}}}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   255
%
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   256
\only<2>{%
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   257
\bl{\begin{plstx}[margin=1cm]
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   258
: \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
   259
\end{plstx}}}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   260
795
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   261
%\small
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   262
%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
   263
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   264
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   265
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   266
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]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   269
\frametitle{Arithmetic Expressions}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   270
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   271
\bl{\begin{plstx}[margin=3cm,one per line]
795
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   272
: \meta{E} ::=  0 \mid 1 \mid 2 \mid ... \mid 9
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   273
   | \meta{E} \cdot + \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   274
   | \meta{E} \cdot - \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   275
   | \meta{E} \cdot * \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   276
   | ( \cdot \meta{E} \cdot ) \\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   277
\end{plstx}}\pause
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   278
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   279
\bl{\texttt{1 + 2 * 3 + 4}}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   280
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   281
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   282
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   283
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
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   286
\frametitle{A CFG Derivation}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   287
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   288
\begin{enumerate}
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   289
\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
   290
\item Replace any nonterminal \bl{\meta{X}} in the string by the
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   291
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
   292
\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
   293
\end{enumerate}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   294
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   295
\begin{center}
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   296
\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
   297
\end{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   298
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   299
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   300
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   301
  
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   302
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   303
\begin{frame}[t]
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   304
\frametitle{Example Derivation}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   305
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   306
\bl{\begin{plstx}[margin=2cm]
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   307
: \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
   308
\end{plstx}}\bigskip
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   309
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   310
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   311
\begin{tabular}{lcl}
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   312
\bl{\meta{S}} & \bl{$\rightarrow$} & \bl{$a\meta{S}a$}\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   313
              & \bl{$\rightarrow$} & \bl{$ab\meta{S}ba$}\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   314
              & \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
   315
              & \bl{$\rightarrow$} & \bl{$abaaba$}\\
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
 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   318
\end{tabular}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   319
\end{center}
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
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   322
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   323
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   324
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   325
\begin{frame}[t]
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   326
\frametitle{Example Derivation}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   327
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   328
\bl{\begin{plstx}[margin=3cm,one per line]
795
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   329
: \meta{E} ::=  0 \mid 1 \mid 2 \mid ... \mid 9
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   330
   | \meta{E} \cdot + \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   331
   | \meta{E} \cdot - \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   332
   | \meta{E} \cdot * \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   333
   | ( \cdot \meta{E} \cdot ) \\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   334
\end{plstx}}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   335
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   336
\small
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   337
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   338
\begin{tabular}{@{}c@{}c@{}}
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   339
\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
   340
\bl{\meta{E}} & \bl{$\rightarrow$} & \bl{$\meta{E}*\meta{E}$}\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   341
              & \bl{$\rightarrow$} & \bl{$\meta{E}+\meta{E}*\meta{E}$}\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   342
              & \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
   343
              & \bl{$\rightarrow^+$} & \bl{$1+2*3+4$}\\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   344
\end{tabular} &\pause
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   345
\begin{tabular}{@{}l@{\hspace{0mm}}l@{\hspace{1mm}}l}
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   346
\bl{$\meta{E}$} & \bl{$\rightarrow$} & \bl{$\meta{E}+\meta{E}$}\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   347
                & \bl{$\rightarrow$} & \bl{$\meta{E}+\meta{E}+\meta{E}$}\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   348
                & \bl{$\rightarrow$} & \bl{$\meta{E}+\meta{E}*\meta{E}+\meta{E}$}\\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   349
                & \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
   350
\end{tabular}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   351
\end{tabular}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   352
\end{center}
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
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   355
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   356
796
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   357
   
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   359
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   360
\begin{frame}[c]
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   361
\frametitle{Language of a CFG}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   362
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   363
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
   364
Then the language \bl{$L(G)$} is:
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   365
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   366
\begin{center}
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   367
\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
   368
\end{center}\pause
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
\begin{itemize}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   371
\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
   372
\item Once generated, terminals are ``permanent''.
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   373
\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
   374
(but can also be strings).
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   375
\end{itemize}
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
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   378
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   379
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
\begin{frame}[t]
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   382
\frametitle{Parse Trees}
582
d236e75e1d55 updated
Christian Urban <urbanc@in.tum.de>
parents: 550
diff changeset
   383
\mbox{}\\[-12mm]
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   384
593
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 588
diff changeset
   385
\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
   386
: \meta{T} ::= \meta{F} | \meta{F} \cdot * \cdot \meta{T}\\
795
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   387
: \meta{F} ::= 0 ... 9 | ( \cdot \meta{E} \cdot )\\
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   388
\end{plstx}}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   389
795
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   390
\begin{textblock}{5}(6, 5)
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   391
\small
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   392
\begin{tikzpicture}[level distance=10mm, blue]
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   393
  \node {$\meta{E}$}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   394
  child {node {$\meta{T}$}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   395
    child {node {$\meta{F}$} child {node {1}}}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   396
  }
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   397
  child {node {+}}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   398
  child {node {$\meta{E}$}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   399
    child[sibling distance=10mm] {node {$\meta{T}$}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   400
      child {node {$\meta{F}$} child {node {2}}}
798
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   401
      child {node {*}}
795
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   402
      child {node {$\meta{T}$} child {node {$\meta{F}$} child {node {3}}}}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   403
    }
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   404
    child {node {+}}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   405
    child {node {$\meta{E}$} child {node {$\meta{T}$}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   406
        child {node {$\meta{F}$} child {node {4}}}}}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   407
  } 
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   408
  ;
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   409
\end{tikzpicture}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   410
\end{textblock}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   411
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   412
\begin{textblock}{5}(1, 10)
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   413
\bl{\texttt{1 + 2 * 3 + 4}}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   414
\end{textblock}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   415
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   416
\end{frame}
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   417
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   418
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   419
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   420
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   421
\begin{frame}[t]
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   422
\frametitle{Arithmetic Expressions}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   423
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   424
\bl{\begin{plstx}[margin=3cm,one per line]
795
ff2894dfc399 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   425
: \meta{E} ::=  0..9 
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   426
   | \meta{E} \cdot + \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   427
   | \meta{E} \cdot - \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   428
   | \meta{E} \cdot * \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   429
   | ( \cdot \meta{E} \cdot ) \\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   430
\end{plstx}}\pause\bigskip
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   431
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   432
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
   433
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
   434
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   435
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   436
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   437
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   438
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   439
\begin{frame}[t]
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   440
\frametitle{Ambiguous Grammars}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   441
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   442
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
   443
has at least two different parse trees.
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   444
796
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   445
\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
   446
   | \meta{E} \cdot + \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   447
   | \meta{E} \cdot - \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   448
   | \meta{E} \cdot * \cdot \meta{E} 
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   449
   | ( \cdot \meta{E} \cdot ) \\
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 445
diff changeset
   450
\end{plstx}}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   451
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   452
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   453
\bl{\texttt{1 + 2 * 3 + 4}}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   454
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   455
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   456
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   457
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   458
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   459
\begin{frame}[c]
582
d236e75e1d55 updated
Christian Urban <urbanc@in.tum.de>
parents: 550
diff changeset
   460
\frametitle{`Dangling' Else}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   461
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   462
Another ambiguous grammar:\bigskip
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   463
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   464
\begin{center}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   465
\bl{\begin{tabular}{lcl}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   466
$E$ & $\rightarrow$ &  if $E$ then $E$\\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   467
 & $|$ &  if $E$ then $E$ else $E$ \\
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   468
 & $|$ &  \ldots
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   469
\end{tabular}}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   470
\end{center}\bigskip
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   471
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   472
\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
   473
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   474
\end{frame}
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   475
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   476
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   477
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   478
\begin{frame}[c]
798
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   479
\frametitle{CYK Algorithm}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   480
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   481
Suppose the grammar:
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   482
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   483
\begin{center}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   484
\bl{\begin{tabular}{@ {}lcl@ {}}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   485
$\meta{S}$ & $::=$ &  $\meta{N}\cdot \meta{P}$ \\
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   486
$\meta{P}$ & $::=$ &  $\meta{V}\cdot \meta{N}$ \\
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   487
$\meta{N}$ & $::=$ &  $\meta{N}\cdot \meta{N}$ \\
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   488
$\meta{N}$ & $::=$ &  $\texttt{students} \;|\; \texttt{Jeff} \;|\; \texttt{geometry} \;|\; \texttt{trains} $ \\
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   489
$\meta{V}$ & $::=$ &  $\texttt{trains}$ 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   490
\end{tabular}}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   491
\end{center}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   492
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   493
\bl{\texttt{Jeff trains geometry students}}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   494
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   495
\end{frame}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   496
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   497
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   498
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   499
\begin{frame}[c]
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   500
\frametitle{CYK Algorithm}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   501
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   502
\begin{center}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   503
  \begin{tikzpicture}[scale=1,line width=0.8mm]
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   504
  \draw (-2,0) -- (2,0);
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   505
  \draw (-2,1) -- (2,1);
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   506
  \draw (-2,2) -- (1,2);
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   507
  \draw (-2,3) -- (0,3);
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   508
  \draw (-2,4) -- (-1,4);
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   509
  
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   510
  \draw (0,0) -- (0, 3);
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   511
  \draw (1,0) -- (1, 2);
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   512
  \draw (2,0) -- (2, 1);
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   513
  \draw (-1,0) -- (-1, 4);
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   514
  \draw (-2,0) -- (-2, 4);
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   515
  
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   516
  \draw (-1.5,-0.5) node {\footnotesize{}\texttt{Jeff}}; 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   517
  \draw (-0.5,-1.0) node {\footnotesize{}\texttt{trains}}; 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   518
  \draw ( 0.5,-0.5) node {\footnotesize{}\texttt{geometry}}; 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   519
  \draw ( 1.5,-1.0) node {\footnotesize{}\texttt{students}}; 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   520
  
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   521
  \draw (-1.5,0.5) node {$N$}; 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   522
  \draw (-0.5,0.5) node {$N,V$}; 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   523
  \draw ( 0.5,0.5) node {$N$}; 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   524
  \draw ( 1.5,0.5) node {$N$}; 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   525
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   526
  \draw (-2.4, 3.5) node {$1$}; 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   527
  \draw (-2.4, 2.5) node {$2$}; 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   528
  \draw (-2.4, 1.5) node {$3$}; 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   529
  \draw (-2.4, 0.5) node {$4$}; 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   530
  \end{tikzpicture}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   531
  \end{center}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   532
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   533
\begin{textblock}{5}(10,10)
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   534
\small\bl{\begin{tabular}{@ {}lcl@ {}}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   535
$\meta{S}$ & $::=$ &  $\meta{N}\cdot \meta{P}$ \\
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   536
$\meta{P}$ & $::=$ &  $\meta{V}\cdot \meta{N}$ \\
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   537
$\meta{N}$ & $::=$ &  $\meta{N}\cdot \meta{N}$ \\
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   538
            $\meta{N}$ & $::=$ &  $\texttt{students} \;|\; \texttt{Jeff}$\\
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   539
            & & $\;|\; \texttt{geometry} \;|\; \texttt{trains} $ \\
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   540
$\meta{V}$ & $::=$ &  $\texttt{trains}$ 
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   541
\end{tabular}}  
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   542
\end{textblock}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   543
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   544
\end{frame}
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
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
\begin{frame}[t]
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   549
\frametitle{Chomsky Normal Form}
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
A grammar for palindromes over the alphabet~\bl{$\{a,b\}$}:
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   552
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   553
\bl{\begin{plstx}[margin=0cm]
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   554
: \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
   555
\end{plstx}}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   556
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   557
\end{frame}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   558
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   559
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   560
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   561
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   562
\begin{frame}[c]
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   563
\frametitle{CYK Algorithm}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   564
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   565
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   566
\begin{itemize}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   567
\item fastest possible algorithm for recognition problem
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   568
\item runtime is \bl{$O(n^3)$}\bigskip
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   569
\item grammars need to be transformed into CNF
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   570
\end{itemize}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   571
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   572
\end{frame}
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
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   575
799
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   576
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   577
\begin{frame}[c,fragile]
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   578
  \begin{mybox3}{}\it 
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   579
    "The C++ grammar is ambiguous, context-dependent and potentially
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   580
    requires infinite lookahead to resolve some ambiguities."
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   581
  \end{mybox3}\bigskip
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   582
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   583
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   584
  \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
   585
  
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   586
  \small
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   587
  \begin{center}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   588
  \begin{lstlisting}[language={},numbers=none]
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   589
    int(x), y, *const z;
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   590
    int(x), y, new int;
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   591
  \end{lstlisting}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   592
  \end{center}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   593
\end{frame}
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   594
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
798
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   595
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
\begin{frame}[c]
796
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   598
\frametitle{Context Sensitive Grammars}
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   599
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   600
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
   601
by a context sensitive grammar:
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   602
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   603
\bl{\begin{plstx}[margin=2cm]
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   604
: \meta{S} ::= b\meta{S}\meta{A}\meta{A} | \epsilon\\
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   605
: \meta{A} ::= a\\
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   606
: b\meta{A} ::= \meta{A}b\\
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   607
\end{plstx}}\pause
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   608
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   609
\begin{center}
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   610
\bl{$\meta{S} \rightarrow\ldots\rightarrow^? ababaa$}
799
85267be9a5ed updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 798
diff changeset
   611
\end{center}
796
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   612
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   613
\end{frame}
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   614
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   615
465
b5e1cfaf3319 updated
Christian Urban <urbanc@in.tum.de>
parents: 462
diff changeset
   616
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   617
798
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   618
\begin{frame}[t,fragile]
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   619
\begin{mybox3}{}
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   620
  For CW2, please include '$\backslash$' as a symbol in strings, because
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   621
  the collatz program contains
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   622
  \begin{lstlisting}[language=Scala, numbers=none]
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   623
  write "\n";\end{lstlisting}  
aaf0bd0a211d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 796
diff changeset
   624
\end{mybox3}
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
796
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   627
\begin{frame}[t]
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   628
\begin{mybox3}{}
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   629
  val (r1s, f1s) = simp(r1)\\
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   630
  val (r2s, f2s) = simp(r2)\\
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   631
  how are the
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   632
  first rectification functions f1s and f2s made? could you maybe
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   633
  show an example?
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   634
\end{mybox3}
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   635
\end{frame}
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   636
849
3d5ecb8f1f2f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 799
diff changeset
   637
\begin{frame}<1-24>[c]
796
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   638
\end{frame}
c6f975266155 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 795
diff changeset
   639
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 290
diff changeset
   640
44
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   641
\end{document}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   642
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   643
%%% Local Variables:  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   644
%%% mode: latex
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   645
%%% TeX-master: t
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   646
%%% End: 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   647