coursework/cw01.tex
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Tue, 12 Jan 2016 02:18:58 +0000
changeset 395 e57d3d92b856
parent 358 b3129cff41e9
child 418 010c5a03dca2
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
\documentclass{article}
253
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 216
diff changeset
     2
\usepackage{../style}
216
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
     3
\usepackage{../langs}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
\begin{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
260
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
     7
\section*{Coursework 1 (Strand 1)}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 351
diff changeset
     9
This coursework is worth 5\% and is due on 20 October at
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 351
diff changeset
    10
16:00. You are asked to implement a regular expression matcher
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 351
diff changeset
    11
and submit a document containing the answers for the questions
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 351
diff changeset
    12
below. You can do the implementation in any programming
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 351
diff changeset
    13
language you like, but you need to submit the source code with
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 351
diff changeset
    14
which you answered the questions, otherwise a mark of 0\% will
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    15
be awarded. You can submit your answers in a txt-file or pdf.
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 351
diff changeset
    16
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 351
diff changeset
    17
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    18
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    19
\subsubsection*{Disclaimer}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    21
It should be understood that the work you submit represents
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    22
your own effort. You have not copied from anyone else. An
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    23
exception is the Scala code I showed during the lectures or
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    24
uploaded to KEATS, which you can use.\bigskip
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    25
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    26
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    27
\subsubsection*{Tasks}
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    28
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    29
The task is to implement a regular expression matcher based on
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    30
derivatives. The implementation should be able to deal with the usual
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    31
(basic) regular expressions
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
\[
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
\varnothing, \epsilon, c, r_1 + r_2, r_1 \cdot r_2, r^*
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
\]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
\noindent
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    38
but also with the following extended regular expressions:
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
\begin{tabular}{ll}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
$[c_1 c_2 \ldots c_n]$ & a range of characters\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
$r^+$ & one or more times $r$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
$r^?$ & optional $r$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
$r^{\{n,m\}}$ & at least $n$-times $r$ but no more than $m$-times\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
$\sim{}r$ & not-regular expression of $r$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
\end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    50
\noindent In the case of $r^{\{n,m\}}$ we have the convention
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    51
that $0 \le n \le m$. The meanings of the extended regular
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    52
expressions are
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
\begin{tabular}{r@{\hspace{2mm}}c@{\hspace{2mm}}l}
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    56
$L([c_1 c_2 \ldots c_n])$ & $\dn$ & $\{[c_1], [c_2], \ldots, [c_n]\}$\\ 
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    57
$L(r^+)$                  & $\dn$ & $\bigcup_{1\le i}. L(r)^i$\\
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    58
$L(r^?)$                  & $\dn$ & $L(r) \cup \{[]\}$\\
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    59
$L(r^{\{n,m\}})$           & $\dn$ & $\bigcup_{n\le i \le m}. L(r)^i$\\
333
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
    60
$L(\sim{}r)$              & $\dn$ & $\Sigma^* - L(r)$
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
\end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    64
\noindent whereby in the last clause the set $\Sigma^*$ stands
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    65
for the set of \emph{all} strings over the alphabet $\Sigma$
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    66
(in the implementation the alphabet can be just what is
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    67
represented by, say, the type \pcode{char}). So $\sim{}r$
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    68
means `all the strings that $r$ cannot match'. 
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    70
Be careful that your implementation of \textit{nullable} and
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    71
\textit{der} satisfies for every $r$ the following two
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    72
properties (see also Question 2):
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
\begin{itemize}
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    75
\item $\textit{nullable}(r)$ if and only if $[]\in L(r)$
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    76
\item $L(der\,c\,r) = Der\,c\,(L(r))$
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
\end{itemize}
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    78
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    79
\noindent {\bf Important!} Your implementation should have
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    80
explicit cases for the basic regular expressions, but also
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    81
explicit cases for the extended regular expressions. That
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    82
means do not treat the extended regular expressions by just
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    83
translating them into the basic ones. See also Question 2,
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    84
where you are asked to explicitly give the rules for
260
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
    85
\textit{nullable} and \textit{der} for the extended regular
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
    86
expressions.
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    87
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    88
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
\subsection*{Question 1 (unmarked)}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    90
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    91
What is your King's email address (you will need it in
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    92
Question 3)?
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    93
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    94
\subsection*{Question 2 (marked with 2\%)}
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    95
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    96
This question does not require any implementation. From the
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    97
lectures you have seen the definitions for the functions
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    98
\textit{nullable} and \textit{der} for the basic regular
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    99
expressions. Give the rules for the extended regular
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   100
expressions:
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   101
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   102
\begin{center}
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   103
\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   104
$\textit{nullable}([c_1 c_2 \ldots c_n])$  & $\dn$ & $?$\\
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   105
$\textit{nullable}(r^+)$                   & $\dn$ & $?$\\
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   106
$\textit{nullable}(r^?)$                   & $\dn$ & $?$\\
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   107
$\textit{nullable}(r^{\{n,m\}})$            & $\dn$ & $?$\\
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   108
$\textit{nullable}(\sim{}r)$               & $\dn$ & $?$\medskip\\
260
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   109
$der\, c\, ([c_1 c_2 \ldots c_n])$  & $\dn$ & $?$\\
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   110
$der\, c\, (r^+)$                   & $\dn$ & $?$\\
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   111
$der\, c\, (r^?)$                   & $\dn$ & $?$\\
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   112
$der\, c\, (r^{\{n,m\}})$            & $\dn$ & $?$\\
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   113
$der\, c\, (\sim{}r)$               & $\dn$ & $?$\\
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   114
\end{tabular}
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   115
\end{center}
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   116
333
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   117
\noindent
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   118
Remember your definitions have to satisfy the two properties
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   119
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   120
\begin{itemize}
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   121
\item $\textit{nullable}(r)$ if and only if $[]\in L(r)$
333
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   122
\item $L(der\,c\,r)) = Der\,c\,(L(r))$
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   123
\end{itemize}
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   124
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   125
\subsection*{Question 3 (marked with 1\%)}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   126
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   127
Implement the following regular expression for email addresses
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   128
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   129
\[
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   130
([a\mbox{-}z0\mbox{-}9\_\!\_\,.-]^+)\cdot @\cdot ([a\mbox{-}z0\mbox{-}9\,.-]^+)\cdot .\cdot ([a\mbox{-}z\,.]^{\{2,6\}})
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   131
\]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   132
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   133
\noindent and calculate the derivative according to your email
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   134
address. When calculating the derivative, simplify all regular
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   135
expressions as much as possible, but at least apply the
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   136
following six simplification rules:
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   137
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   138
\begin{center}
272
1446bc47a294 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   139
\begin{tabular}{l@{\hspace{2mm}}c@{\hspace{2mm}}ll}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   140
$r \cdot \varnothing$ & $\mapsto$ & $\varnothing$\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   141
$\varnothing \cdot r$ & $\mapsto$ & $\varnothing$\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   142
$r \cdot \epsilon$ & $\mapsto$ & $r$\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   143
$\epsilon \cdot r$ & $\mapsto$ & $r$\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   144
$r + \varnothing$ & $\mapsto$ & $r$\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   145
$\varnothing + r$ & $\mapsto$ & $r$\\ 
333
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   146
$r + r$ & $\mapsto$ & $r$\\ 
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   147
\end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   148
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   149
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   150
\noindent
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   151
Write down your simplified derivative in the ``mathematicical''
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   152
notation using parentheses where necessary. That means you should
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   153
use the more readable infix notation $+$, $\cdot$ and $^*$, 
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   154
instead of code.
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   155
 
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   156
\subsection*{Question 4 (marked with 1\%)}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   157
260
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   158
Suppose \textit{[a-z]} stands for the range regular expression
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   159
$[a,b,c,\ldots,z]$.  Consider the regular expression $/ \cdot * \cdot
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   160
(\sim{}([a\mbox{-}z]^* \cdot * \cdot / \cdot [a\mbox{-}z]^*)) \cdot *
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   161
\cdot /$ and decide wether the following four strings are matched by
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   162
this regular expression. Answer yes or no.
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   163
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   164
\begin{enumerate}
216
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   165
\item \texttt{"/**/"}
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   166
\item \texttt{"/*foobar*/"}
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   167
\item \texttt{"/*test*/test*/"}
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   168
\item \texttt{"/*test/*test*/"}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   169
\end{enumerate}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   170
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   171
\subsection*{Question 5 (marked with 1\%)}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   172
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   173
Let $r_1$ be the regular expression $a\cdot a\cdot a$ and $r_2$ be
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   174
$(a^{\{19,19\}}) \cdot (a^?)$.  Decide whether the following three
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   175
strings consisting of $a$s only can be matched by $(r_1^+)^+$.
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   176
Similarly test them with $(r_2^+)^+$. Again answer in all six cases
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   177
with yes or no. \medskip
130
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 129
diff changeset
   178
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 129
diff changeset
   179
\noindent
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   180
These are strings are meant to be entirely made up of $a$s. Be careful
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   181
when copy-and-pasting the strings so as to not forgetting any $a$ and
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   182
to not introducing any other character.
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   183
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   184
\begin{enumerate}
216
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   185
\item \texttt{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   186
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\
216
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   187
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   188
\item \texttt{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\ 
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   189
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\ 
216
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   190
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   191
\item \texttt{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\ 
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   192
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\ 
216
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   193
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   194
\end{enumerate}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   195
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   197
\end{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   198
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   199
%%% Local Variables: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   200
%%% mode: latex
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   201
%%% TeX-master: t
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   202
%%% End: