slides/slides04.tex
changeset 662 8da26d4c2ca8
parent 661 135fc1eba66a
child 671 83e38043ed78
equal deleted inserted replaced
661:135fc1eba66a 662:8da26d4c2ca8
   485 \frametitle{Regular Expressions}
   485 \frametitle{Regular Expressions}
   486 
   486 
   487 In programming languages they are often used to recognise:\medskip
   487 In programming languages they are often used to recognise:\medskip
   488 
   488 
   489 \begin{itemize}
   489 \begin{itemize}
   490 \item symbols, digits
   490 \item operands, digits
   491 \item identifiers
   491 \item identifiers
   492 \item numbers (non-leading zeros)
   492 \item numbers (non-leading zeros)
   493 \item keywords
   493 \item keywords
   494 \item comments
   494 \item comments
   495 \end{itemize}\bigskip
   495 \end{itemize}\bigskip
   614 
   614 
   615 \[
   615 \[
   616 \bl{(ab + a) \cdot (c + bc)}
   616 \bl{(ab + a) \cdot (c + bc)}
   617 \]\medskip
   617 \]\medskip
   618 
   618 
   619 and the string $\bl{abc}$.\pause\pause\bigskip
   619 and the string $\bl{abc}$.\pause\bigskip
   620 
   620 
   621 Or, keywords are \pcode{if} and identifiers are 
   621 Or, keywords are \code{if} etc and identifiers are 
   622 letters followed by ``letters + numbers + \_''$^*$
   622 letters followed by ``letters + numbers + \_''$^*$
   623 
   623 
   624 \[
   624 \[
   625 \bl{if}\qquad\bl{iffoo}
   625 \bl{if}\qquad\bl{iffoo}
   626 \]
   626 \]
   739 {\small\lstinputlisting[language=Scala,numbers=none,
   739 {\small\lstinputlisting[language=Scala,numbers=none,
   740 xleftmargin=-5mm] {../progs/app02.scala}}
   740 xleftmargin=-5mm] {../progs/app02.scala}}
   741 
   741 
   742 \end{frame}
   742 \end{frame}
   743 
   743 
   744 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   745 \begin{frame}[c]
       
   746 \frametitle{Mkeps}
       
   747 
       
   748 Finding a (posix) value for recognising the empty string:
       
   749 
       
   750 \begin{center}
       
   751 \begin{tabular}{lcl}
       
   752   \bl{$mkeps\,(\ONE)$}  & \bl{$\dn$}  & \bl{$Empty$}\\
       
   753   \bl{$mkeps\,(r_1 + r_2)$} & \bl{$\dn$}  & \bl{if $nullable(r_1)$}  \\
       
   754                           &             & \bl{then $Left(mkeps(r_1))$}\\
       
   755                           &             & \bl{else $Right(mkeps(r_2))$}\\
       
   756   \bl{$mkeps\,(r_1 \cdot r_2)$}  & \bl{$\dn$} & \bl{$Seq(mkeps(r_1),mkeps(r_2))$}\\
       
   757   \bl{$mkeps\,(r^*)$}      & \bl{$\dn$} & \bl{$Stars\,[]$}  \\
       
   758 \end{tabular}
       
   759 \end{center}
       
   760 
       
   761 \end{frame}
       
   762 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   763 
       
   764 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   765 \begin{frame}[c]
       
   766 \frametitle{Inject}
       
   767 
       
   768 Injecting (``Adding'') a character to a value\\[-12mm]\mbox{}
       
   769 
       
   770 \begin{center}
       
   771 \begin{tabular}{@{\hspace{-3mm}}l@{\hspace{1mm}}c@{\hspace{1mm}}l@{}}
       
   772   \bl{$inj\,(c)\,c\,(Empty)$} & \bl{$\dn$}  & \bl{$Char\,c$}\\
       
   773   \bl{$inj\,(r_1 + r_2)\,c\,(Left(v))$} & \bl{$\dn$}  & \bl{$Left(inj\,r_1\,c\,v)$}\\
       
   774   \bl{$inj\,(r_1 + r_2)\,c\,(Right(v))$} & \bl{$\dn$}  & \bl{$Right(inj\,r_2\,c\,v)$}\\
       
   775   \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)$}\\
       
   776   \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)$}\\
       
   777   \bl{$inj\,(r_1 \cdot r_2)\,c\,(Right(v))$} & \bl{$\dn$}  & \bl{$Seq(mkeps(r_1),inj\,r_2\,c\,v)$}\\
       
   778   \bl{$inj\,(r^*)\,c\,(Seq(v,Stars\,vs))$} & \bl{$\dn$}  & \bl{$Stars\,(inj\,r\,c\,v\,::\,vs)$}\\
       
   779 \end{tabular}
       
   780 \end{center}\bigskip
       
   781 
       
   782 \footnotesize
       
   783 \bl{$inj$}: 1st arg $\mapsto$ a rexp; 2nd arg $\mapsto$ a character; 3rd arg $\mapsto$ a value 
       
   784 \end{frame}
       
   785 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   786 
   744 
   787 
   745 
   788 
   746 
   789 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   747 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   790 \begin{frame}[c]
   748 \begin{frame}[c]
   812 \draw[->,line width=0.5mm]  (r1) -- (v1);
   770 \draw[->,line width=0.5mm]  (r1) -- (v1);
   813 \draw (r4) node[anchor=north west] {\;\raisebox{-8mm}{\bl{$mkeps$}}};
   771 \draw (r4) node[anchor=north west] {\;\raisebox{-8mm}{\bl{$mkeps$}}};
   814 \end{tikzpicture}
   772 \end{tikzpicture}
   815 \end{textblock}
   773 \end{textblock}
   816 
   774 
   817 \only<2->{
   775 \only<1->{
   818 \begin{textblock}{6}(1,0.8)
   776 \begin{textblock}{6}(1,0.8)
   819 \begin{bubble}[6cm]
   777 \begin{bubble}[6cm]
   820 \small
   778 \small
   821 \begin{tabular}{ll}
   779 \begin{tabular}{ll}
   822 \bl{$r_1$}: & \bl{$a \cdot (b \cdot c)$}\\
   780 \bl{$r_1$}: & \bl{$a \cdot (b \cdot c)$}\\
   928 
   886 
   929 
   887 
   930 \end{frame}
   888 \end{frame}
   931 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   889 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   932 
   890 
   933 
   891 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   892 \begin{frame}[c]
       
   893   \frametitle{Mkeps}
       
   894   
       
   895   Finding a (posix) value for recognising the empty string:
       
   896   
       
   897   \begin{center}
       
   898   \begin{tabular}{lcl}
       
   899     \bl{$mkeps\,(\ONE)$}  & \bl{$\dn$}  & \bl{$Empty$}\\
       
   900     \bl{$mkeps\,(r_1 + r_2)$} & \bl{$\dn$}  & \bl{if $nullable(r_1)$}  \\
       
   901                             &             & \bl{then $Left(mkeps(r_1))$}\\
       
   902                             &             & \bl{else $Right(mkeps(r_2))$}\\
       
   903     \bl{$mkeps\,(r_1 \cdot r_2)$}  & \bl{$\dn$} & \bl{$Seq(mkeps(r_1),mkeps(r_2))$}\\
       
   904     \bl{$mkeps\,(r^*)$}      & \bl{$\dn$} & \bl{$Stars\,[]$}  \\
       
   905   \end{tabular}
       
   906   \end{center}
       
   907   
       
   908   \end{frame}
       
   909   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   910   
       
   911   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   912   \begin{frame}[c]
       
   913   \frametitle{Inject}
       
   914   
       
   915   Injecting (``Adding'') a character to a value\\[-12mm]\mbox{}
       
   916   
       
   917   \begin{center}
       
   918   \begin{tabular}{@{\hspace{-3mm}}l@{\hspace{1mm}}c@{\hspace{1mm}}l@{}}
       
   919     \bl{$inj\,(c)\,c\,(Empty)$} & \bl{$\dn$}  & \bl{$Char\,c$}\\
       
   920     \bl{$inj\,(r_1 + r_2)\,c\,(Left(v))$} & \bl{$\dn$}  & \bl{$Left(inj\,r_1\,c\,v)$}\\
       
   921     \bl{$inj\,(r_1 + r_2)\,c\,(Right(v))$} & \bl{$\dn$}  & \bl{$Right(inj\,r_2\,c\,v)$}\\
       
   922     \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)$}\\
       
   923     \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)$}\\
       
   924     \bl{$inj\,(r_1 \cdot r_2)\,c\,(Right(v))$} & \bl{$\dn$}  & \bl{$Seq(mkeps(r_1),inj\,r_2\,c\,v)$}\\
       
   925     \bl{$inj\,(r^*)\,c\,(Seq(v,Stars\,vs))$} & \bl{$\dn$}  & \bl{$Stars\,(inj\,r\,c\,v\,::\,vs)$}\\
       
   926   \end{tabular}
       
   927   \end{center}\bigskip
       
   928   
       
   929   \footnotesize
       
   930   \begin{tabular}{l@{\hspace{2mm}}l}
       
   931   \bl{$inj$}: & 1st arg $\mapsto$ a rexp; 2nd arg $\mapsto$ a character; 
       
   932   3rd arg $\mapsto$ a value\\
       
   933               & result $\mapsto$ a value 
       
   934   \end{tabular}
       
   935   \end{frame}
       
   936   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   937   
   934 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   938 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   935 \begin{frame}[c]
   939 \begin{frame}[c]
   936 \frametitle{Lexing}
   940 \frametitle{Lexing}
   937 
   941 
   938 \begin{center}
   942 \begin{center}