slides/slides07.tex
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Mon, 11 Nov 2013 15:26:20 +0000
changeset 184 2e9134d25a2b
parent 173 7cfb7a6f7c99
child 185 ea8b94d4755e
permissions -rw-r--r--
added slides
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
\documentclass[dvipsnames,14pt,t]{beamer}
173
7cfb7a6f7c99 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
     2
\usepackage{beamerthemeplaincu}
7cfb7a6f7c99 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
     3
%\usepackage[T1]{fontenc}
7cfb7a6f7c99 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
     4
%\usepackage[latin1]{inputenc}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
\usepackage{mathpartir}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
\usepackage[absolute,overlay]{textpos}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
\usepackage{ifthen}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
\usepackage{tikz}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
\usepackage{pgf}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
\usepackage{calc} 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
\usepackage{ulem}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
\usepackage{courier}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
\usepackage{listings}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
\renewcommand{\uline}[1]{#1}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
\usetikzlibrary{arrows}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
\usetikzlibrary{automata}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
\usetikzlibrary{shapes}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
\usetikzlibrary{shadows}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
\usetikzlibrary{positioning}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
\usetikzlibrary{calc}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
\usetikzlibrary{plotmarks}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
\usepackage{graphicx} 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
\definecolor{javared}{rgb}{0.6,0,0} % for strings
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
\definecolor{javagreen}{rgb}{0.25,0.5,0.35} % comments
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
\definecolor{javapurple}{rgb}{0.5,0,0.35} % keywords
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
\definecolor{javadocblue}{rgb}{0.25,0.35,0.75} % javadoc
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
\lstset{language=Java,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
	basicstyle=\ttfamily,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
	keywordstyle=\color{javapurple}\bfseries,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
	stringstyle=\color{javagreen},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
	commentstyle=\color{javagreen},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
	morecomment=[s][\color{javadocblue}]{/**}{*/},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
	numbers=left,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
	numberstyle=\tiny\color{black},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
	stepnumber=1,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
	numbersep=10pt,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
	tabsize=2,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
	showspaces=false,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
	showstringspaces=false}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
\lstdefinelanguage{scala}{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
  morekeywords={abstract,case,catch,class,def,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
    do,else,extends,false,final,finally,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
    for,if,implicit,import,match,mixin,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
    new,null,object,override,package,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
    private,protected,requires,return,sealed,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
    super,this,throw,trait,true,try,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
    type,val,var,while,with,yield},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
  otherkeywords={=>,<-,<\%,<:,>:,\#,@},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
  sensitive=true,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
  morecomment=[l]{//},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
  morecomment=[n]{/*}{*/},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
  morestring=[b]",
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
  morestring=[b]',
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
  morestring=[b]"""
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
\lstset{language=Scala,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
	basicstyle=\ttfamily,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
	keywordstyle=\color{javapurple}\bfseries,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
	stringstyle=\color{javagreen},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
	commentstyle=\color{javagreen},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
	morecomment=[s][\color{javadocblue}]{/**}{*/},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
	numbers=left,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
	numberstyle=\tiny\color{black},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
	stepnumber=1,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
	numbersep=10pt,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
	tabsize=2,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
	showspaces=false,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
	showstringspaces=false}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
% beamer stuff 
173
7cfb7a6f7c99 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    75
\renewcommand{\slidecaption}{AFL 07, King's College London, 13.~November 2013}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
\newcommand{\bl}[1]{\textcolor{blue}{#1}}       
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
\begin{document}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
\mode<presentation>{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
\begin{frame}<1>[t]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
\frametitle{%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
  \begin{tabular}{@ {}c@ {}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
  \\[-3mm]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
  \LARGE Automata and \\[-2mm] 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  \LARGE Formal Languages (7)\\[3mm] 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
  \end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
  \normalsize
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
  \begin{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
  \begin{tabular}{ll}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
  Email:  & christian.urban at kcl.ac.uk\\
173
7cfb7a6f7c99 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    95
  Office: & S1.27 (1st floor Strand Building)\\
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
  Slides: & KEATS (also home work is there)\\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
  \end{tabular}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
  \end{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
\end{frame}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
\newcommand{\qq}{\mbox{\texttt{"}}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
\mode<presentation>{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
\begin{frame}[c]
64
2d625418c011 added everything
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
   109
\frametitle{\begin{tabular}{c}CFGs\end{tabular}}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
64
2d625418c011 added everything
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
   111
A \alert{context-free} grammar (CFG) \bl{$G$} consists of:
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
\begin{itemize}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
\item a finite set of nonterminal symbols (upper case)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
\item a finite terminal symbols or tokens (lower case)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
\item a start symbol (which must be a nonterminal)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
\item a set of rules
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
\begin{center}
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   119
\bl{$A \rightarrow \text{rhs}_1 | \text{rhs}_2 | \ldots$}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
\end{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
where \bl{rhs} are sequences involving terminals and nonterminals (can also be empty).\medskip\pause
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
\end{itemize}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
\end{frame}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
\mode<presentation>{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
\begin{frame}[c]
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   133
\frametitle{\begin{tabular}{c}Hierarchie of Languages\end{tabular}}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   135
Recall that languages are sets of strings.
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
\begin{center}
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   138
\begin{tikzpicture}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   139
[rect/.style={draw=black!50, top color=white,bottom color=black!20, rectangle, very thick, rounded corners}]
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   140
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   141
\draw (0,0) node [rect, text depth=39mm, text width=68mm] {all languages};
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   142
\draw (0,-0.4) node [rect, text depth=28.5mm, text width=64mm] {decidable languages};
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   143
\draw (0,-0.85) node [rect, text depth=17mm] {context sensitive languages};
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   144
\draw (0,-1.14) node [rect, text depth=9mm, text width=50mm] {context-free languages};
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   145
\draw (0,-1.4) node [rect] {regular languages};
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   146
\end{tikzpicture}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   147
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
\end{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
\end{frame}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
\mode<presentation>{
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   155
\begin{frame}[t]
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   156
\frametitle{\begin{tabular}{c}Numbers\end{tabular}}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   157
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   158
A grammar for numbers:
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   159
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   160
\begin{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   161
\bl{\begin{tabular}{lcl}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   162
$N$ & $\rightarrow$ &  $N \cdot N \;|\; 0 \;|\; 1 \;|\; \ldots \;|\; 9$\\
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   163
\end{tabular}}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   164
\end{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   165
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   166
Unfortunately left-recursive (and ambiguous).\medskip\\
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   167
A problem for \alert{recursive descent parsers} (e.g.~parser combinators).
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   168
\bigskip\pause
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   169
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   170
A non-left-recursive grammar for numbers
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   171
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   172
\begin{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   173
\bl{\begin{tabular}{lcl}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   174
$N$ & $\rightarrow$ &  $0 \cdot N \;|\;1 \cdot N \;|\ldots\;|\; 0 \;|\; 1 \;|\; \ldots \;|\; 9$\\
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   175
\end{tabular}}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   176
\end{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   177
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   178
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   179
\end{frame}}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   180
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   181
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   182
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   183
\mode<presentation>{
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
\begin{frame}[c]
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   185
\frametitle{\begin{tabular}{c}Chomsky Normal Form\end{tabular}}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   187
All rules must be of the form
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
\begin{center}
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   190
\bl{$A \rightarrow a$}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   191
\end{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   192
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   193
or
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   195
\begin{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   196
\bl{$A \rightarrow B\cdot C$}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   197
\end{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   198
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   199
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
\end{frame}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
\mode<presentation>{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
\begin{frame}[c]
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   206
\frametitle{\begin{tabular}{c}CYK Algorithm\end{tabular}}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   207
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
\begin{center}
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   210
\bl{\begin{tabular}{@ {}lcl}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   211
$S$ & $\rightarrow$ &  $N\cdot P$ \\
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   212
$P$ & $\rightarrow$ &  $V\cdot N$ \\
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   213
$N$ & $\rightarrow$ &  $N\cdot N$ \\
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   214
$N$ & $\rightarrow$ &  $\texttt{students} \;|\; \texttt{Jeff} \;|\; \texttt{geometry} \;|\; \texttt{trains} $ \\
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   215
$V$ & $\rightarrow$ &  $\texttt{trains}$ 
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
\end{tabular}}
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   217
\end{center}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   219
\bl{\texttt{Jeff trains geometry students}}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   220
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
\end{frame}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   223
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   224
\mode<presentation>{
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   225
\begin{frame}[c]
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   226
\frametitle{\begin{tabular}{c}CYK Algorithm\end{tabular}}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   227
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   228
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   229
\begin{itemize}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   230
\item runtime is \bl{$O(n^3)$}\bigskip
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   231
\item grammars need to be transferred into CNF
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   232
\end{itemize}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   233
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   234
\end{frame}}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   235
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   237
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   238
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   239
\mode<presentation>{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   240
\begin{frame}[c]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   241
\frametitle{\begin{tabular}{c}Parse Trees\end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   242
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   243
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   244
\bl{\begin{tabular}{lcl}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   245
$E$ & $\rightarrow$ &  $F \;|\; F \cdot * \cdot F$\\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   246
$F$ & $\rightarrow$ & $T \;|\; T \cdot + \cdot T \;|\; T \cdot - \cdot T$\\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   247
$T$ & $\rightarrow$ & $num\_token \;|\; ( \cdot E \cdot )$\\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   248
\end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   249
\end{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   250
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   251
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   252
\begin{tikzpicture}[level distance=8mm, blue]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   253
  \node {$E$}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   254
    child {node {$F$} 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   255
     child {node {$T$} 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   256
                 child {node {(\,$E$\,)}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   257
                            child {node{$F$ *{} $F$}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   258
                                  child {node {$T$} child {node {2}}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   259
                                  child {node {$T$} child {node {3}}} 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   260
                               }
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   261
                          }
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   262
              }
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   263
     child {node {+}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   264
     child {node {$T$}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   265
       child {node {(\,$E$\,)} 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   266
       child {node {$F$}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   267
       child {node {$T$ +{} $T$}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   268
                    child {node {3}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   269
                    child {node {4}} 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   270
                 }
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   271
                 }}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   272
    }};
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   273
\end{tikzpicture}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   274
\end{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   275
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   276
\begin{textblock}{5}(1, 6.5)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   277
\bl{\texttt{(2*3)+(3+4)}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   278
\end{textblock}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   279
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   280
\end{frame}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   281
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   282
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   283
\mode<presentation>{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   284
\begin{frame}[c]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   285
\frametitle{\begin{tabular}{c}Ambiguous Grammars\end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   286
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   287
A CFG is \alert{ambiguous} if there is a string that has at least parse trees.
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   288
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   289
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   290
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   291
\bl{\begin{tabular}{lcl}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   292
$E$ & $\rightarrow$ &  $num\_token$ \\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   293
$E$ & $\rightarrow$ &  $E \cdot + \cdot E$ \\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   294
$E$ & $\rightarrow$ &  $E \cdot - \cdot E$ \\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   295
$E$ & $\rightarrow$ &  $E \cdot * \cdot E$ \\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   296
$E$ & $\rightarrow$ &  $( \cdot E \cdot )$ 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   297
\end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   298
\end{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   299
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   300
\bl{\texttt{1 + 2 * 3 + 4}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   301
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   302
\end{frame}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   303
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   304
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   305
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   306
\mode<presentation>{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   307
\begin{frame}[c]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   308
\frametitle{\begin{tabular}{c}Dangling Else\end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   309
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   310
Another ambiguous grammar:\bigskip
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   311
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   312
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   313
\bl{\begin{tabular}{lcl}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   314
$E$ & $\rightarrow$ &  if $E$ then $E$\\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   315
 & $|$ &  if $E$ then $E$ else $E$ \\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   316
 & $|$ &  id 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   317
\end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   318
\end{center}\bigskip
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   319
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   320
\bl{\texttt{if a then if x then y else c}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   321
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   322
\end{frame}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   323
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   324
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   325
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   326
\mode<presentation>{
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   327
\begin{frame}[c]
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   328
\frametitle{\begin{tabular}{c}A CFG Derivation\end{tabular}}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   329
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   330
\begin{enumerate}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   331
\item Begin with a string with only the start symbol \bl{$S$}\bigskip
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   332
\item Replace any non-terminal \bl{$X$} in the string by the
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   333
right-hand side of some production \bl{$X \rightarrow \text{rhs}$}\bigskip
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   334
\item Repeat 2 until there are no non-terminals
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   335
\end{enumerate}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   336
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   337
\begin{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   338
\bl{$S \rightarrow \ldots \rightarrow \ldots  \rightarrow \ldots  \rightarrow \ldots $}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   339
\end{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   340
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   341
\end{frame}}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   342
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   343
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   344
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   345
\end{document}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   346
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   347
%%% Local Variables:  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   348
%%% mode: latex
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   349
%%% TeX-master: t
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   350
%%% End: 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   351