updated
authorChristian Urban <christian dot urban at kcl dot ac dot uk>
Sun, 12 Oct 2014 21:54:04 +0100
changeset 273 b56d5e4468c0
parent 272 1446bc47a294
child 274 21f0f24424ab
updated
coursework/cw01.pdf
slides/slides04.pdf
slides/slides04.tex
Binary file coursework/cw01.pdf has changed
Binary file slides/slides04.pdf has changed
--- a/slides/slides04.tex	Sun Oct 12 19:39:55 2014 +0100
+++ b/slides/slides04.tex	Sun Oct 12 21:54:04 2014 +0100
@@ -571,12 +571,149 @@
 \draw[->,line width=0.5mm]  (r3) -- (v3);
 \draw[->,line width=0.5mm]  (r2) -- (v2);
 \draw[->,line width=0.5mm]  (r1) -- (v1);
+\draw (r4) node[anchor=north west] {\;\raisebox{-8mm}{\bl{$mkeps$}}};
 \end{tikzpicture}
 \end{center}
 
 \end{frame}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{frame}[c]
+\frametitle{Regexes and Values}
+
+Regular expressions and their corresponding values:
+
+\begin{center}
+\begin{columns}
+\begin{column}{3cm}
+\begin{tabular}{@{}rrl@{}}
+  \bl{$r$} & \bl{$::=$}  & \bl{$\varnothing$}\\
+           & \bl{$\mid$} & \bl{$\epsilon$}   \\
+           & \bl{$\mid$} & \bl{$c$}          \\
+           & \bl{$\mid$} & \bl{$r_1 \cdot r_2$}\\
+           & \bl{$\mid$} & \bl{$r_1 + r_2$}   \\
+  \\
+           & \bl{$\mid$} & \bl{$r^*$}         \\
+  \\
+  \end{tabular}
+\end{column}
+\begin{column}{3cm}
+\begin{tabular}{@{\hspace{-7mm}}rrl@{}}
+  \bl{$v$} & \bl{$::=$}  & \\
+           &             & \bl{$Empty$}   \\
+           & \bl{$\mid$} & \bl{$Char(c)$}          \\
+           & \bl{$\mid$} & \bl{$Seq(v_1\,v_2)$}\\
+           & \bl{$\mid$} & \bl{$Left(v)$}   \\
+           & \bl{$\mid$} & \bl{$Right(v)$}  \\
+           & \bl{$\mid$} & \bl{$[]$}      \\
+           & \bl{$\mid$} & \bl{$[v_1,\ldots\,v_n]$} \\
+  \end{tabular}
+\end{column}
+\end{columns}
+\end{center}
+
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{frame}[c]
+\frametitle{Mkeps}
+
+Finding a (posix) value for recognising the empty string
+
+\begin{center}
+\begin{tabular}{lcl}
+  \bl{$mkeps\,\epsilon$}  & \bl{$\dn$}  & \bl{$Empty$}\\
+  \bl{$mkeps\,r_1 + r_2$} & \bl{$\dn$}  & \bl{if $nullable(r_1)$}  \\
+                          &             & \bl{then $Left(mkeps(r_1))$}\\
+                          &             & \bl{else $Right(mkeps(r_2))$}\\
+  \bl{$mkeps\,r_1 \cdot r_2$}  & \bl{$\dn$} & \bl{$Seq(mkeps(r_1),mkeps(r_2))$}\\
+  \bl{$mkeps\,r^*$}      & \bl{$\dn$} & \bl{$[]$}  \\
+\end{tabular}
+\end{center}
+
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{frame}[c]
+\frametitle{Inject}
+
+Injecting (``Adding'') a character to a value\\
+
+\begin{center}
+\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}
+  \bl{$inj\,(c)\,c\,Empty$} & \bl{$\dn$}  & \bl{$Char\,c$}\\
+  \bl{$inj\,(r_1 + r_2)\,c\,Left(v)$} & \bl{$\dn$}  & \bl{$Left(inj\,r_1\,c\,v)$}\\
+  \bl{$inj\,(r_1 + r_2)\,c\,Right(v)$} & \bl{$\dn$}  & \bl{$Right(inj\,r_2\,c\,v)$}\\
+  \bl{$inj\,(r_1 \cdot r_2)\,c\,Seq(v_1,v_2)$} & \bl{$\dn$}  & \bl{$Seq(inj\,r_1\,c\,v_1,v_2)$}\\
+  \bl{$inj\,(r_1 \cdot r_2)\,c\,Left(Seq(v_1,v_2))$} & \bl{$\dn$}  & \bl{$Seq(inj\,r_1\,c\,v_1,v_2)$}\\
+  \bl{$inj\,(r_1 \cdot r_2)\,c\,Right(v)$} & \bl{$\dn$}  & \bl{$Seq(mkeps(r_1),inj\,r_2\,c\,v)$}\\
+  \bl{$inj\,(r^*)\,c\,Sequ(v,vs)$} & \bl{$\dn$}  & \bl{$inj\,r\,c\,v\,::\,vs$}\\
+\end{tabular}
+\end{center}\bigskip
+
+\footnotesize
+\bl{$inj$}: 1st arg $\mapsto$ a rexp; 2nd arg $\mapsto$ a character; 3rd arg $\mapsto$ a value 
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{frame}[c]
+\frametitle{Lexing}
+
+\begin{center}
+\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}
+  \bl{$lex\,r\,[]$} & \bl{$\dn$}  & \bl{if $nullable(r)$ then $mkeps(r)$ else $error$}\\
+  \bl{$lex\,r\,c::s$} & \bl{$\dn$}  & \bl{$inj\,r\,c\,lex(der(c,r), s)$}\\
+\end{tabular}
+\end{center}
+
+\footnotesize
+\bl{$lex$}: returns a value
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{frame}[c]
+\frametitle{Records}
+
+\begin{itemize}
+\item new regex: \bl{$(x:r)$}\hspace{7mm}new value: \bl{$Rec(x,v)$}\medskip\pause
+
+\item \bl{$nullable(x:r) \dn nullable(r)$}
+\item \bl{$der\,c\,(x:r) \dn (x:der\,c\,r)$}
+\item \bl{$mkeps(x:r) \dn Rec(x, mkeps(r))$}
+\item \bl{$inj\,(x:r)\,c\,v \dn Rec(x, inj\,r\,c\,v)$}
+\end{itemize}\bigskip\bigskip\pause
+
+\small
+for extracting subpatterns \bl{$(z: ((x:ab) + (y:ba))$}
+
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{frame}[c]
+\frametitle{While Tokens}
+
+\begin{center}
+\begin{tabular}{rcl}
+\pcode{WHILE\_REGS} & $\dn$ & \raisebox{-1mm}{\large(}\pcode{("k" : KEYWORD)} +\\ 
+                  &       & \phantom{(}\pcode{("i" : ID)} +\\ 
+                  &       & \phantom{(}\pcode{("o" : OP)} + \\
+                  &       & \phantom{(}\pcode{("n" : NUM)} + \\
+                  &       & \phantom{(}\pcode{("s" : SEMI)} +\\ 
+                  &       & \phantom{(}\pcode{("p" : (LPAREN + RPAREN))} +\\ 
+                  &       & \phantom{(}\pcode{("b" : (BEGIN + END))} +\\ 
+                  &       & \phantom{(}\pcode{("w" : WHITESPACE)}\raisebox{-1mm}{\large)$^*$}
+\end{tabular}
+\end{center}
+
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
+
 \end{document}
 
 %%% Local Variables: