coursework/cw01.tex
changeset 576 550186034b6e
parent 567 4573d36d0b2f
child 577 7a437f1f689d
equal deleted inserted replaced
575:21631a040fc1 576:550186034b6e
       
     1 
     1 \documentclass{article}
     2 \documentclass{article}
     2 \usepackage{../style}
     3 \usepackage{../style}
     3 \usepackage{../langs}
     4 \usepackage{../langs}
     4 
     5 
     5 \usepackage{array}
     6 \usepackage{array}
    68   \code{RANGE}, \code{PLUS}, \code{OPTIONAL}, \code{NTIMES},
    69   \code{RANGE}, \code{PLUS}, \code{OPTIONAL}, \code{NTIMES},
    69   \code{UPTO}, \code{FROM}, \code{BETWEEN}, \code{NOT} or something
    70   \code{UPTO}, \code{FROM}, \code{BETWEEN}, \code{NOT} or something
    70   like that.} That means do not treat the extended regular expressions
    71   like that.} That means do not treat the extended regular expressions
    71 by just translating them into the basic ones. See also Question 3,
    72 by just translating them into the basic ones. See also Question 3,
    72 where you are asked to explicitly give the rules for \textit{nullable}
    73 where you are asked to explicitly give the rules for \textit{nullable}
    73 and \textit{der} for the extended regular expressions.\medskip
    74 and \textit{der} for the extended regular expressions. So something like
       
    75 $der\,c\,(r^+) \dn der\,c\,(r\cdot r^*)$ is \emph{not} allowed.\medskip
    74 
    76 
    75 \noindent
    77 \noindent
    76 The meanings of the extended regular expressions are
    78 The meanings of the extended regular expressions are
    77 
    79 
    78 \begin{center}
    80 \begin{center}
   199 \noindent
   201 \noindent
   200 The latter is useful for matching any string (for example
   202 The latter is useful for matching any string (for example
   201 by using $\textit{ALL}^*$). In order to avoid having an explicit constructor
   203 by using $\textit{ALL}^*$). In order to avoid having an explicit constructor
   202 for each case, we can generalise all these cases and introduce a single
   204 for each case, we can generalise all these cases and introduce a single
   203 constructor $\textit{CFUN}(f)$ where $f$ is a function from characters
   205 constructor $\textit{CFUN}(f)$ where $f$ is a function from characters
   204 to booleans. The idea is that the function $f$ determines which character(s)
   206 to booleans. In Scala code this would look as follows:
       
   207 
       
   208 \begin{lstlisting}[numbers=none]
       
   209 abstract class Rexp
       
   210 ...
       
   211 case class CFUN(f: Char => Boolean) extends Rexp 
       
   212 \end{lstlisting}\smallskip
       
   213 
       
   214 \noindent
       
   215 The idea is that the function $f$ determines which character(s)
   205 are matched, namely those where $f$ returns \texttt{true}.
   216 are matched, namely those where $f$ returns \texttt{true}.
   206 In this question implement \textit{CFUN} and define
   217 In this question implement \textit{CFUN} and define
   207 
   218 
   208 \begin{center}
   219 \begin{center}
   209 \begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
   220 \begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}