slides/slides07.tex
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Mon, 11 Nov 2013 23:24:38 +0000
changeset 185 ea8b94d4755e
parent 184 2e9134d25a2b
child 186 fab34204d08e
permissions -rw-r--r--
added
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>{
185
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   155
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   156
\frametitle{\begin{tabular}{c}Arithmetic Expressions\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   157
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   158
A grammar for arithmetic expressions and numbers:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   159
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   160
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   161
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   162
$E$ & $\rightarrow$ &  $E \cdot + \cdot E \;|\;E \cdot * \cdot E \;|\;( \cdot E \cdot ) \;|\;N$ \\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   163
$N$ & $\rightarrow$ & $N \cdot N \;|\; 0 \;|\; 1 \;|\: \ldots \;|\; 9$ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   164
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   165
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   166
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   167
Unfortunately left-recursive (and ambiguous).\medskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   168
A problem for \alert{recursive descent parsers} (e.g.~parser combinators).
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   169
\bigskip\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   170
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   171
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   172
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   173
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   174
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   175
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   176
\mode<presentation>{
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   177
\begin{frame}[t]
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   178
\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
   179
185
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   180
184
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
\begin{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   183
\bl{\begin{tabular}{lcl}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   184
$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
   185
\end{tabular}}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   186
\end{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   187
185
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   188
A non-left-recursive, non-ambiguous grammar for numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   189
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   190
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   191
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   192
$N$ & $\rightarrow$ &  $0 \cdot N \;|\;1 \cdot N \;|\;\ldots\;|\; 0 \;|\; 1 \;|\; \ldots \;|\; 9$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   193
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   194
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   195
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   197
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   198
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   199
185
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   200
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   201
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   202
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   203
\frametitle{\begin{tabular}{c}Operator Precedences\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   204
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   205
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   206
To disambiguate
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   207
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   208
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   209
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   210
$E$ & $\rightarrow$ &  $E \cdot + \cdot E \;|\;E \cdot * \cdot E \;|\;( \cdot E \cdot ) \;|\;N$ \\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   211
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   212
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   213
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   214
Decide how many precedence levels, say\medskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   215
\hspace{5mm}highest for \bl{$()$}, medium for \bl{*}, lowest for \bl{+}
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   216
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   217
\begin{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   218
\bl{\begin{tabular}{lcl}
185
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   219
$E_{low}$ & $\rightarrow$ & $E_{med} \cdot + \cdot E_{low} \;|\; E_{med}$ \\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   220
$E_{med}$ & $\rightarrow$ & $E_{hi} \cdot * \cdot E_{med} \;|\; E_{hi}$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   221
$E_{hi}$ & $\rightarrow$ &  $( \cdot E_{low} \cdot ) \;|\;N$ \\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   222
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   223
\end{center}\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   224
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   225
\small What happens with \bl{$1 + 3  + 4$}?
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   226
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   227
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   228
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   229
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   230
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   231
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   232
\frametitle{\begin{tabular}{c}Removing Left-Recursion\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   233
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   234
The rule for numbers is directly left-recursive:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   235
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   236
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   237
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   238
$N$ & $\rightarrow$ & $N \cdot N \;|\; 0 \;|\; 1\;\;\;\;(\ldots)$ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   239
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   240
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   241
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   242
Translate
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   243
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   244
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   245
\begin{tabular}{ccc}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   246
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   247
$N$ & $\rightarrow$ & $N \cdot \alpha$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   248
 &  $\;|\;$ & $\beta$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   249
 \\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   250
\end{tabular}} 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   251
& {\Large$\Rightarrow$} &
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   252
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   253
$N$ & $\rightarrow$ & $\beta \cdot N'$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   254
$N'$ & $\rightarrow$ & $\alpha \cdot N'$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   255
 &  $\;|\;$ & $\epsilon$ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   256
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   257
\end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   258
\end{center}\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   259
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   260
Which means
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   261
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   262
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   263
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   264
$N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1 \cdot N'$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   265
$N'$ & $\rightarrow$ & $N \cdot N' \;|\; \epsilon$\\
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   266
\end{tabular}}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   267
\end{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   268
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   269
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   270
\end{frame}}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   271
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   272
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   273
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   274
\mode<presentation>{
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   275
\begin{frame}[c]
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   276
\frametitle{\begin{tabular}{c}Chomsky Normal Form\end{tabular}}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   277
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   278
All rules must be of the form
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   279
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   280
\begin{center}
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   281
\bl{$A \rightarrow a$}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   282
\end{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   283
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   284
or
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   285
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   286
\begin{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   287
\bl{$A \rightarrow B\cdot C$}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   288
\end{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   289
185
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   290
No rule can contain \bl{$\epsilon$}.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   291
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   292
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   293
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   294
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   295
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   296
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   297
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   298
\frametitle{\begin{tabular}{c}$\epsilon$-Removal\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   299
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   300
\begin{enumerate}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   301
\item If \bl{$A\rightarrow \alpha \cdot B \cdot \beta$} and \bl{$B \rightarrow \epsilon$} are in the grammar,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   302
then add \bl{$A\rightarrow \alpha \cdot \beta$} (iterate if necessary).
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   303
\item Throw out all \bl{$B \rightarrow \epsilon$}.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   304
\end{enumerate}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   305
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   306
\small
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   307
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   308
\begin{tabular}{ccc}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   309
\bl{\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   310
$N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1\cdot N'$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   311
$N'$ & $\rightarrow$ & $N \cdot N'\;|\;\epsilon$ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   312
\end{tabular}} &
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   313
\bl{\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   314
$N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1\cdot N'\;|\;0\;|\;1$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   315
$N'$ & $\rightarrow$ & $N \cdot N'\;|\;N\;|\;\epsilon$ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   316
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   317
\end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   318
\end{center}
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   319
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   320
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   321
\end{frame}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   322
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
185
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   323
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   324
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   325
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   326
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   327
\mode<presentation>{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   328
\begin{frame}[c]
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   329
\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
   330
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   331
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   332
\begin{center}
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   333
\bl{\begin{tabular}{@ {}lcl}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   334
$S$ & $\rightarrow$ &  $N\cdot P$ \\
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   335
$P$ & $\rightarrow$ &  $V\cdot N$ \\
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   336
$N$ & $\rightarrow$ &  $N\cdot N$ \\
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   337
$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
   338
$V$ & $\rightarrow$ &  $\texttt{trains}$ 
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   339
\end{tabular}}
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   340
\end{center}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   341
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   342
\bl{\texttt{Jeff trains geometry students}}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   343
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   344
\end{frame}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   345
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   346
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   347
\mode<presentation>{
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   348
\begin{frame}[c]
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   349
\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
   350
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   351
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   352
\begin{itemize}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   353
\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
   354
\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
   355
\end{itemize}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   356
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   357
\end{frame}}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   358
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   359
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   360
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   361
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   362
\mode<presentation>{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   363
\begin{frame}[c]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   364
\frametitle{\begin{tabular}{c}Parse Trees\end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   365
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   366
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   367
\bl{\begin{tabular}{lcl}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   368
$E$ & $\rightarrow$ &  $F \;|\; F \cdot * \cdot F$\\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   369
$F$ & $\rightarrow$ & $T \;|\; T \cdot + \cdot T \;|\; T \cdot - \cdot T$\\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   370
$T$ & $\rightarrow$ & $num\_token \;|\; ( \cdot E \cdot )$\\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   371
\end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   372
\end{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   373
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   374
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   375
\begin{tikzpicture}[level distance=8mm, blue]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   376
  \node {$E$}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   377
    child {node {$F$} 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   378
     child {node {$T$} 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   379
                 child {node {(\,$E$\,)}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   380
                            child {node{$F$ *{} $F$}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   381
                                  child {node {$T$} child {node {2}}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   382
                                  child {node {$T$} child {node {3}}} 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   383
                               }
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   384
                          }
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   385
              }
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   386
     child {node {+}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   387
     child {node {$T$}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   388
       child {node {(\,$E$\,)} 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   389
       child {node {$F$}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   390
       child {node {$T$ +{} $T$}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   391
                    child {node {3}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   392
                    child {node {4}} 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   393
                 }
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   394
                 }}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   395
    }};
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   396
\end{tikzpicture}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   397
\end{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   398
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   399
\begin{textblock}{5}(1, 6.5)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   400
\bl{\texttt{(2*3)+(3+4)}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   401
\end{textblock}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   402
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   403
\end{frame}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   404
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   405
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   406
\mode<presentation>{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   407
\begin{frame}[c]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   408
\frametitle{\begin{tabular}{c}Ambiguous Grammars\end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   409
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   410
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
   411
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   412
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   413
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   414
\bl{\begin{tabular}{lcl}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   415
$E$ & $\rightarrow$ &  $num\_token$ \\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   416
$E$ & $\rightarrow$ &  $E \cdot + \cdot E$ \\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   417
$E$ & $\rightarrow$ &  $E \cdot - \cdot E$ \\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   418
$E$ & $\rightarrow$ &  $E \cdot * \cdot E$ \\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   419
$E$ & $\rightarrow$ &  $( \cdot E \cdot )$ 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   420
\end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   421
\end{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   422
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   423
\bl{\texttt{1 + 2 * 3 + 4}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   424
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   425
\end{frame}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   426
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   427
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   428
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   429
\mode<presentation>{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   430
\begin{frame}[c]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   431
\frametitle{\begin{tabular}{c}Dangling Else\end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   432
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   433
Another ambiguous grammar:\bigskip
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   434
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   435
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   436
\bl{\begin{tabular}{lcl}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   437
$E$ & $\rightarrow$ &  if $E$ then $E$\\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   438
 & $|$ &  if $E$ then $E$ else $E$ \\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   439
 & $|$ &  id 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   440
\end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   441
\end{center}\bigskip
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   442
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   443
\bl{\texttt{if a then if x then y else c}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   444
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   445
\end{frame}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   446
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   447
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   448
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   449
\mode<presentation>{
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   450
\begin{frame}[c]
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   451
\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
   452
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   453
\begin{enumerate}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   454
\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
   455
\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
   456
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
   457
\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
   458
\end{enumerate}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   459
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   460
\begin{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   461
\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
   462
\end{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   463
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   464
\end{frame}}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   465
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   466
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   467
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   468
\end{document}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   469
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   470
%%% Local Variables:  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   471
%%% mode: latex
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   472
%%% TeX-master: t
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   473
%%% End: 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   474