slides/slides03.tex
changeset 134 e3a8cf96f570
parent 133 09efdf5cf07c
child 135 72b686e1c974
equal deleted inserted replaced
133:09efdf5cf07c 134:e3a8cf96f570
    98   %\footnotesize\textcolor{gray}{Antikythera automaton, 100 BC (Archimedes?)}
    98   %\footnotesize\textcolor{gray}{Antikythera automaton, 100 BC (Archimedes?)}
    99   %\end{center}
    99   %\end{center}
   100 
   100 
   101 \normalsize
   101 \normalsize
   102   \begin{center}
   102   \begin{center}
   103   \begin{tabular}{ll}
   103   \begin{tabular}{lp{8cm}}
   104   Email:  & christian.urban at kcl.ac.uk\\
   104   Email:  & christian.urban at kcl.ac.uk\\
   105   Office: & S1.27 (1st floor Strand Building)\\
   105   Office: & S1.27 (1st floor Strand Building)\\
   106   Slides: & KEATS (also home work is there)\\
   106   Slides: & KEATS (also home work and coursework is there)\\
   107   \end{tabular}
   107   \end{tabular}
   108   \end{center}
   108   \end{center}
   109 
   109 
   110 
   110 
   111 \end{frame}}
   111 \end{frame}}
   114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   115 \mode<presentation>{
   115 \mode<presentation>{
   116 \begin{frame}[c]
   116 \begin{frame}[c]
   117 \frametitle{\begin{tabular}{c}Regular Expressions\end{tabular}}
   117 \frametitle{\begin{tabular}{c}Regular Expressions\end{tabular}}
   118 
   118 
   119 They are often used to recognise:\medskip
   119 In programming languages they are often used to recognise:\medskip
   120 
   120 
   121 \begin{itemize}
   121 \begin{itemize}
   122 \item symbols, digits
   122 \item symbols, digits
   123 \item identifiers
   123 \item identifiers
   124 \item numbers (non-leading zeros)
   124 \item numbers (non-leading zeros)
   136 \mode<presentation>{
   136 \mode<presentation>{
   137 \begin{frame}[c]
   137 \begin{frame}[c]
   138 \frametitle{\begin{tabular}{c}Last Week\end{tabular}}
   138 \frametitle{\begin{tabular}{c}Last Week\end{tabular}}
   139 
   139 
   140 Last week I showed you a regular expression matcher 
   140 Last week I showed you a regular expression matcher 
   141 which works provably in all cases.
   141 which works provably correctly in all cases.
   142 
   142 
   143 \begin{center}
   143 \begin{center}
   144 \bl{$matcher\,r\,s$} \;\;if and only if \;\; \bl{$s \in L(r)$}
   144 \bl{$matcher\,r\,s$} \;\;if and only if \;\; \bl{$s \in L(r)$}
   145 \end{center}\bigskip\bigskip 
   145 \end{center}\bigskip\bigskip 
   146 
   146 
   216 \item \bl{$Der\,b\,(Der\,a\,(L(r)))$}\pause
   216 \item \bl{$Der\,b\,(Der\,a\,(L(r)))$}\pause
   217 \item \bl{$Der\,c\,(Der\,b\,(Der\,a\,(L(r))))$}\pause
   217 \item \bl{$Der\,c\,(Der\,b\,(Der\,a\,(L(r))))$}\pause
   218 \item finally we test whether the empty string is in this set\pause\medskip
   218 \item finally we test whether the empty string is in this set\pause\medskip
   219 \end{enumerate}
   219 \end{enumerate}
   220 
   220 
   221 The matching algorithm works similarly, just over regular expression than sets.
   221 The matching algorithm works similarly, just over regular expression instead of sets.
   222 \end{frame}}
   222 \end{frame}}
   223 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   223 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   224 
   224 
   225 
   225 
   226 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   226 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   231 
   231 
   232 \begin{enumerate}
   232 \begin{enumerate}
   233 \item \bl{$der\,a\,r$}
   233 \item \bl{$der\,a\,r$}
   234 \item \bl{$der\,b\,(der\,a\,r)$}
   234 \item \bl{$der\,b\,(der\,a\,r)$}
   235 \item \bl{$der\,c\,(der\,b\,(der\,a\,r))$}\bigskip\pause
   235 \item \bl{$der\,c\,(der\,b\,(der\,a\,r))$}\bigskip\pause
   236 \item finally check whether the latter regular expression can match the empty string
   236 \item finally check whether the last regular expression can match the empty string
   237 \end{enumerate}
   237 \end{enumerate}
   238 
   238 
   239 \end{frame}}
   239 \end{frame}}
   240 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   240 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   241 
   241 
   247 
   247 
   248 \begin{center}
   248 \begin{center}
   249 \bl{$nullable(r)$} \;if and only if\;  \bl{$"" \in L(r)$}
   249 \bl{$nullable(r)$} \;if and only if\;  \bl{$"" \in L(r)$}
   250 \end{center}
   250 \end{center}
   251 
   251 
   252 by induction on the regular expression.
   252 by induction on the regular expression.\bigskip\pause
       
   253 
       
   254 \begin{center}
       
   255 \huge\bf \alert{Any Questions?}
       
   256 \end{center}
       
   257 
   253 
   258 
   254 \end{frame}}
   259 \end{frame}}
   255 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   260 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   256 
   261 
   257 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   262 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   263 \begin{center}
   268 \begin{center}
   264 \bl{$L(der\,c\,r) = Der\,c\,(L(r))$}
   269 \bl{$L(der\,c\,r) = Der\,c\,(L(r))$}
   265 \end{center}
   270 \end{center}
   266 
   271 
   267 by induction on the regular expression.
   272 by induction on the regular expression.
   268 
       
   269 \end{frame}}
   273 \end{frame}}
   270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   274 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   271 
   275 
   272 
   276 
   273 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   277 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   320 A \alert{regular expression} specifies a language.\bigskip
   324 A \alert{regular expression} specifies a language.\bigskip
   321 
   325 
   322 A language is \alert{regular} iff there exists
   326 A language is \alert{regular} iff there exists
   323 a regular expression that recognises all its strings.\bigskip\bigskip\pause
   327 a regular expression that recognises all its strings.\bigskip\bigskip\pause
   324 
   328 
   325 \textcolor{gray}{not all languages are regular, e.g.~\bl{a$^n$b$^n$}.}
   329 \textcolor{gray}{not all languages are regular, e.g.~\bl{$a^nb^n$}.}
   326 \end{frame}}
   330 \end{frame}}
   327 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   328 
   332 
   329 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   330 \mode<presentation>{
   334 \mode<presentation>{
   331 \begin{frame}[t]
   335 \begin{frame}[t]
   332 \frametitle{\begin{tabular}{c}Regular Expressions\end{tabular}}
   336 \frametitle{\begin{tabular}{c}Regular Expressions\end{tabular}}
   333 
   337 
   334 \begin{center}
   338 \begin{center}
   335   \begin{tabular}{@ {}rrl@ {\hspace{13mm}}l}
   339    \begin{tabular}{@ {}rrl@ {\hspace{13mm}}l}
   336   \bl{r} & \bl{$::=$}  & \bl{$\varnothing$}  & null\\
   340   \bl{$r$} & \bl{$::=$}  & \bl{$\varnothing$}  & null\\
   337          & \bl{$\mid$} & \bl{$\epsilon$}        & empty string / "" / []\\
   341          & \bl{$\mid$} & \bl{$\epsilon$}        & empty string / "" / $[]$\\
   338          & \bl{$\mid$} & \bl{c}                         & character\\
   342          & \bl{$\mid$} & \bl{$c$}                         & character\\
   339          & \bl{$\mid$} & \bl{r$_1$ $\cdot$ r$_2$} & sequence\\
   343          & \bl{$\mid$} & \bl{$r_1 \cdot r_2$} & sequence\\
   340          & \bl{$\mid$} & \bl{r$_1$ + r$_2$}  & alternative / choice\\
   344          & \bl{$\mid$} & \bl{$r_1 + r_2$}  & alternative / choice\\
   341          & \bl{$\mid$} & \bl{r$^*$}                   & star (zero or more)\\
   345          & \bl{$\mid$} & \bl{$r^*$}                   & star (zero or more)\\
   342   \end{tabular}\bigskip
   346   \end{tabular}
   343   \end{center}
   347   \end{center}
   344 
       
   345 How about ranges \bl{[a-z]}, \bl{r$^\text{+}$} and \bl{!r}?
       
   346   
   348   
       
   349 How about ranges \bl{$[a\mbox{-}z]$}, \bl{$r^+$} and \bl{$\sim{}r$}? Do they increase the
       
   350 set of languages we can recognise?
       
   351   
   347 \end{frame}}
   352 \end{frame}}
   348 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   353 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   349 
   354 
   350 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   355 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   351 \mode<presentation>{
   356 \mode<presentation>{
   352 \begin{frame}[c]
   357 \begin{frame}[c]
   353 \frametitle{\begin{tabular}{c}Negation of Regular Expr's\end{tabular}}
   358 \frametitle{\begin{tabular}{c}Negation of Regular Expr's\end{tabular}}
   354 
   359 
   355 \begin{itemize}
   360 \begin{itemize}
   356 \item \bl{!r}  \hspace{6mm} (everything that \bl{r} cannot recognise)\medskip
   361 \item \bl{$\sim{}r$}  \hspace{6mm} (everything that \bl{r} cannot recognise)\medskip
   357 \item \bl{$L$(!r) $\dn$ UNIV - $L$(r)}\medskip
   362 \item \bl{$L(\sim{}r) \dn UNIV - L(r)$}\medskip
   358 \item \bl{nullable (!r) $\dn$ not (nullable(r))}\medskip
   363 \item \bl{$nullable (r) \dn not (nullable(r))$}\medskip
   359 \item \bl{der\,c\,(!r) $\dn$ !(der\,c\,r)}
   364 \item \bl{$der\,c\,(\sim{}r) \dn \;\sim{}(der\,c\,r)$}
   360 \end{itemize}
   365 \end{itemize}\bigskip\pause
   361 
   366 
   362 \end{frame}}
   367 Used often for comments:
   363 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   368 
   364 
   369 \[
   365 
   370 \bl{/ \cdot * \cdot (\sim{}([a\mbox{-}z]^* \cdot * \cdot / \cdot [a\mbox{-}z]^*)) \cdot * \cdot /}
   366 
   371 \]
   367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   372 
   368 \mode<presentation>{
   373 
   369 \begin{frame}[c]
   374 \end{frame}}
   370 \frametitle{\begin{tabular}{c}Regular Languages\end{tabular}}
   375 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   371 
   376 
   372 A language (a set of strings) is \alert{regular} iff there exists
   377 
   373 a regular expression that recognises all its strings.\bigskip\bigskip\pause
       
   374 
       
   375 
       
   376 Do you think there are languages that are {\bf not} regular?
       
   377 \end{frame}}
       
   378 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   379 
   378 
   380 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   379 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   381 \mode<presentation>{
   380 \mode<presentation>{
   382 \begin{frame}[c]
   381 \begin{frame}[c]
   383 \frametitle{\begin{tabular}{c}Regular Exp's for Lexing\end{tabular}}
   382 \frametitle{\begin{tabular}{c}Regular Exp's for Lexing\end{tabular}}