slides/slides07.tex
author Christian Urban <urbanc@in.tum.de>
Tue, 13 Nov 2018 08:16:48 +0000
changeset 600 d488a3e7b0ec
parent 500 c502933be072
child 608 3db4970ad0aa
permissions -rw-r--r--
updated
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}
302
0fa7b4221745 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
     2
\usepackage{../slides}
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
     3
\usepackage{../graphics}
215
828303e8e4af updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 188
diff changeset
     4
\usepackage{../langs}
828303e8e4af updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 188
diff changeset
     5
\usepackage{../data}
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
     6
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
     7
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
% beamer stuff 
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 387
diff changeset
     9
\renewcommand{\slidecaption}{CFL 07, King's College London}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
\newcommand{\bl}[1]{\textcolor{blue}{#1}}       
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    11
%\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
\begin{document}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
302
0fa7b4221745 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    16
\begin{frame}[t]
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
\frametitle{%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
  \begin{tabular}{@ {}c@ {}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
  \\[-3mm]
451
4a5876f321ae updated
Christian Urban <urbanc@in.tum.de>
parents: 387
diff changeset
    20
  \LARGE Compilers and \\[-2mm] 
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    21
  \LARGE Formal Languages (7)\\[3mm] 
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
  \end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
  \normalsize
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
  \begin{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
  \begin{tabular}{ll}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
  Email:  & christian.urban at kcl.ac.uk\\
600
d488a3e7b0ec updated
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
    28
  Office: & N\liningnums{7.07} (North Wing, Bush House)\\
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
  Slides: & KEATS (also home work is there)\\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
  \end{tabular}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
  \end{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
302
0fa7b4221745 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    33
\end{frame}
0fa7b4221745 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    34
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    36
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    37
\newcommand{\qq}{\mbox{\texttt{"}}}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
\begin{frame}[c]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    40
\frametitle{CFGs}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    41
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    42
A \alert{context-free} grammar (CFG) \bl{$G$} consists of:
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    44
\begin{itemize}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    45
\item a finite set of nonterminal symbols (upper case)
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    46
\item a finite terminal symbols or tokens (lower case)
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    47
\item a start symbol (which must be a nonterminal)
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    48
\item a set of rules
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
\begin{center}
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    50
\bl{$A \rightarrow \text{rhs}_1 | \text{rhs}_2 | \ldots$}
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    51
\end{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    52
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    53
where \bl{rhs} are sequences involving terminals and nonterminals (can also be empty).\medskip\pause
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    54
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    55
\end{itemize}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    56
369
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 302
diff changeset
    57
\end{frame}
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    58
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    59
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
    60
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    61
\mode<presentation>{
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    62
\begin{frame}[c]
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    63
\frametitle{\begin{tabular}{c}Hierarchy of Languages\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    64
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    65
Recall that languages are sets of strings.
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    66
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    67
\begin{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    68
\begin{tikzpicture}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    69
[rect/.style={draw=black!50, top color=white,bottom color=black!20, rectangle, very thick, rounded corners}]
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    70
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    71
\draw (0,0) node [rect, text depth=39mm, text width=68mm] {all languages};
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    72
\draw (0,-0.4) node [rect, text depth=28.5mm, text width=64mm] {decidable languages};
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    73
\draw (0,-0.85) node [rect, text depth=17mm] {context sensitive languages};
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    74
\draw (0,-1.14) node [rect, text depth=9mm, text width=50mm] {context-free languages};
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    75
\draw (0,-1.4) node [rect] {regular languages};
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    76
\end{tikzpicture}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    77
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    78
\end{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    79
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    80
\end{frame}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    81
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    82
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    83
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    84
\mode<presentation>{
185
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
    85
\begin{frame}[c]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    86
\frametitle{\begin{tabular}{c}Arithmetic Expressions\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    87
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    88
A grammar for arithmetic expressions and numbers:
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    89
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    90
\begin{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    91
\bl{\begin{tabular}{lcl}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    92
$E$ & $\rightarrow$ &  $E \cdot + \cdot E \;|\;E \cdot * \cdot E \;|\;( \cdot E \cdot ) \;|\;N$ \\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    93
$N$ & $\rightarrow$ & $N \cdot N \;|\; 0 \;|\; 1 \;|\: \ldots \;|\; 9$ 
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    94
\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    95
\end{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    96
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    97
Unfortunately it is left-recursive (and ambiguous).\medskip\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    98
A problem for \alert{recursive descent parsers} (e.g.~parser combinators).
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
    99
\bigskip\pause
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   100
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   101
\end{frame}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   102
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   103
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   104
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   105
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   106
\mode<presentation>{
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   107
\begin{frame}[t]
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   108
\frametitle{\begin{tabular}{c}Numbers\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   109
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   110
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   111
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   112
\begin{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   113
\bl{\begin{tabular}{lcl}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   114
$N$ & $\rightarrow$ &  $N \cdot N \;|\; 0 \;|\; 1 \;|\; \ldots \;|\; 9$\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   115
\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   116
\end{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   117
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   118
A non-left-recursive, non-ambiguous grammar for numbers:
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   119
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   120
\begin{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   121
\bl{\begin{tabular}{lcl}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   122
$N$ & $\rightarrow$ &  $0 \cdot N \;|\;1 \cdot N \;|\;\ldots\;|\; 0 \;|\; 1 \;|\; \ldots \;|\; 9$\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   123
\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   124
\end{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   125
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   126
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   127
\end{frame}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   128
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   129
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   130
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   131
\mode<presentation>{
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   132
\begin{frame}[c]
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   133
\frametitle{\begin{tabular}{c}Operator Precedences\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   134
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   135
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   136
To disambiguate
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   137
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   138
\begin{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   139
\bl{\begin{tabular}{lcl}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   140
$E$ & $\rightarrow$ &  $E \cdot + \cdot E \;|\;E \cdot * \cdot E \;|\;( \cdot E \cdot ) \;|\;N$ \\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   141
\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   142
\end{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   143
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   144
Decide on how many precedence levels, say\medskip\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   145
\hspace{5mm}highest for \bl{$()$}, medium for \bl{*}, lowest for \bl{+}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   146
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   147
\begin{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   148
\bl{\begin{tabular}{lcl}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   149
$E_{low}$ & $\rightarrow$ & $E_{med} \cdot + \cdot E_{low} \;|\; E_{med}$ \\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   150
$E_{med}$ & $\rightarrow$ & $E_{hi} \cdot * \cdot E_{med} \;|\; E_{hi}$\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   151
$E_{hi}$ & $\rightarrow$ &  $( \cdot E_{low} \cdot ) \;|\;N$ \\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   152
\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   153
\end{center}\pause
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   154
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   155
\small What happens with \bl{$1 + 3  + 4$}?
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   156
\end{frame}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   157
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   158
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   159
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   160
\mode<presentation>{
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   161
\begin{frame}[c]
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   162
\frametitle{\begin{tabular}{c}Removing Left-Recursion\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   163
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   164
The rule for numbers is directly left-recursive:
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   165
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   166
\begin{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   167
\bl{\begin{tabular}{lcl}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   168
$N$ & $\rightarrow$ & $N \cdot N \;|\; 0 \;|\; 1\;\;\;\;(\ldots)$ 
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   169
\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   170
\end{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   171
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   172
Translate
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   173
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   174
\begin{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   175
\begin{tabular}{ccc}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   176
\bl{\begin{tabular}{lcl}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   177
$N$ & $\rightarrow$ & $N \cdot \alpha$\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   178
 &  $\;|\;$ & $\beta$\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   179
 \\ 
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   180
\end{tabular}} 
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   181
& {\Large$\Rightarrow$} &
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   182
\bl{\begin{tabular}{lcl}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   183
$N$ & $\rightarrow$ & $\beta \cdot N'$\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   184
$N'$ & $\rightarrow$ & $\alpha \cdot N'$\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   185
 &  $\;|\;$ & $\epsilon$ 
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   186
\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   187
\end{tabular}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   188
\end{center}\pause
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   189
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   190
Which means
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   191
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   192
\begin{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   193
\bl{\begin{tabular}{lcl}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   194
$N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1 \cdot N'$\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   195
$N'$ & $\rightarrow$ & $N \cdot N' \;|\; \epsilon$\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   196
\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   197
\end{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   198
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   199
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   200
\end{frame}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   201
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   202
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   203
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   204
\mode<presentation>{
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   205
\begin{frame}[c]
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   206
\frametitle{\begin{tabular}{c}Chomsky Normal Form\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   207
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   208
All rules must be of the form
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   209
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   210
\begin{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   211
\bl{$A \rightarrow a$}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   212
\end{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   213
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   214
or
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   215
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   216
\begin{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   217
\bl{$A \rightarrow B\cdot C$}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   218
\end{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   219
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   220
No rule can contain \bl{$\epsilon$}.
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   221
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   222
\end{frame}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   223
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   224
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   225
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   226
\mode<presentation>{
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   227
\begin{frame}[c]
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   228
\frametitle{\begin{tabular}{c}$\epsilon$-Removal\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   229
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   230
\begin{enumerate}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   231
\item If \bl{$A\rightarrow \alpha \cdot B \cdot \beta$} and \bl{$B \rightarrow \epsilon$} are in the grammar,
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   232
then add \bl{$A\rightarrow \alpha \cdot \beta$} (iterate if necessary).
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   233
\item Throw out all \bl{$B \rightarrow \epsilon$}.
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   234
\end{enumerate}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   235
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   236
\small
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   237
\begin{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   238
\begin{tabular}{ccc}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   239
\bl{\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   240
$N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1\cdot N'$\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   241
$N'$ & $\rightarrow$ & $N \cdot N'\;|\;\epsilon$\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   242
\\ 
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   243
\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   244
\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   245
\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   246
\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   247
\end{tabular}} &
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   248
\bl{\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   249
\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   250
$N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1\cdot N'\;|\;0\;|\;1$\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   251
$N'$ & $\rightarrow$ & $N \cdot N'\;|\;N\;|\;\epsilon$\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   252
\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   253
$N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1\cdot N'\;|\;0\;|\;1$\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   254
$N'$ & $\rightarrow$ & $N \cdot N'\;|\;N$\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   255
\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   256
\end{tabular}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   257
\end{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   258
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   259
\pause\normalsize
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   260
\begin{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   261
\bl{\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   262
$N$ & $\rightarrow$ & $0 \cdot N\;|\; 1\cdot N\;|\;0\;|\;1$\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   263
\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   264
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   265
\end{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   266
\end{frame}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   267
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   268
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   269
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   270
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   271
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   272
\mode<presentation>{
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   273
\begin{frame}[c]
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   274
\frametitle{\begin{tabular}{c}CYK Algorithm\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   275
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   276
If grammar is in Chomsky normalform \ldots
187
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   277
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   278
\begin{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   279
\bl{\begin{tabular}{@ {}lcl@ {}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   280
$S$ & $\rightarrow$ &  $N\cdot P$ \\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   281
$P$ & $\rightarrow$ &  $V\cdot N$ \\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   282
$N$ & $\rightarrow$ &  $N\cdot N$ \\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   283
$N$ & $\rightarrow$ &  $\texttt{students} \;|\; \texttt{Jeff} \;|\; \texttt{geometry} \;|\; \texttt{trains} $ \\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   284
$V$ & $\rightarrow$ &  $\texttt{trains}$ 
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   285
\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   286
\end{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   287
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   288
\bl{\texttt{Jeff trains geometry students}}
187
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   289
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   290
\end{frame}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   291
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   292
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   293
\mode<presentation>{
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   294
\begin{frame}[c]
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   295
\frametitle{\begin{tabular}{c}CYK Algorithm\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   296
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   297
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   298
\begin{itemize}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   299
\item fastest possible algorithm for recognition problem
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   300
\item runtime is \bl{$O(n^3)$}\bigskip
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   301
\item grammars need to be transferred into CNF
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   302
\end{itemize}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   303
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   304
\end{frame}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   305
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   306
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   307
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   308
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   309
\mode<presentation>{
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   310
\begin{frame}[c]
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   311
\frametitle{\begin{tabular}{c}Hierarchy of Languages\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   312
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   313
Recall that languages are sets of strings.
187
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   314
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   315
\begin{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   316
\begin{tikzpicture}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   317
[rect/.style={draw=black!50, top color=white,bottom color=black!20, rectangle, very thick, rounded corners}]
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   318
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   319
\draw (0,0) node [rect, text depth=39mm, text width=68mm] {all languages};
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   320
\draw (0,-0.4) node [rect, text depth=28.5mm, text width=64mm] {decidable languages};
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   321
\draw (0,-0.85) node [rect, text depth=17mm] {context sensitive languages};
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   322
\draw (0,-1.14) node [rect, text depth=9mm, text width=50mm] {context-free languages};
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   323
\draw (0,-1.4) node [rect] {regular languages};
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   324
\end{tikzpicture}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   325
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   326
\end{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   327
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   328
\end{frame}}
187
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   329
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   330
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   331
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   332
\mode<presentation>{
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   333
\begin{frame}[c]
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   334
\frametitle{\begin{tabular}{c}Context Sensitive Grms\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   335
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   336
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   337
\begin{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   338
\bl{\begin{tabular}{lcl}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   339
$S$ & $\Rightarrow$ &  $bSAA\;|\; \epsilon$\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   340
$A$ & $\Rightarrow$ & $a$\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   341
$bA$ & $\Rightarrow$ & $Ab$\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   342
\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   343
\end{center}\pause
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   344
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   345
\begin{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   346
\bl{$S \Rightarrow\ldots\Rightarrow^? "ababaa"$}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   347
\end{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   348
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   349
\end{frame}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   350
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   351
187
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   352
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   353
\mode<presentation>{
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   354
\begin{frame}[c]
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   355
187
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   356
\begin{center}
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   357
\bl{\begin{tabular}{@{}lcl@{}}
187
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   358
\textit{Stmt} & $\rightarrow$ &  $\texttt{skip}$\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   359
              & $|$ & \textit{Id}\;\texttt{:=}\;\textit{AExp}\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   360
              & $|$ & \texttt{if}\; \textit{BExp} \;\texttt{then}\; \textit{Block} \;\texttt{else}\; \textit{Block}\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   361
              & $|$ & \texttt{while}\; \textit{BExp} \;\texttt{do}\; \textit{Block}\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   362
              & $|$ & \texttt{read}\;\textit{Id}\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   363
              & $|$ & \texttt{write}\;\textit{Id}\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   364
              & $|$ & \texttt{write}\;\textit{String}\medskip\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   365
\textit{Stmts} & $\rightarrow$ &  \textit{Stmt} \;\texttt{;}\; \textit{Stmts}\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   366
              & $|$ & \textit{Stmt}\medskip\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   367
\textit{Block} & $\rightarrow$ &  \texttt{\{}\,\textit{Stmts}\,\texttt{\}}\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   368
                & $|$ & \textit{Stmt}\medskip\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   369
\textit{AExp} & $\rightarrow$ & \ldots\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   370
\textit{BExp} & $\rightarrow$ & \ldots\\
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   371
\end{tabular}}
187
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   372
\end{center}
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   373
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   374
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   375
369
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 302
diff changeset
   376
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   377
\mode<presentation>{
369
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 302
diff changeset
   378
\begin{frame}[c]
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 302
diff changeset
   379
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   380
\mbox{\lstinputlisting[language=while]{../progs/fib.while}}
369
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 302
diff changeset
   381
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   382
\end{frame}}
369
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 302
diff changeset
   383
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   384
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   385
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   386
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   387
\mode<presentation>{
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   388
\begin{frame}[c]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   389
\frametitle{\begin{tabular}{c}An Interpreter\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   390
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   391
\begin{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   392
\bl{\begin{tabular}{l}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   393
$\{$\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   394
\;\;$x := 5 \text{;}$\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   395
\;\;$y := x * 3\text{;}$\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   396
\;\;$y := x * 4\text{;}$\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   397
\;\;$x := u * 3$\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   398
$\}$
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   399
\end{tabular}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   400
\end{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   401
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   402
\begin{itemize}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   403
\item the interpreter has to record the value of \bl{$x$} before assigning a value to \bl{$y$}\pause
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   404
\item \bl{\text{eval}(stmt, env)}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   405
\end{itemize}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   406
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   407
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   408
\end{frame}}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   409
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   410
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   411
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   412
\mode<presentation>{
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   413
\begin{frame}[c]
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   414
\frametitle{\begin{tabular}{c}Interpreter\end{tabular}}
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   415
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   416
\begin{center}
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   417
\bl{\begin{tabular}{@{}lcl@{}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   418
$\text{eval}(n, E)$ & $\dn$ & $n$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   419
$\text{eval}(x, E)$ & $\dn$ & $E(x)$ \;\;\;\textcolor{black}{lookup \bl{$x$} in \bl{$E$}}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   420
$\text{eval}(a_1 + a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) + \text{eval}(a_2, E)$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   421
$\text{eval}(a_1 - a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) - \text{eval}(a_2, E)$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   422
$\text{eval}(a_1 * a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) * \text{eval}(a_2, E)$\bigskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   423
$\text{eval}(a_1 = a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) = \text{eval}(a_2, E)$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   424
$\text{eval}(a_1\,!\!= a_2, E)$ & $\dn$ & $\neg(\text{eval}(a_1, E) = \text{eval}(a_2, E))$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   425
$\text{eval}(a_1 < a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) < \text{eval}(a_2, E)$\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   426
\end{tabular}}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   427
\end{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   428
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   429
\end{frame}}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   430
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   431
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   432
\mode<presentation>{
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   433
\begin{frame}[c]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   434
\frametitle{\begin{tabular}{c}Interpreter (2)\end{tabular}}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   435
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   436
\begin{center}
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   437
\bl{\begin{tabular}{@{}lcl@{}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   438
$\text{eval}(\text{skip}, E)$ & $\dn$ & $E$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   439
$\text{eval}(x:=a, E)$ & $\dn$ & \bl{$E(x \mapsto \text{eval}(a, E))$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   440
\multicolumn{3}{@{}l@{}}{$\text{eval}(\text{if}\;b\;\text{then}\;cs_1\;\text{else}\;cs_2 , E) \dn$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   441
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)\;\text{then}\;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   442
\text{eval}(cs_1,E)$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   443
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\phantom{\text{if}\;\text{eval}(b,E)\;}\text{else}\;\text{eval}(cs_2,E)$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   444
\multicolumn{3}{@{}l@{}}{$\text{eval}(\text{while}\;b\;\text{do}\;cs, E) \dn$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   445
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   446
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{then}\;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   447
\text{eval}(\text{while}\;b\;\text{do}\;cs, \text{eval}(cs,E))$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   448
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{else}\; E$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   449
$\text{eval}(\text{write}\; x, E)$ & $\dn$ & $\{\;\text{println}(E(x))\; ;\;E\;\}$\\
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   450
\end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   451
\end{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   452
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   453
\end{frame}}
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   454
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   455
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   456
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   457
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   458
\mode<presentation>{
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   459
\begin{frame}[c]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   460
\frametitle{\begin{tabular}{c}Test Program\end{tabular}}
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   461
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   462
\mbox{}\\[-18mm]\mbox{}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   463
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   464
{\lstset{language=While}%%\fontsize{10}{12}\selectfont
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   465
\texttt{\lstinputlisting{../progs/loops.while}}}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   466
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   467
\end{frame}}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   468
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   469
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   470
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   471
\mode<presentation>{
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   472
\begin{frame}[t]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   473
\frametitle{\begin{tabular}{c}Interpreted Code\end{tabular}}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   474
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   475
\begin{center}
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   476
\begin{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   477
\begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   478
\addplot+[smooth] file {interpreted.data};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   479
\end{axis}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   480
\end{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   481
\end{center}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   482
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   483
\end{frame}}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   484
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   485
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   486
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   487
\mode<presentation>{
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   488
\begin{frame}[c]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   489
\frametitle{\begin{tabular}{c}Java Virtual Machine\end{tabular}}
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   490
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   491
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   492
\item introduced in 1995
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   493
\item is a stack-based VM (like Postscript, CLR of .Net)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   494
\item contains a JIT compiler
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   495
\item many languages take advantage of JVM's infrastructure (JRE)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   496
\item is garbage collected $\Rightarrow$ no buffer overflows
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 374
diff changeset
   497
\item some languages compile to the JVM: Scala, Clojure\ldots
369
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 302
diff changeset
   498
\end{itemize}
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 302
diff changeset
   499
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 302
diff changeset
   500
\end{frame}}
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 302
diff changeset
   501
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
43c0ed473720 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 302
diff changeset
   502
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   503
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   504
\end{document}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   505
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   506
%%% Local Variables:  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   507
%%% mode: latex
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   508
%%% TeX-master: t
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   509
%%% End: 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   510