slides/slides07.tex
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Wed, 13 Nov 2013 06:40:37 +0000
changeset 188 12ef150273ce
parent 187 9471a0325773
child 215 828303e8e4af
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} 
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
    23
\usepackage{pgfplots}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
\definecolor{javared}{rgb}{0.6,0,0} % for strings
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
\definecolor{javagreen}{rgb}{0.25,0.5,0.35} % comments
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
\definecolor{javapurple}{rgb}{0.5,0,0.35} % keywords
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
\definecolor{javadocblue}{rgb}{0.25,0.35,0.75} % javadoc
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
\lstset{language=Java,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
	basicstyle=\ttfamily,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
	keywordstyle=\color{javapurple}\bfseries,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
	stringstyle=\color{javagreen},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
	commentstyle=\color{javagreen},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
	morecomment=[s][\color{javadocblue}]{/**}{*/},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
	numbers=left,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
	numberstyle=\tiny\color{black},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
	stepnumber=1,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
	numbersep=10pt,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
	tabsize=2,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
	showspaces=false,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
	showstringspaces=false}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
\lstdefinelanguage{scala}{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
  morekeywords={abstract,case,catch,class,def,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
    do,else,extends,false,final,finally,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
    for,if,implicit,import,match,mixin,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
    new,null,object,override,package,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
    private,protected,requires,return,sealed,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
    super,this,throw,trait,true,try,%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
    type,val,var,while,with,yield},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
  otherkeywords={=>,<-,<\%,<:,>:,\#,@},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
  sensitive=true,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
  morecomment=[l]{//},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
  morecomment=[n]{/*}{*/},
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
  morestring=[b]"""
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
\lstset{language=Scala,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
	basicstyle=\ttfamily,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
	keywordstyle=\color{javapurple}\bfseries,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
	stringstyle=\color{javagreen},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
	commentstyle=\color{javagreen},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
	morecomment=[s][\color{javadocblue}]{/**}{*/},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
	numbers=left,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
	numberstyle=\tiny\color{black},
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
	stepnumber=1,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
	numbersep=10pt,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
	tabsize=2,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
	showspaces=false,
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
	showstringspaces=false}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
    75
\lstdefinelanguage{While}{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
    76
  morekeywords={while, if, then. else, read, write},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
    77
  otherkeywords={=>,<-,<\%,<:,>:,\#,@},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
    78
  sensitive=true,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
    79
  morecomment=[l]{//},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
    80
  morecomment=[n]{/*}{*/},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
    81
  morestring=[b]",
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
    82
  morestring=[b]',
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
    83
  morestring=[b]"""
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
    84
}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
    85
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
    86
187
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
    87
\setmonofont{Consolas}
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
    88
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
    89
\begin{filecontents}{interpreted.data}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
    90
%1 0.00503
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
    91
200 1.005863
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
    92
400 7.8296765
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
    93
500 15.43106
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
    94
600 27.2321885
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
    95
800 65.249271
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
    96
1000 135.4493445
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
    97
1200 232.134097
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
    98
1400 382.527227
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
    99
\end{filecontents}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   100
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
% beamer stuff 
173
7cfb7a6f7c99 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   102
\renewcommand{\slidecaption}{AFL 07, King's College London, 13.~November 2013}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
\newcommand{\bl}[1]{\textcolor{blue}{#1}}       
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
\begin{document}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
\mode<presentation>{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
\begin{frame}<1>[t]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
\frametitle{%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
  \begin{tabular}{@ {}c@ {}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
  \\[-3mm]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
  \LARGE Automata and \\[-2mm] 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
  \LARGE Formal Languages (7)\\[3mm] 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
  \end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
  \normalsize
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
  \begin{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
  \begin{tabular}{ll}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
  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
   122
  Office: & S1.27 (1st floor Strand Building)\\
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
  Slides: & KEATS (also home work is there)\\
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
  \end{tabular}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
  \end{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
\end{frame}}
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
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
\newcommand{\qq}{\mbox{\texttt{"}}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
\mode<presentation>{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
\begin{frame}[c]
186
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 185
diff changeset
   136
\frametitle{\begin{tabular}{c}Two Weeks Ago: CFGs\end{tabular}}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
64
2d625418c011 added everything
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
   138
A \alert{context-free} grammar (CFG) \bl{$G$} consists of:
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
\begin{itemize}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
\item a finite set of nonterminal symbols (upper case)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
\item a finite terminal symbols or tokens (lower case)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
\item a start symbol (which must be a nonterminal)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
\item a set of rules
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
\begin{center}
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   146
\bl{$A \rightarrow \text{rhs}_1 | \text{rhs}_2 | \ldots$}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
\end{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
where \bl{rhs} are sequences involving terminals and nonterminals (can also be empty).\medskip\pause
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
\end{itemize}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
\end{frame}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
\mode<presentation>{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
\begin{frame}[c]
186
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 185
diff changeset
   160
\frametitle{\begin{tabular}{c}Hierarchy of Languages\end{tabular}}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   162
Recall that languages are sets of strings.
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
\begin{center}
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   165
\begin{tikzpicture}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   166
[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
   167
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   168
\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
   169
\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
   170
\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
   171
\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
   172
\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
   173
\end{tikzpicture}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   174
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
\end{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
\end{frame}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
\mode<presentation>{
185
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   182
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   183
\frametitle{\begin{tabular}{c}Arithmetic Expressions\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   184
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   185
A grammar for arithmetic expressions and numbers:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   186
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   187
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   188
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   189
$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
   190
$N$ & $\rightarrow$ & $N \cdot N \;|\; 0 \;|\; 1 \;|\: \ldots \;|\; 9$ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   191
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   192
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   193
187
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   194
Unfortunately it is left-recursive (and ambiguous).\medskip\\
185
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   195
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
   196
\bigskip\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   197
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   198
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   199
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
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
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   202
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   203
\mode<presentation>{
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   204
\begin{frame}[t]
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   205
\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
   206
185
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   207
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   208
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   209
\begin{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   210
\bl{\begin{tabular}{lcl}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   211
$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
   212
\end{tabular}}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   213
\end{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   214
187
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   215
A non-left-recursive, non-ambiguous grammar for numbers:
185
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   216
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   217
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   218
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   219
$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
   220
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   221
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   222
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   223
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   224
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   225
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   226
185
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
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   229
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   230
\frametitle{\begin{tabular}{c}Operator Precedences\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   231
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   232
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   233
To disambiguate
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   234
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   235
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   236
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   237
$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
   238
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   239
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   240
187
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   241
Decide on how many precedence levels, say\medskip\\
185
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   242
\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
   243
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   244
\begin{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   245
\bl{\begin{tabular}{lcl}
185
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   246
$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
   247
$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
   248
$E_{hi}$ & $\rightarrow$ &  $( \cdot E_{low} \cdot ) \;|\;N$ \\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   249
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   250
\end{center}\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   251
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   252
\small What happens with \bl{$1 + 3  + 4$}?
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   253
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   254
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   255
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   256
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   257
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   258
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   259
\frametitle{\begin{tabular}{c}Removing Left-Recursion\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   260
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   261
The rule for numbers is directly left-recursive:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   262
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   263
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   264
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   265
$N$ & $\rightarrow$ & $N \cdot N \;|\; 0 \;|\; 1\;\;\;\;(\ldots)$ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   266
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   267
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   268
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   269
Translate
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   270
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   271
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   272
\begin{tabular}{ccc}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   273
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   274
$N$ & $\rightarrow$ & $N \cdot \alpha$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   275
 &  $\;|\;$ & $\beta$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   276
 \\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   277
\end{tabular}} 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   278
& {\Large$\Rightarrow$} &
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   279
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   280
$N$ & $\rightarrow$ & $\beta \cdot N'$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   281
$N'$ & $\rightarrow$ & $\alpha \cdot N'$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   282
 &  $\;|\;$ & $\epsilon$ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   283
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   284
\end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   285
\end{center}\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   286
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   287
Which means
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   288
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   289
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   290
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   291
$N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1 \cdot N'$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   292
$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
   293
\end{tabular}}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   294
\end{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   295
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   296
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   297
\end{frame}}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   298
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   299
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   300
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   301
\mode<presentation>{
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   302
\begin{frame}[c]
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   303
\frametitle{\begin{tabular}{c}Chomsky Normal Form\end{tabular}}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   304
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   305
All rules must be of the form
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   306
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   307
\begin{center}
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   308
\bl{$A \rightarrow a$}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   309
\end{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   310
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   311
or
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   312
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   313
\begin{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   314
\bl{$A \rightarrow B\cdot C$}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   315
\end{center}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   316
185
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   317
No rule can contain \bl{$\epsilon$}.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   318
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   319
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   320
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   321
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   322
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   323
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   324
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   325
\frametitle{\begin{tabular}{c}$\epsilon$-Removal\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   326
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   327
\begin{enumerate}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   328
\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
   329
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
   330
\item Throw out all \bl{$B \rightarrow \epsilon$}.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   331
\end{enumerate}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   332
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   333
\small
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   334
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   335
\begin{tabular}{ccc}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   336
\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
   337
$N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1\cdot N'$\\
187
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   338
$N'$ & $\rightarrow$ & $N \cdot N'\;|\;\epsilon$\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   339
\\ 
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   340
\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   341
\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   342
\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   343
\\
185
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   344
\end{tabular}} &
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   345
\bl{\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}
187
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   346
\\
185
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   347
$N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1\cdot N'\;|\;0\;|\;1$\\
187
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   348
$N'$ & $\rightarrow$ & $N \cdot N'\;|\;N\;|\;\epsilon$\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   349
\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   350
$N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1\cdot N'\;|\;0\;|\;1$\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   351
$N'$ & $\rightarrow$ & $N \cdot N'\;|\;N$\\
185
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   352
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   353
\end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   354
\end{center}
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   355
187
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   356
\pause\normalsize
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   357
\begin{center}
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   358
\bl{\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   359
$N$ & $\rightarrow$ & $0 \cdot N\;|\; 1\cdot N\;|\;0\;|\;1$\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   360
\end{tabular}}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   361
187
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   362
\end{center}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   363
\end{frame}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   364
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
185
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   365
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   366
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 184
diff changeset
   367
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   368
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   369
\mode<presentation>{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   370
\begin{frame}[c]
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   371
\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
   372
187
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   373
If grammar is in Chomsky normalform \ldots
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   374
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   375
\begin{center}
187
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   376
\bl{\begin{tabular}{@ {}lcl@ {}}
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   377
$S$ & $\rightarrow$ &  $N\cdot P$ \\
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   378
$P$ & $\rightarrow$ &  $V\cdot N$ \\
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   379
$N$ & $\rightarrow$ &  $N\cdot N$ \\
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   380
$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
   381
$V$ & $\rightarrow$ &  $\texttt{trains}$ 
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   382
\end{tabular}}
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   383
\end{center}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   384
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   385
\bl{\texttt{Jeff trains geometry students}}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   386
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   387
\end{frame}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   388
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   389
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   390
\mode<presentation>{
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   391
\begin{frame}[c]
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   392
\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
   393
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   394
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   395
\begin{itemize}
187
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   396
\item fastest possible algorithm for recognition problem
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   397
\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
   398
\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
   399
\end{itemize}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   400
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   401
\end{frame}}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   402
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   403
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]
187
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   408
\frametitle{\begin{tabular}{c}Hierarchy of Languages\end{tabular}}
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   409
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   410
Recall that languages are sets of strings.
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   411
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   412
\begin{center}
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   413
\begin{tikzpicture}
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   414
[rect/.style={draw=black!50, top color=white,bottom color=black!20, rectangle, very thick, rounded corners}]
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   415
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   416
\draw (0,0) node [rect, text depth=39mm, text width=68mm] {all languages};
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   417
\draw (0,-0.4) node [rect, text depth=28.5mm, text width=64mm] {decidable languages};
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   418
\draw (0,-0.85) node [rect, text depth=17mm] {context sensitive languages};
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   419
\draw (0,-1.14) node [rect, text depth=9mm, text width=50mm] {context-free languages};
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   420
\draw (0,-1.4) node [rect] {regular languages};
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   421
\end{tikzpicture}
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   422
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   423
\end{center}
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   424
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   425
\end{frame}}
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   426
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   427
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   428
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   429
\mode<presentation>{
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   430
\begin{frame}[c]
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   431
\frametitle{\begin{tabular}{c}Context Sensitive Grms\end{tabular}}
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   432
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   433
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   434
\begin{center}
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   435
\bl{\begin{tabular}{lcl}
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   436
$S$ & $\Rightarrow$ &  $bSAA\;|\; \epsilon$\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   437
$A$ & $\Rightarrow$ & $a$\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   438
$bA$ & $\Rightarrow$ & $Ab$\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   439
\end{tabular}}
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   440
\end{center}\pause
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   441
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   442
\begin{center}
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   443
\bl{$S \Rightarrow\ldots\Rightarrow^? "ababaa"$}
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   444
\end{center}
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   445
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   446
\end{frame}}
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   447
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   448
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   449
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   450
\mode<presentation>{
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   451
\begin{frame}[c]
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   452
187
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   453
\begin{center}
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   454
\bl{\begin{tabular}{@{}lcl@{}}
187
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   455
\textit{Stmt} & $\rightarrow$ &  $\texttt{skip}$\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   456
              & $|$ & \textit{Id}\;\texttt{:=}\;\textit{AExp}\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   457
              & $|$ & \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
   458
              & $|$ & \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
   459
              & $|$ & \texttt{read}\;\textit{Id}\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   460
              & $|$ & \texttt{write}\;\textit{Id}\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   461
              & $|$ & \texttt{write}\;\textit{String}\medskip\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   462
\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
   463
              & $|$ & \textit{Stmt}\medskip\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   464
\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
   465
                & $|$ & \textit{Stmt}\medskip\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   466
\textit{AExp} & $\rightarrow$ & \ldots\\
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   467
\textit{BExp} & $\rightarrow$ & \ldots\\
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   468
\end{tabular}}
187
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   469
\end{center}
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   470
\end{frame}}
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   471
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   472
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   473
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   474
\mode<presentation>{
9471a0325773 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 186
diff changeset
   475
\begin{frame}[c]
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   476
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   477
\mbox{\lstinputlisting[language=while]{../progs/fib.while}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   478
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   479
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   480
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   481
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   482
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   483
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   484
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   485
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   486
\frametitle{\begin{tabular}{c}An Interpreter\end{tabular}}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   487
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   488
\begin{center}
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   489
\bl{\begin{tabular}{l}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   490
$\{$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   491
\;\;$x := 5 \text{;}$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   492
\;\;$y := x * 3\text{;}$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   493
\;\;$y := x * 4\text{;}$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   494
\;\;$x := u * 3$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   495
$\}$
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   496
\end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   497
\end{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   498
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   499
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   500
\item the interpreter has to record the value of \bl{$x$} before assigning a value to \bl{$y$}\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   501
\item \bl{\text{eval}(stmt, env)}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   502
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   503
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   504
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   505
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   506
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   507
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   508
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   509
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   510
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   511
\frametitle{\begin{tabular}{c}Interpreter\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   512
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   513
\begin{center}
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   514
\bl{\begin{tabular}{@{}lcl@{}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   515
$\text{eval}(n, E)$ & $\dn$ & $n$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   516
$\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
   517
$\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
   518
$\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
   519
$\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
   520
$\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
   521
$\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
   522
$\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
   523
\end{tabular}}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   524
\end{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   525
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   526
\end{frame}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   527
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   528
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   529
\mode<presentation>{
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   530
\begin{frame}[c]
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   531
\frametitle{\begin{tabular}{c}Interpreter (2)\end{tabular}}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   532
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   533
\begin{center}
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   534
\bl{\begin{tabular}{@{}lcl@{}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   535
$\text{eval}(\text{skip}, E)$ & $\dn$ & $E$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   536
$\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
   537
\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
   538
\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
   539
\text{eval}(cs_1,E)$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   540
\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
   541
\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
   542
\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
   543
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{then}\;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   544
\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
   545
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{else}\; E$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   546
$\text{eval}(\text{write}\; x, E)$ & $\dn$ & $\{\;\text{println}(E(x))\; ;\;E\;\}$\\
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   547
\end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   548
\end{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   549
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   550
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   551
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   552
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   553
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   554
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   555
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   556
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   557
\frametitle{\begin{tabular}{c}Test Program\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   558
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   559
\mbox{}\\[-18mm]\mbox{}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   560
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   561
{\lstset{language=While}%%\fontsize{10}{12}\selectfont
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   562
\texttt{\lstinputlisting{../progs/loops.while}}}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   563
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   564
\end{frame}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   565
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   566
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   567
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   568
\mode<presentation>{
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   569
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   570
\frametitle{\begin{tabular}{c}Interpreted Code\end{tabular}}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   571
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   572
\begin{center}
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   573
\begin{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   574
\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
   575
\addplot+[smooth] file {interpreted.data};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   576
\end{axis}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   577
\end{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   578
\end{center}
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   579
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   580
\end{frame}}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   581
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   582
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   583
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   584
\mode<presentation>{
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   585
\begin{frame}[c]
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   586
\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
   587
188
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   588
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   589
\item introduced in 1995
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   590
\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
   591
\item contains a JIT compiler
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   592
\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
   593
\item is garbage collected $\Rightarrow$ no buffer overflows
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   594
\item some languages compile to the JVM: Scala, Clojure\ldots
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 187
diff changeset
   595
\end{itemize}
184
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   596
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   597
\end{frame}}
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   598
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   599
2e9134d25a2b added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 173
diff changeset
   600
63
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   601
\end{document}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   602
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   603
%%% Local Variables:  
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   604
%%% mode: latex
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   605
%%% TeX-master: t
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   606
%%% End: 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   607