--- a/slides/slides08.tex Sun Nov 17 19:23:15 2013 +0000
+++ b/slides/slides08.tex Tue Nov 19 23:38:49 2013 +0000
@@ -1,7 +1,7 @@
\documentclass[dvipsnames,14pt,t]{beamer}
-\usepackage{beamerthemeplainculight}
-\usepackage[T1]{fontenc}
-\usepackage[latin1]{inputenc}
+\usepackage{beamerthemeplaincu}
+%\usepackage[T1]{fontenc}
+%\usepackage[latin1]{inputenc}
\usepackage{mathpartir}
\usepackage[absolute,overlay]{textpos}
\usepackage{ifthen}
@@ -20,6 +20,8 @@
\usetikzlibrary{calc}
\usetikzlibrary{plotmarks}
\usepackage{graphicx}
+\usepackage{pgfplots}
+\setmonofont{Consolas}
\definecolor{javared}{rgb}{0.6,0,0} % for strings
\definecolor{javagreen}{rgb}{0.25,0.5,0.35} % comments
@@ -57,6 +59,7 @@
morestring=[b]"""
}
+
\lstset{language=Scala,
basicstyle=\ttfamily,
keywordstyle=\color{javapurple}\bfseries,
@@ -71,57 +74,80 @@
showspaces=false,
showstringspaces=false}
+\lstdefinelanguage{while}{
+ morekeywords={if,then,else,while,do,true,false,write},
+ otherkeywords={=,!=,:=,<,>,;},
+ sensitive=true,
+ morecomment=[n]{/*}{*/},
+}
+
+
+\lstset{language=While,
+ basicstyle=\ttfamily,
+ keywordstyle=\color{javapurple}\bfseries,
+ stringstyle=\color{javagreen},
+ commentstyle=\color{javagreen},
+ morecomment=[s][\color{javadocblue}]{/**}{*/},
+ numbers=left,
+ numberstyle=\tiny\color{black},
+ stepnumber=1,
+ numbersep=10pt,
+ tabsize=2,
+ showspaces=false,
+ showstringspaces=false}
+
+
% beamer stuff
-\renewcommand{\slidecaption}{AFL 08, King's College London, 21.~November 2012}
+\renewcommand{\slidecaption}{AFL 09, King's College London, 20.~November 2013}
\newcommand{\bl}[1]{\textcolor{blue}{#1}}
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions
% The data files, written on the first run.
-\begin{filecontents}{s-grammar1.data}
-1 0.01152
-51 0.07973
-101 0.09726
-151 0.09320
-201 0.10010
-251 0.16997
-301 0.26662
-351 0.46118
-401 0.62516
-451 0.87247
-501 1.16334
-551 1.71152
-601 2.10958
-651 2.44360
-701 2.98488
-751 3.50326
-801 4.11036
-851 4.93394
-901 5.77465
-951 7.39123
+\begin{filecontents}{compiled.data}
+%1 0.234146
+%5000 0.227539
+%10000 0.280748
+50000 1.087897
+100000 3.713165
+250000 21.6624545
+500000 85.872613
+750000 203.6408015
+1000000 345.736574
\end{filecontents}
-\begin{filecontents}{s-grammar2.data}
-1 0.01280
-2 0.00064
-3 0.00173
-4 0.00355
-5 0.00965
-6 0.02674
-7 0.06953
-8 0.11166
-9 0.18707
-10 0.09189
-11 0.12724
-12 0.24337
-13 0.59304
-14 1.53594
-15 4.01195
-16 10.73582
-17 29.51587
-#18 73.14163
+\begin{filecontents}{interpreted.data}
+%1 0.00503
+200 1.005863
+400 7.8296765
+500 15.43106
+600 27.2321885
+800 65.249271
+1000 135.4493445
+1200 232.134097
+1400 382.527227
\end{filecontents}
+\begin{filecontents}{interpreted2.data}
+%1 0.00503
+200 1.005863
+400 7.8296765
+600 27.2321885
+800 65.249271
+1000 135.4493445
+1200 232.134097
+1400 382.527227
+\end{filecontents}
+
+\begin{filecontents}{compiled2.data}
+200 0.222058
+400 0.215204
+600 0.202031
+800 0.21986
+1000 0.205934
+1200 0.1981615
+1400 0.207116
+\end{filecontents}
\begin{document}
@@ -139,112 +165,30 @@
\begin{center}
\begin{tabular}{ll}
Email: & christian.urban at kcl.ac.uk\\
- Of$\!$fice: & S1.27 (1st floor Strand Building)\\
+ Office: & S1.27 (1st floor Strand Building)\\
Slides: & KEATS (also home work is there)\\
\end{tabular}
\end{center}
-
\end{frame}}
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
-\begin{frame}[c]
-\frametitle{\begin{tabular}{c}Building a ``Web Browser''\end{tabular}}
-
-Using a lexer: assume the following regular expressions
-
-\begin{center}
-\bl{\begin{tabular}{lcl}
-$SY\!M$ & $\dn$ & $(\text{a}..\text{zA}..\text{Z0}..\text{9}..)$\\
-$W\!O\!RD$ & $\dn$ & $SY\!M^+$\\
-$BT\!AG$ & $\dn$ & $<\!W\!O\!RD\!>$\\
-$ET\!AG$ & $\dn$ & $<\!/W\!O\!RD\!>$\\
-$W\!HIT\!E$ & $\dn$ & $\texttt{" "} + \texttt{"}\slash{}n\texttt{"}$\\
-\end{tabular}}
-\end{center}
-
-\end{frame}}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
-\begin{frame}[c]
-\frametitle{\begin{tabular}{c}Interpreting a List of Tokens\end{tabular}}
-
-\begin{itemize}
-\item the text should be formatted consistently up to a specified width, say 60 characters
-\item potential linebreaks are inserted by the formatter (not the input)
-\item repeated whitespaces are ``condensed'' to a single whitepace
-\item \bl{$<\!p\!>$} \bl{$<\!\slash{}p\!>$} start/end paragraph
-\item \bl{$<\!b\!>$} \bl{$<\!\slash{}b\!>$} start/end bold
-\item \bl{$<\!red\!>$} \bl{$<\!\slash{}red\!>$} start/end red (cyan, etc)
-
-
-\end{itemize}
-
-\end{frame}}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
-\begin{frame}[c]
-\frametitle{\begin{tabular}{c}Interpreting a List of Tokens\end{tabular}}
-
-The lexer cannot prevent errors like
-
-\begin{center}
-\bl{$<\!b\!>$} \ldots \bl{$<\!p\!>$} \ldots \bl{$<\!\slash{}b\!>$} \ldots \bl{$<\!\slash{}p\!>$}
-\end{center}
-
-or
-
-\begin{center}
-\bl{$<\!\slash{}b\!>$} \ldots \bl{$<\!b\!>$}
-\end{center}
-
-
-\end{frame}}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
-\begin{frame}[c]
-\frametitle{\begin{tabular}{c}Parser Combinators\end{tabular}}
-
-Parser combinators: \bigskip
-
-\begin{minipage}{1.1\textwidth}
-\begin{center}
-\mbox{}\hspace{-12mm}\mbox{}$\underbrace{\text{list of tokens}}_{\text{input}}$ \bl{$\Rightarrow$}
-$\underbrace{\text{set of (parsed input, unparsed input)}}_{\text{output}}$
-\end{center}
-\end{minipage}\bigskip
-
-\begin{itemize}
-\item sequencing
-\item alternative
-\item semantic action
-\end{itemize}
-
-\end{frame}}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\mode<presentation>{
\begin{frame}[c]
-Alternative parser (code \bl{$p\;||\;q$})\bigskip
+Imagine the following situation: You talk to somebody
+and you find out that she/he has implemented a compiler.\smallskip
+
+What is your reaction? \pause Check all that apply.\bigskip
-\begin{itemize}
-\item apply \bl{$p$} and also \bl{$q$}; then combine the outputs
-\end{itemize}
-
-\begin{center}
-\large \bl{$p(\text{input}) \cup q(\text{input})$}
-\end{center}
-
+ \begin{itemize}
+ \item[$\Box$] You think she/he is God
+ \item[$\Box$] \"Uberhacker
+ \item[$\Box$] superhuman
+ \item[$\Box$] wizard
+ \item[$\Box$] supremo
+ \end{itemize}
\end{frame}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -252,389 +196,66 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\mode<presentation>{
\begin{frame}[c]
-
-Sequence parser (code \bl{$p\sim q$})\bigskip
-
-\begin{itemize}
-\item apply first \bl{$p$} producing a set of pairs
-\item then apply \bl{$q$} to the unparsed parts
-\item then combine the results:\\ \mbox{}\;\;((output$_1$, output$_2$), unparsed part)
-\end{itemize}
+\frametitle{Bird's Eye View}
\begin{center}
-\begin{tabular}{l}
-\large \bl{$\{((o_1, o_2), u_2) \;|\;$}\\[2mm]
-\large\mbox{}\hspace{15mm} \bl{$(o_1, u_1) \in p(\text{input}) \wedge$}\\[2mm]
-\large\mbox{}\hspace{15mm} \bl{$(o_2, u_2) \in q(u_1)\}$}
-\end{tabular}
+\begin{tikzpicture}
+\node (rexp) {\bl{\bf Lexer}};
+\node (nfa) [right=of rexp] {\bl{\bf Parser}};
+\node (dfa) [right=of nfa] {\bl{\begin{tabular}{c}\bf Machine Code/\\\bf Byte Code\end{tabular}}};
+\path[->, red, line width=2mm] (rexp) edge node [above=4mm, black] {\begin{tabular}{c@{\hspace{9mm}}}token\\[-1mm]
+sequence\end{tabular}} (nfa);
+\path[->, red, line width=2mm] (nfa) edge node [above=4mm, black] {\begin{tabular}{c}parse\\[-1mm] tree\end{tabular}}(dfa);
+\end{tikzpicture}\\
\end{center}
-
\end{frame}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\mode<presentation>{
\begin{frame}[c]
-Function parser (code \bl{$p \Longrightarrow f$})\bigskip
+\begin{center}
+\includegraphics[scale=0.7]{../pics/machine_code.jpg}
+\end{center}
-\begin{itemize}
-\item apply \bl{$p$} producing a set of pairs
-\item then apply the function \bl{$f$} to each first component
-\end{itemize}
+\end{frame}}
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[c]
+\frametitle{Assembly Code}
+\mbox{}\\[-20mm]\mbox{}
\begin{center}
-\begin{tabular}{l}
-\large \bl{$\{(f(o_1), u_1) \;|\; (o_1, u_1) \in p(\text{input})\}$}
-\end{tabular}
-\end{center}\bigskip\bigskip\pause
-
-\bl{$f$} is the semantic action (``what to do with the parsed input'')
+\includegraphics[scale=0.7]{../pics/assembly.jpg}
+\end{center}
\end{frame}}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\mode<presentation>{
\begin{frame}[c]
-Token parser:\bigskip
-
-\begin{itemize}
-\item if the input is
-
-\begin{center}
-\large \bl{$tok_1:: tok_2 :: \ldots :: tok_n$}
-\end{center}
-
-then return
-
-\begin{center}
-\large \bl{$\{(tok_1,\; tok_2 :: \ldots :: tok_n)\}$}
-\end{center}
-
-or
-
-\begin{center}
-\large \bl{$\{\}$}
-\end{center}
-
-if \bl{$tok_1$} is not the right token we are looking for
-\end{itemize}
-
-
-
-\end{frame}}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
-\begin{frame}[c]
-
-Number-Token parser:\bigskip
-
-\begin{itemize}
-\item if the input is
-
-\begin{center}
-\large \bl{$num\_tok(42):: tok_2 :: \ldots :: tok_n$}
-\end{center}
-
-then return
-
-\begin{center}
-\large \bl{$\{(42,\; tok_2 :: \ldots :: tok_n)\}$}
-\end{center}
-
-or
-
-\begin{center}
-\large \bl{$\{\}$}
-\end{center}
-
-if \bl{$tok_1$} is not the right token we are looking for
-\end{itemize}\pause
-
-\begin{center}
-list of tokens \bl{$\Rightarrow$} set of (\alert{int}, list of tokens)
-\end{center}
-
-\end{frame}}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
-\begin{frame}[c]
-
-\begin{itemize}
-\item if the input is
-
-\begin{center}
-\begin{tabular}{l}
-\large \bl{$num\_tok(42)::$}\\
-\hspace{7mm}\large \bl{$num\_tok(3) ::$}\\
-\hspace{14mm}\large \bl{$tok_3 :: \ldots :: tok_n$}
-\end{tabular}
-\end{center}
-
-and the parser is
-
-\begin{center}
-\bl{$ntp \sim ntp$}
-\end{center}
-
-the successful output will be
-
-\begin{center}
-\large \bl{$\{((42, 3),\; tok_2 :: \ldots :: tok_n)\}$}
-\end{center}\pause
-
-Now we can form
-\begin{center}
-\bl{$(ntp \sim ntp) \Longrightarrow f$}
-\end{center}
-
-where \bl{$f$} is the semantic action (``what to do with the pair'')
-
-\end{itemize}
-
-\end{frame}}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
-\begin{frame}[c]
-\frametitle{\begin{tabular}{c}Semantic Actions\end{tabular}}
-
-Addition
-
-\begin{center}
-\bl{$T \sim + \sim E \Longrightarrow \underbrace{f((x,y), z) \Rightarrow x + z}_{\text{semantic action}}$}
-\end{center}\pause
-
-Multiplication
-
-\begin{center}
-\bl{$F \sim * \sim T \Longrightarrow f((x,y), z) \Rightarrow x * z$}
-\end{center}\pause
-
-Parenthesis
-
-\begin{center}
-\bl{$\text{(} \sim E \sim \text{)} \Longrightarrow f((x,y), z) \Rightarrow y$}
-\end{center}
-
-\end{frame}}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
-\begin{frame}[c]
-\frametitle{\begin{tabular}{c}Types of Parsers\end{tabular}}
-
-\begin{itemize}
-\item {\bf Sequencing}: if \bl{$p$} returns results of type \bl{$T$}, and \bl{$q$} results of type \bl{$S$},
-then \bl{$p \sim q$} returns results of type
-
-\begin{center}
-\bl{$T \times S$}
-\end{center}\pause
-
-\item {\bf Alternative}: if \bl{$p$} returns results of type \bl{$T$} then \bl{$q$} \alert{must} also have results of type \bl{$T$},
-and \bl{$p \;||\; q$} returns results of type
-
-\begin{center}
-\bl{$T$}
-\end{center}\pause
-
-\item {\bf Semantic Action}: if \bl{$p$} returns results of type \bl{$T$} and \bl{$f$} is a function from
-\bl{$T$} to \bl{$S$}, then
-\bl{$p \Longrightarrow f$} returns results of type
-
-\begin{center}
-\bl{$S$}
-\end{center}
-
-\end{itemize}
-
-\end{frame}}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
-\begin{frame}[c]
-\frametitle{\begin{tabular}{c}Input Types of Parsers\end{tabular}}
-
-\begin{itemize}
-\item input: \alert{list of tokens}
-\item output: set of (output\_type, \alert{list of tokens})
-\end{itemize}\bigskip\pause
-
-actually it can be any input type as long as it is a kind of sequence
-(for example a string)
-
-\end{frame}}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
-\begin{frame}[c]
-\frametitle{\begin{tabular}{c}Scannerless Parsers\end{tabular}}
-
-\begin{itemize}
-\item input: \alert{string}
-\item output: set of (output\_type, \alert{string})
-\end{itemize}\bigskip
-
-but lexers are better when whitespaces or comments need to be filtered out
-
-\end{frame}}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
-\begin{frame}[c]
-\frametitle{\begin{tabular}{c}Successful Parses\end{tabular}}
-
-\begin{itemize}
-\item input: string
-\item output: \alert{set of} (output\_type, string)
-\end{itemize}\bigskip
-
-a parse is successful whenever the input has been
-fully ``consumed'' (that is the second component is empty)
-
-
-\end{frame}}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
-\begin{frame}[c]
-{\lstset{language=Scala}\fontsize{10}{12}\selectfont
-\texttt{\lstinputlisting{app7.scala}}}
-\end{frame}}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
-\begin{frame}[c]
-{\lstset{language=Scala}\fontsize{10}{12}\selectfont
-\texttt{\lstinputlisting{app7.scala}}}
-\end{frame}}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
-\begin{frame}[c]
-{\lstset{language=Scala}\fontsize{10}{12}\selectfont
-\texttt{\lstinputlisting{app8.scala}}}
-\end{frame}}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
-\begin{frame}[c]
-\frametitle{\begin{tabular}{c}Two Grammars\end{tabular}}
-
-Which languages are recognised by the following two grammars?
-
-\begin{center}
-\bl{\begin{tabular}{lcl}
-$S$ & $\rightarrow$ & $1 \cdot S \cdot S$\\
- & $|$ & $\epsilon$
-\end{tabular}}
-\end{center}\bigskip
-
-\begin{center}
-\bl{\begin{tabular}{lcl}
-$U$ & $\rightarrow$ & $1 \cdot U$\\
- & $|$ & $\epsilon$
-\end{tabular}}
-\end{center}
-
-\end{frame}}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
-\begin{frame}[t]
-\frametitle{\begin{tabular}{c}Ambiguous Grammars\end{tabular}}
-
-\mbox{}\\[-25mm]\mbox{}
-
-\begin{center}
-\begin{tikzpicture}[y=.2cm, x=.009cm]
- %axis
- \draw (0,0) -- coordinate (x axis mid) (1000,0);
- \draw (0,0) -- coordinate (y axis mid) (0,30);
- %ticks
- \foreach \x in {0, 20, 100, 200,...,1000}
- \draw (\x,1pt) -- (\x,-3pt)
- node[anchor=north] {\small \x};
- \foreach \y in {0,5,...,30}
- \draw (1pt,\y) -- (-3pt,\y)
- node[anchor=east] {\small\y};
- %labels
- \node[below=0.6cm] at (x axis mid) {\bl{1}s};
- \node[rotate=90, left=1.2cm] at (y axis mid) {secs};
-
- %plots
- \draw[color=blue] plot[mark=*, mark options={fill=white}]
- file {s-grammar1.data};
- \only<2->{\draw[color=red] plot[mark=triangle*, mark options={fill=white} ]
- file {s-grammar2.data};}
- %legend
- \begin{scope}[shift={(400,20)}]
- \draw[color=blue] (0,0) --
- plot[mark=*, mark options={fill=white}] (0.25,0) -- (0.5,0)
- node[right]{\small unambiguous};
- \only<2->{\draw[yshift=\baselineskip, color=red] (0,0) --
- plot[mark=triangle*, mark options={fill=white}] (0.25,0) -- (0.5,0)
- node[right]{\small ambiguous};}
- \end{scope}
-\end{tikzpicture}
-\end{center}
-
-\end{frame}}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
-\begin{frame}[c]
-\frametitle{\begin{tabular}{c}What about Left-Recursion?\end{tabular}}
-
-\begin{itemize}
-\item we record when we recursively called a parser\bigskip
-\item whenever the is a recursion, the parser must have consumed something --- so
-we can decrease the input string/list of token by one (at the end)
-\end{itemize}
-\end{frame}}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
-\begin{frame}[c]
-\frametitle{\begin{tabular}{c}While-Language\end{tabular}}
-
-
\begin{center}
\bl{\begin{tabular}{@{}lcl@{}}
-$Stmt$ & $\rightarrow$ & $\text{skip}$\\
- & $|$ & $Id := AExp$\\
- & $|$ & $\text{if}\; B\!Exp \;\text{then}\; Block \;\text{else}\; Block$\\
- & $|$ & $\text{while}\; B\!Exp \;\text{do}\; Block$\medskip\\
-$Stmts$ & $\rightarrow$ & $Stmt \;\text{;}\; Stmts$\\
- & $|$ & $Stmt$\medskip\\
-$Block$ & $\rightarrow$ & $\{ Stmts \}$\\
- & $|$ & $Stmt$\medskip\\
-$AExp$ & $\rightarrow$ & \ldots\\
-$BExp$ & $\rightarrow$ & \ldots\\
+\textit{Stmt} & $\rightarrow$ & $\texttt{skip}$\\
+ & $|$ & \textit{Id}\;\texttt{:=}\;\textit{AExp}\\
+ & $|$ & \texttt{if}\; \textit{BExp} \;\texttt{then}\; \textit{Block} \;\texttt{else}\; \textit{Block}\\
+ & $|$ & \texttt{while}\; \textit{BExp} \;\texttt{do}\; \textit{Block}\\
+ & $|$ & \texttt{read}\;\textit{Id}\\
+ & $|$ & \texttt{write}\;\textit{Id}\\
+ & $|$ & \texttt{write}\;\textit{String}\medskip\\
+\textit{Stmts} & $\rightarrow$ & \textit{Stmt} \;\texttt{;}\; \textit{Stmts}\\
+ & $|$ & \textit{Stmt}\medskip\\
+\textit{Block} & $\rightarrow$ & \texttt{\{}\,\textit{Stmts}\,\texttt{\}}\\
+ & $|$ & \textit{Stmt}\medskip\\
+\textit{AExp} & $\rightarrow$ & \ldots\\
+\textit{BExp} & $\rightarrow$ & \ldots\\
\end{tabular}}
\end{center}
@@ -645,28 +266,611 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\mode<presentation>{
\begin{frame}[c]
-\frametitle{\begin{tabular}{c}An Interpreter\end{tabular}}
+\frametitle{\begin{tabular}{c}Fibonacci Numbers\end{tabular}}
+
+\mbox{}\\[-18mm]\mbox{}
+
+{\lstset{language=While}\fontsize{10}{12}\selectfont
+\texttt{\lstinputlisting{../progs/fib.while}}}
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[c]
+\frametitle{\begin{tabular}{c}Interpreter\end{tabular}}
+
+\begin{center}
+\bl{\begin{tabular}{@{}lcl@{}}
+$\text{eval}(n, E)$ & $\dn$ & $n$\\
+$\text{eval}(x, E)$ & $\dn$ & $E(x)$ \;\;\;\textcolor{black}{lookup \bl{$x$} in \bl{$E$}}\\
+$\text{eval}(a_1 + a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) + \text{eval}(a_2, E)$\\
+$\text{eval}(a_1 - a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) - \text{eval}(a_2, E)$\\
+$\text{eval}(a_1 * a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) * \text{eval}(a_2, E)$\bigskip\\
+$\text{eval}(a_1 = a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) = \text{eval}(a_2, E)$\\
+$\text{eval}(a_1\,!\!= a_2, E)$ & $\dn$ & $\neg(\text{eval}(a_1, E) = \text{eval}(a_2, E))$\\
+$\text{eval}(a_1 < a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) < \text{eval}(a_2, E)$\
+\end{tabular}}
+\end{center}
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[c]
+\frametitle{\begin{tabular}{c}Interpreter (2)\end{tabular}}
+
+\begin{center}
+\bl{\begin{tabular}{@{}lcl@{}}
+$\text{eval}(\text{skip}, E)$ & $\dn$ & $E$\\
+$\text{eval}(x:=a, E)$ & $\dn$ & \bl{$E(x \mapsto \text{eval}(a, E))$}\\
+\multicolumn{3}{@{}l@{}}{$\text{eval}(\text{if}\;b\;\text{then}\;cs_1\;\text{else}\;cs_2 , E) \dn$}\\
+\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)\;\text{then}\;
+\text{eval}(cs_1,E)$}\\
+\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\phantom{\text{if}\;\text{eval}(b,E)\;}\text{else}\;\text{eval}(cs_2,E)$}\\
+\multicolumn{3}{@{}l@{}}{$\text{eval}(\text{while}\;b\;\text{do}\;cs, E) \dn$}\\
+\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)$}\\
+\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{then}\;
+\text{eval}(\text{while}\;b\;\text{do}\;cs, \text{eval}(cs,E))$}\\
+\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{else}\; E$}\\
+$\text{eval}(\text{write}\; x, E)$ & $\dn$ & $\{\;\text{println}(E(x))\; ;\;E\;\}$\\
+\end{tabular}}
+\end{center}
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[c]
+\frametitle{\begin{tabular}{c}Test Program\end{tabular}}
+
+\mbox{}\\[-18mm]\mbox{}
+
+{\lstset{language=While}\fontsize{10}{12}\selectfont
+\texttt{\lstinputlisting{../progs/loops.while}}}
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[t]
+\frametitle{\begin{tabular}{c}Interpreted Code\end{tabular}}
+
+\begin{center}
+\begin{tikzpicture}
+\begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small]
+\addplot+[smooth] file {interpreted.data};
+\end{axis}
+\end{tikzpicture}
+\end{center}
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[c]
+\frametitle{\begin{tabular}{c}Java Virtual Machine\end{tabular}}
+
+\begin{itemize}
+\item introduced in 1995
+\item is a stack-based VM (like Postscript, CLR of .Net)
+\item contains a JIT compiler
+\item many languages take advantage of JVM's infrastructure (JRE)
+\item is garbage collected $\Rightarrow$ no buffer overflows
+\item some languages compiled to the JVM: Scala, Clojure\ldots
+\end{itemize}
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[t]
+\frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
+
+{\Large\bl{1 + 2}}
+
+\begin{center}
+\bl{\begin{tabular}{l}
+ldc 1\\
+ldc 2\\
+iadd\\
+\end{tabular}}
+\end{center}\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[t]
+\frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
+
+{\Large\bl{1 + 2 + 3}}
+
+\begin{center}
+\bl{\begin{tabular}{l}
+ldc 1\\
+ldc 2\\
+iadd\\
+ldc 3\\
+iadd\\
+\end{tabular}}
+\end{center}
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[t]
+\frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
+
+{\Large\bl{1 + (2 + 3)}}
\begin{center}
\bl{\begin{tabular}{l}
-$\{$\\
-\;\;$x := 5 \text{;}$\\
-\;\;$y := x * 3\text{;}$\\
-\;\;$y := x * 4\text{;}$\\
-\;\;$x := u * 3$\\
-$\}$
+ldc 1\\
+ldc 2\\
+ldc 3\\
+iadd\\
+iadd\\
+\end{tabular}}
+\end{center}\bigskip\pause
+\vfill
+
+\bl{dadd, fadd, ladd, \ldots}
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[t]
+\frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
+
+\begin{center}
+\bl{\begin{tabular}{@{}lcl@{}}
+$\text{compile}(n)$ & $\dn$ & $\text{ldc}\;n$\\
+$\text{compile}(a_1 + a_2)$ & $\dn$\\
+\multicolumn{3}{l}{$\qquad\text{compile}(a_1) \;@\;\text{compile}(a_2)\;@\; \text{iadd}$}\smallskip\\
+$\text{compile}(a_1 - a_2)$ & $\dn$\\
+\multicolumn{3}{l}{$\qquad\text{compile}(a_1) \;@\; \text{compile}(a_2)\;@\; \text{isub}$}\smallskip\\
+$\text{compile}(a_1 * a_2)$ & $\dn$\\
+\multicolumn{3}{l}{$\qquad\text{compile}(a_1) \;@\; \text{compile}(a_2)\;@\; \text{imul}$}\smallskip\\
+\end{tabular}}
+\end{center}\pause
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[t]
+\frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
+
+{\Large\bl{1 + 2 * 3 + (4 - 3)}}
+
+\begin{center}
+\bl{\begin{tabular}{l}
+ldc 1\\
+ldc 2\\
+ldc 3\\
+imul\\
+ldc 4\\
+ldc 3\\
+isub\\
+iadd\\
+iadd\\
\end{tabular}}
\end{center}
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[t]
+\frametitle{\begin{tabular}{c}Variables\end{tabular}}
+
+{\Large\bl{$x := 5 + y * 2$}}\bigskip\pause
+
\begin{itemize}
-\item the interpreter has to record the value of \bl{$x$} before assigning a value to \bl{$y$}\pause
-\item \bl{\text{eval}(stmt, env)}
-\end{itemize}
+\item lookup: \bl{$\text{iload}\; index$}
+\item store: \bl{$\text{istore}\; index$}
+\end{itemize}\bigskip\pause
+
+while compilating we have to maintain a map between our identifiers and the
+Java bytecode indices
+
+\begin{center}
+\bl{$\text{compile}(a, E)$}
+\end{center}
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[t]
+\frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
+
+\begin{center}
+\bl{\begin{tabular}{@{}lcl@{}}
+$\text{compile}(n, E)$ & $\dn$ & $\text{ldc}\;n$\\
+$\text{compile}(a_1 + a_2, E)$ & $\dn$\\
+\multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\;\text{compile}(a_2. E)\;@\; \text{iadd}$}\smallskip\\
+$\text{compile}(a_1 - a_2, E)$ & $\dn$\\
+\multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\; \text{compile}(a_2, E)\;@\; \text{isub}$}\smallskip\\
+$\text{compile}(a_1 * a_2, E)$ & $\dn$\\
+\multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\; \text{compile}(a_2, E)\;@\; \text{imul}$}\bigskip\\
+$\text{compile}(x, E)$ & $\dn$ & $\text{iload}\;E(x)$\\
+\end{tabular}}
+\end{center}\pause
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[t]
+\frametitle{\begin{tabular}{c}Compiling Statements\end{tabular}}
+
+We return a list of instructions and an environment for the variables
+
+\begin{center}
+\bl{\begin{tabular}{@{}l@{\hspace{1mm}}c@{\hspace{1mm}}l@{}}
+$\text{compile}(\text{skip}, E)$ & $\dn$ & $(N\!il, E)$\bigskip\\
+$\text{compile}(x := a, E)$ & $\dn$\\
+\multicolumn{3}{l}{$(\text{compile}(a, E) \;@\;\text{istore}\;index, E(x\mapsto index))$}\\
+\end{tabular}}
+\end{center}\medskip
+
+where \bl{$index$} is \bl{$E(x)$} if it is already defined, or if it is not then the largest index not yet seen
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[t]
+\frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
+
+{\Large\bl{$x := x + 1$}}
+
+\begin{center}
+\bl{\begin{tabular}{l}
+iload $n_x$\\
+ldc 1\\
+iadd\\
+istore $n_x$\\
+\end{tabular}}
+\end{center}
+
+where \bl{$n_x$} is the index corresponding to the variable \bl{$x$}
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[t]
+\frametitle{\begin{tabular}{c}Compiling Ifs\end{tabular}}
+
+{\Large\bl{$\text{if}\;b\;\text{then}\;cs_1\;\text{else}\;cs_2$}}\bigskip\bigskip
+
+\onslide<2->{Case }\only<2>{{\bf True}:}\only<3>{{\bf False}:}
+
+\begin{center}
+\begin{tikzpicture}[node distance=2mm and 4mm,
+ block/.style={rectangle, minimum size=1cm, draw=black, line width=1mm},
+ point/.style={rectangle, inner sep=0mm, minimum size=0mm, fill=red},
+ skip loop/.style={red, line width=1mm, to path={-- ++(0,-10mm) -| (\tikztotarget)}}]
+\node (A1) [point] {};
+\node (b) [block, right=of A1] {code of \bl{$b$}};
+\node (A2) [point, right=of b] {};
+\node (cs1) [block, right=of A2] {code of \bl{$cs_1$}};
+\node (A3) [point, right=of cs1] {};
+\node (cs2) [block, right=of A3] {code of \bl{$cs_2$}};
+\node (A4) [point, right=of cs2] {};
+
+\only<2>{
+\draw (A1) edge [->, red, line width=1mm] (b);
+\draw (b) edge [->, red, line width=1mm] (cs1);
+\draw (cs1) edge [->, red, line width=1mm] (A3);
+\draw (A3) edge [->,skip loop] (A4);
+\node [below=of cs2] {\raisebox{-5mm}{\small{}jump}};}
+\only<3>{
+\draw (A1) edge [->, red, line width=1mm] (b);
+\draw (b) edge [->, red, line width=1mm] (A2);
+\draw (A2) edge [skip loop] (A3);
+\draw (A3) edge [->, red, line width=1mm] (cs2);
+\draw (cs2) edge [->,red, line width=1mm] (A4);
+\node [below=of cs1] {\raisebox{-5mm}{\small{}conditional jump}};}
+\end{tikzpicture}
+\end{center}
\end{frame}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[c]
+\frametitle{\begin{tabular}{c}Conditional Jumps\end{tabular}}
+
+\begin{minipage}{1.1\textwidth}
+\begin{itemize}
+\item \bl{if\_icmpeq $label$} if two ints are equal, then jump\medskip
+\item \bl{if\_icmpne $label$} if two ints aren't equal, then jump\medskip
+\item \bl{if\_icmpge $label$} if one int is greater or equal then another, then jump
+\item[]\ldots
+\end{itemize}
+\end{minipage}\pause
+
+
+\begin{center}
+\bl{\begin{tabular}{l}
+$L_1$:\\
+\hspace{5mm}if\_icmpeq\;$L_2$\\
+\hspace{5mm}iload 1\\
+\hspace{5mm}ldc 1\\
+\hspace{5mm}iadd\\
+\hspace{5mm}if\_icmpeq\;$L_1$\\
+$L_2$:
+\end{tabular}}
+\end{center}
+
+\begin{textblock}{3.5}(11,12)
+\only<3>{labels must be unique}
+\end{textblock}
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[t]
+\frametitle{\begin{tabular}{c}Compiling BExps\end{tabular}}
+
+{\Large\bl{$a_1 = a_2$}}
+
+\begin{center}
+\bl{\begin{tabular}{lcl}
+$\text{compile}(a_1 = a_2, E, lab)$ & $\dn$\\
+\multicolumn{3}{l}{$\quad\text{compile}(a_1, E) \;@\;\text{compile}(a_2, E)\;@\; \text{if\_icmpne}\;lab$}
+\end{tabular}}
+\end{center}
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[t]
+\frametitle{\begin{tabular}{c}Compiling Ifs\end{tabular}}
+
+{\Large\bl{if $b$ then $cs_1$ else $cs_2$}}
+
+\begin{center}
+\bl{\begin{tabular}{lcl}
+$\text{compile}(\text{if}\;b\;\text{then}\; cs_1\;\text{else}\; cs_2, E)$ & $\dn$\\
+\multicolumn{3}{l}{$\quad l_{ifelse}\;$ \textcolor{black}{(fresh label)}}\\
+\multicolumn{3}{l}{$\quad l_{ifend}\;$ \textcolor{black}{(fresh label)}}\\
+\multicolumn{3}{l}{$\quad (is_1, E') = \text{compile}(cs_1, E)$}\\
+\multicolumn{3}{l}{$\quad (is_2, E'') = \text{compile}(cs_2, E')$}\\
+\multicolumn{3}{l}{$\quad(\text{compile}(b, E, l_{ifelse})$}\\
+\multicolumn{3}{l}{$\quad\phantom{(}@\;is_1$}\\
+\multicolumn{3}{l}{$\quad\phantom{(}@\; \text{goto}\;l_{ifend}$}\\
+\multicolumn{3}{l}{$\quad\phantom{(}@\;l_{ifelse}:$}\\
+\multicolumn{3}{l}{$\quad\phantom{(}@\;is_2$}\\
+\multicolumn{3}{l}{$\quad\phantom{(}@\;l_{ifend}:, E'')$}\\
+\end{tabular}}
+\end{center}
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[t]
+\frametitle{\begin{tabular}{c}Compiling Whiles\end{tabular}}
+
+{\Large\bl{$\text{while}\;b\;\text{do}\;cs$}}\bigskip\bigskip
+
+\onslide<2->{Case }\only<2>{{\bf True}:}\only<3>{{\bf False}:}
+
+\begin{center}
+\begin{tikzpicture}[node distance=2mm and 4mm,
+ block/.style={rectangle, minimum size=1cm, draw=black, line width=1mm},
+ point/.style={rectangle, inner sep=0mm, minimum size=0mm, fill=red},
+ skip loop/.style={red, line width=1mm, to path={-- ++(0,-10mm) -| (\tikztotarget)}}]
+\node (A0) [point, left=of A1] {};
+\node (A1) [point] {};
+\node (b) [block, right=of A1] {code of \bl{$b$}};
+\node (A2) [point, right=of b] {};
+\node (cs1) [block, right=of A2] {code of \bl{$cs$}};
+\node (A3) [point, right=of cs1] {};
+\node (A4) [point, right=of A3] {};
+
+\only<2>{
+\draw (A0) edge [->, red, line width=1mm] (b);
+\draw (b) edge [->, red, line width=1mm] (cs1);
+\draw (cs1) edge [->, red, line width=1mm] (A3);
+\draw (A3) edge [->,skip loop] (A1);}
+\only<3>{
+\draw (A0) edge [->, red, line width=1mm] (b);
+\draw (b) edge [->, red, line width=1mm] (A2);
+\draw (A2) edge [skip loop] (A3);
+\draw (A3) edge [->, red, line width=1mm] (A4);}
+\end{tikzpicture}
+\end{center}
+
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[t]
+\frametitle{\begin{tabular}{c}Compiling Whiles\end{tabular}}
+
+{\Large\bl{while $b$ do $cs$}}
+
+\begin{center}
+\bl{\begin{tabular}{lcl}
+$\text{compile}(\text{while}\; b\; \text{do} \;cs, E)$ & $\dn$\\
+\multicolumn{3}{l}{$\quad l_{wbegin}\;$ \textcolor{black}{(fresh label)}}\\
+\multicolumn{3}{l}{$\quad l_{wend}\;$ \textcolor{black}{(fresh label)}}\\
+\multicolumn{3}{l}{$\quad (is, E') = \text{compile}(cs_1, E)$}\\
+\multicolumn{3}{l}{$\quad(l_{wbegin}:$}\\
+\multicolumn{3}{l}{$\quad\phantom{(}@\;\text{compile}(b, E, l_{wend})$}\\
+\multicolumn{3}{l}{$\quad\phantom{(}@\;is$}\\
+\multicolumn{3}{l}{$\quad\phantom{(}@\; \text{goto}\;l_{wbegin}$}\\
+\multicolumn{3}{l}{$\quad\phantom{(}@\;l_{wend}:, E')$}\\
+\end{tabular}}
+\end{center}
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[t]
+\frametitle{\begin{tabular}{c}Compiling Writes\end{tabular}}
+
+{\Large\bl{write $x$}}
+
+\begin{center}
+\small\bl{\begin{tabular}{l}
+.method public static write(I)V\hspace{1cm}\textcolor{black}{(library function)}\\
+\;\; .limit locals 5 \\
+\;\; .limit stack 5 \\
+\;\; iload 0 \\
+\;\; getstatic java/lang/System/out Ljava/io/PrintStream;\\
+\;\; swap \\
+\;\; invokevirtual java/io/PrintStream/println(I)V \\
+\;\; return \\
+.end method\bigskip\bigskip\\
+%
+\normalsize
+iload $E(x)$\\
+invokestatic write(I)V\\
+\end{tabular}}
+\end{center}
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[c]
+
+\begin{center}
+\small\bl{\begin{tabular}{l}
+.class public XXX.XXX\\
+.super java/lang/Object\\
+\\
+.method public <init>()V\\
+\;\; aload\_0\\
+\;\; invokenonvirtual java/lang/Object/<init>()V\\
+ \;\; return\\
+.end method\\
+\\
+.method public static main([Ljava/lang/String;)V\\
+\;\; .limit locals 200\\
+\;\; .limit stack 200\\
+\\
+ \textcolor{black}{(here comes the compiled code)}\\
+\\
+\;\; return\\
+.end method\\
+\end{tabular}}
+\end{center}
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[c]
+\frametitle{\begin{tabular}{c}Next Compiler Phases\end{tabular}}
+
+\begin{itemize}
+\item assembly $\Rightarrow$ byte code (class file)
+\item labels $\Rightarrow$ absolute or relative jumps\bigskip\bigskip
+\item \texttt{javap} is a disassembler for class files
+\end{itemize}
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[t]
+\frametitle{\begin{tabular}{c}Compiled Code\end{tabular}}
+
+\begin{center}
+\begin{tikzpicture}
+\begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small]
+\addplot+[smooth] file {compiled.data};
+\end{axis}
+\end{tikzpicture}
+\end{center}
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[t]
+\frametitle{\begin{tabular}{c}Compiler vs.~Interpreter\end{tabular}}
+
+\begin{center}
+\begin{tikzpicture}
+\begin{axis}[axis x line=bottom, axis y line=left, ylabel=secs,
+ xlabel=n,
+ enlargelimits=0.05,
+ ybar interval=0.7, legend style=small]
+\addplot file {interpreted2.data};
+\addplot file {compiled2.data};
+%\legend{interpreted, compiled}
+\end{axis}
+\end{tikzpicture}
+\end{center}
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[t]
+\frametitle{\begin{tabular}{c}What Next\end{tabular}}
+
+\begin{itemize}
+\item register spilling
+\item dead code removal
+\item loop optimisations
+\item instruction selection
+\item type checking
+\item concurrency
+\item fuzzy testing
+\item verification\bigskip\\
+
+\item GCC, LLVM, tracing JITs
+\end{itemize}
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
\end{document}
%%% Local Variables: