author | Christian Urban <urbanc@in.tum.de> |
Sun, 21 May 2017 07:35:35 +0100 | |
changeset 494 | d0fc671bcbbf |
parent 492 | 39b7ff2cf1bc |
child 499 | dfd0f41f8668 |
permissions | -rw-r--r-- |
127
41ef073ac6c4
added
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
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
|
492 | 5 |
\usepackage{array} |
6 |
||
7 |
||
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
8 |
\begin{document} |
492 | 9 |
\newcolumntype{C}[1]{>{\centering}m{#1}} |
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
10 |
|
260
65d1ea0e989f
updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
11 |
\section*{Coursework 1 (Strand 1)} |
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
12 |
|
456
2fddf8ab744f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
439
diff
changeset
|
13 |
This coursework is worth 4\% and is due on 25 October at |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
351
diff
changeset
|
14 |
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
|
15 |
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
|
16 |
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
|
17 |
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
|
18 |
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
|
19 |
be awarded. You can submit your answers in a txt-file or pdf. |
418
010c5a03dca2
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
395
diff
changeset
|
20 |
Code send as code. |
358
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
351
diff
changeset
|
21 |
|
b3129cff41e9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
351
diff
changeset
|
22 |
|
259
e5f4b8ff23b8
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
253
diff
changeset
|
23 |
|
e5f4b8ff23b8
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
253
diff
changeset
|
24 |
\subsubsection*{Disclaimer} |
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
25 |
|
395
e57d3d92b856
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
358
diff
changeset
|
26 |
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
|
27 |
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
|
28 |
exception is the Scala code I showed during the lectures or |
418
010c5a03dca2
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
395
diff
changeset
|
29 |
uploaded to KEATS, which you can freely use.\bigskip |
259
e5f4b8ff23b8
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
253
diff
changeset
|
30 |
|
e5f4b8ff23b8
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
253
diff
changeset
|
31 |
|
492 | 32 |
\subsection*{Task} |
259
e5f4b8ff23b8
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
253
diff
changeset
|
33 |
|
e5f4b8ff23b8
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
253
diff
changeset
|
34 |
The task is to implement a regular expression matcher based on |
418
010c5a03dca2
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
395
diff
changeset
|
35 |
derivatives of regular expressions. The implementation should |
010c5a03dca2
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
395
diff
changeset
|
36 |
be able to deal with the usual (basic) regular expressions |
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
37 |
|
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
38 |
\[ |
418
010c5a03dca2
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
395
diff
changeset
|
39 |
\ZERO,\; \ONE,\; c,\; r_1 + r_2,\; r_1 \cdot r_2,\; r^* |
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
40 |
\] |
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
41 |
|
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
42 |
\noindent |
259
e5f4b8ff23b8
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
253
diff
changeset
|
43 |
but also with the following extended regular expressions: |
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
44 |
|
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
45 |
\begin{center} |
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
46 |
\begin{tabular}{ll} |
492 | 47 |
$[c_1,c_2,\ldots,c_n]$ & a set of characters---for character ranges\\ |
48 |
$r^+$ & one or more times $r$\\ |
|
49 |
$r^?$ & optional $r$\\ |
|
50 |
$r^{\{n\}}$ & exactly $n$-times\\ |
|
51 |
$r^{\{..m\}}$ & zero or more times $r$ but no more than $m$-times\\ |
|
52 |
$r^{\{n..\}}$ & at least $n$-times $r$\\ |
|
53 |
$r^{\{n..m\}}$ & at least $n$-times $r$ but no more than $m$-times\\ |
|
54 |
$\sim{}r$ & not-regular-expression of $r$\\ |
|
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
55 |
\end{tabular} |
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
56 |
\end{center} |
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
57 |
|
492 | 58 |
\noindent You can assume that $n$ and $m$ are greater or equal than |
59 |
$0$. In the case of $r^{\{n,m\}}$ you can also assume $0 \le n \le m$.\bigskip |
|
60 |
||
61 |
\noindent {\bf Important!} Your implementation should have explicit |
|
494 | 62 |
cases for the basic regular expressions, but also for explicit cases for |
492 | 63 |
the extended regular expressions. That means do not treat the extended |
64 |
regular expressions by just translating them into the basic ones. See |
|
65 |
also Question 2, where you are asked to explicitly give the rules for |
|
66 |
\textit{nullable} and \textit{der} for the extended regular |
|
67 |
expressions.\newpage |
|
68 |
||
69 |
\noindent |
|
70 |
The meanings of the extended regular expressions are |
|
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
71 |
|
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
72 |
\begin{center} |
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
73 |
\begin{tabular}{r@{\hspace{2mm}}c@{\hspace{2mm}}l} |
492 | 74 |
$L([c_1,c_2,\ldots,c_n])$ & $\dn$ & $\{[c_1], [c_2], \ldots, [c_n]\}$\\ |
75 |
$L(r^+)$ & $\dn$ & $\bigcup_{1\le i}.\;L(r)^i$\\ |
|
76 |
$L(r^?)$ & $\dn$ & $L(r) \cup \{[]\}$\\ |
|
77 |
$L(r^{\{n\}})$ & $\dn$ & $L(r)^n$\\ |
|
78 |
$L(r^{\{..m\}})$ & $\dn$ & $\bigcup_{0\le i \le m}.\;L(r)^i$\\ |
|
79 |
$L(r^{\{n..\}})$ & $\dn$ & $\bigcup_{n\le i}.\;L(r)^i$\\ |
|
80 |
$L(r^{\{n..m\}})$ & $\dn$ & $\bigcup_{n\le i \le m}.\;L(r)^i$\\ |
|
81 |
$L(\sim{}r)$ & $\dn$ & $\Sigma^* - L(r)$ |
|
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
82 |
\end{tabular} |
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
83 |
\end{center} |
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
84 |
|
395
e57d3d92b856
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
358
diff
changeset
|
85 |
\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
|
86 |
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
|
87 |
(in the implementation the alphabet can be just what is |
418
010c5a03dca2
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
395
diff
changeset
|
88 |
represented by, say, the type \pcode{Char}). So $\sim{}r$ |
492 | 89 |
means in effect ``all the strings that $r$ cannot match''.\medskip |
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
90 |
|
492 | 91 |
\noindent |
395
e57d3d92b856
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
358
diff
changeset
|
92 |
Be careful that your implementation of \textit{nullable} and |
492 | 93 |
\textit{der} satisfies for every regular expression $r$ the following |
94 |
two properties (see also Question 2): |
|
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
95 |
|
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
96 |
\begin{itemize} |
395
e57d3d92b856
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
358
diff
changeset
|
97 |
\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
|
98 |
\item $L(der\,c\,r) = Der\,c\,(L(r))$ |
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
99 |
\end{itemize} |
259
e5f4b8ff23b8
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
253
diff
changeset
|
100 |
|
e5f4b8ff23b8
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
253
diff
changeset
|
101 |
|
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
102 |
|
418
010c5a03dca2
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
395
diff
changeset
|
103 |
\subsection*{Question 1} |
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
104 |
|
395
e57d3d92b856
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
358
diff
changeset
|
105 |
What is your King's email address (you will need it in |
492 | 106 |
Question 4)? |
259
e5f4b8ff23b8
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
253
diff
changeset
|
107 |
|
418
010c5a03dca2
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
395
diff
changeset
|
108 |
\subsection*{Question 2} |
259
e5f4b8ff23b8
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
253
diff
changeset
|
109 |
|
473 | 110 |
From the |
395
e57d3d92b856
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
358
diff
changeset
|
111 |
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
|
112 |
\textit{nullable} and \textit{der} for the basic regular |
473 | 113 |
expressions. Implement the rules for the extended regular |
395
e57d3d92b856
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
358
diff
changeset
|
114 |
expressions: |
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
115 |
|
259
e5f4b8ff23b8
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
253
diff
changeset
|
116 |
\begin{center} |
e5f4b8ff23b8
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
253
diff
changeset
|
117 |
\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}} |
492 | 118 |
$\textit{nullable}([c_1,c_2,\ldots,c_n])$ & $\dn$ & $?$\\ |
119 |
$\textit{nullable}(r^+)$ & $\dn$ & $?$\\ |
|
120 |
$\textit{nullable}(r^?)$ & $\dn$ & $?$\\ |
|
121 |
$\textit{nullable}(r^{\{n\}})$ & $\dn$ & $?$\\ |
|
122 |
$\textit{nullable}(r^{\{..m\}})$ & $\dn$ & $?$\\ |
|
123 |
$\textit{nullable}(r^{\{n..\}})$ & $\dn$ & $?$\\ |
|
124 |
$\textit{nullable}(r^{\{n..m\}})$ & $\dn$ & $?$\\ |
|
125 |
$\textit{nullable}(\sim{}r)$ & $\dn$ & $?$ |
|
126 |
\end{tabular} |
|
127 |
\end{center} |
|
128 |
||
129 |
\begin{center} |
|
130 |
\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}} |
|
131 |
$der\, c\, ([c_1,c_2,\ldots,c_n])$ & $\dn$ & $?$\\ |
|
132 |
$der\, c\, (r^+)$ & $\dn$ & $?$\\ |
|
133 |
$der\, c\, (r^?)$ & $\dn$ & $?$\\ |
|
134 |
$der\, c\, (r^{\{n\}})$ & $\dn$ & $?$\\ |
|
135 |
$der\, c\, (r^{\{..m\}})$ & $\dn$ & $?$\\ |
|
136 |
$der\, c\, (r^{\{n..\}})$ & $\dn$ & $?$\\ |
|
137 |
$der\, c\, (r^{\{n..m\}})$ & $\dn$ & $?$\\ |
|
138 |
$der\, c\, (\sim{}r)$ & $\dn$ & $?$\\ |
|
259
e5f4b8ff23b8
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
253
diff
changeset
|
139 |
\end{tabular} |
e5f4b8ff23b8
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
253
diff
changeset
|
140 |
\end{center} |
e5f4b8ff23b8
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
253
diff
changeset
|
141 |
|
333
8890852e18b7
updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
328
diff
changeset
|
142 |
\noindent |
8890852e18b7
updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
328
diff
changeset
|
143 |
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
|
144 |
|
8890852e18b7
updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
328
diff
changeset
|
145 |
\begin{itemize} |
395
e57d3d92b856
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
358
diff
changeset
|
146 |
\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
|
147 |
\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
|
148 |
\end{itemize} |
8890852e18b7
updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
328
diff
changeset
|
149 |
|
473 | 150 |
\noindent |
492 | 151 |
Given the definitions of \textit{nullable} and \textit{der}, it is |
152 |
easy to implement a regular expression matcher. Test your regular |
|
153 |
expression matcher with (at least) the examples: |
|
154 |
||
155 |
||
156 |
\begin{center} |
|
157 |
\def\arraystretch{1.2} |
|
158 |
\begin{tabular}{r|m{12mm}|m{12mm}|m{12mm}|m{12mm}|m{12mm}|m{12mm}} |
|
159 |
string & $a^{\{3\}}$ & $(a^?)^{\{3\}}$ & $a^{\{..3\}}$ & |
|
160 |
$(a^?)^{\{..3\}}$ & $a^{\{3..5\}}$ & $(a^?)^{\{3..5\}}$\\\hline |
|
161 |
$[]$ &&&&&& \\\hline |
|
162 |
\texttt{a} &&&&&& \\\hline |
|
163 |
\texttt{aa} &&&&&& \\\hline |
|
164 |
\texttt{aaa} &&&&&& \\\hline |
|
165 |
\texttt{aaaaa} &&&&&& \\\hline |
|
166 |
\texttt{aaaaaa}&&&&&& \\ |
|
167 |
\end{tabular} |
|
168 |
\end{center} |
|
169 |
||
170 |
\noindent |
|
171 |
Does your matcher produce the expected results? |
|
473 | 172 |
|
418
010c5a03dca2
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
395
diff
changeset
|
173 |
\subsection*{Question 3} |
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
174 |
|
494 | 175 |
As you can see, there are a number of explicit regular expressions |
176 |
that deal with single or several characters, for example: |
|
492 | 177 |
|
178 |
\begin{center} |
|
179 |
\begin{tabular}{ll} |
|
494 | 180 |
$c$ & matches a single character\\ |
181 |
$[c_1,c_2,\ldots,c_n]$ & matches a set of characters---for character ranges\\ |
|
182 |
$\textit{ALL}$ & matches any character |
|
492 | 183 |
\end{tabular} |
184 |
\end{center} |
|
185 |
||
186 |
\noindent |
|
187 |
the latter is useful for matching any string (for example |
|
494 | 188 |
by using $\textit{ALL}^*$). In order to avoid having an explicit constructor |
189 |
for each case, we can generalise all these cases and introduce a single |
|
492 | 190 |
constructor $\textit{CFUN}(f)$ where $f$ is a function from characters |
494 | 191 |
to a boolean. The idea is that the function $f$ determines which character(s) |
192 |
are matched, namely those where $f$ returns \texttt{true}. |
|
193 |
In this question implement \textit{CFUN} and define |
|
492 | 194 |
|
195 |
\begin{center} |
|
196 |
\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}} |
|
197 |
$\textit{nullable}(\textit{CFUN}(f))$ & $\dn$ & $?$\\ |
|
198 |
$\textit{der}\,c\,(\textit{CFUN}(f))$ & $\dn$ & $?$ |
|
199 |
\end{tabular} |
|
200 |
\end{center} |
|
201 |
||
494 | 202 |
\noindent in your matcher and then also give definitions for |
492 | 203 |
|
204 |
\begin{center} |
|
205 |
\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}} |
|
206 |
$c$ & $\dn$ & $\textit{CFUN}(?)$\\ |
|
207 |
$[c_1,c_2,\ldots,c_n]$ & $\dn$ & $\textit{CFUN}(?)$\\ |
|
208 |
$\textit{ALL}$ & $\dn$ & $\textit{CFUN}(?)$ |
|
209 |
\end{tabular} |
|
210 |
\end{center} |
|
211 |
||
212 |
||
213 |
\subsection*{Question 4} |
|
214 |
||
215 |
Suppose $[a\mbox{-}z0\mbox{-}9\_\,.\mbox{-}]$ stands for the regular expression |
|
216 |
||
217 |
\[[a,b,c,\ldots,z,0,\dots,9,\_,.,\mbox{-}]\;.\] |
|
218 |
||
219 |
\noindent |
|
220 |
Define in your code the following regular expression for email addresses |
|
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
221 |
|
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
222 |
\[ |
492 | 223 |
([a\mbox{-}z0\mbox{-}9\_\,.-]^+)\cdot @\cdot ([a\mbox{-}z0\mbox{-}9\,.-]^+)\cdot .\cdot ([a\mbox{-}z\,.]^{\{2,6\}}) |
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
224 |
\] |
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
225 |
|
395
e57d3d92b856
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
358
diff
changeset
|
226 |
\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
|
227 |
address. When calculating the derivative, simplify all regular |
418
010c5a03dca2
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
395
diff
changeset
|
228 |
expressions as much as possible by applying the |
010c5a03dca2
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
395
diff
changeset
|
229 |
following 7 simplification rules: |
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
230 |
|
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
231 |
\begin{center} |
272
1446bc47a294
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
260
diff
changeset
|
232 |
\begin{tabular}{l@{\hspace{2mm}}c@{\hspace{2mm}}ll} |
439
7611ace6a93b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
418
diff
changeset
|
233 |
$r \cdot \ZERO$ & $\mapsto$ & $\ZERO$\\ |
7611ace6a93b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
418
diff
changeset
|
234 |
$\ZERO \cdot r$ & $\mapsto$ & $\ZERO$\\ |
7611ace6a93b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
418
diff
changeset
|
235 |
$r \cdot \ONE$ & $\mapsto$ & $r$\\ |
7611ace6a93b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
418
diff
changeset
|
236 |
$\ONE \cdot r$ & $\mapsto$ & $r$\\ |
7611ace6a93b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
418
diff
changeset
|
237 |
$r + \ZERO$ & $\mapsto$ & $r$\\ |
7611ace6a93b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
418
diff
changeset
|
238 |
$\ZERO + r$ & $\mapsto$ & $r$\\ |
333
8890852e18b7
updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
328
diff
changeset
|
239 |
$r + r$ & $\mapsto$ & $r$\\ |
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
240 |
\end{tabular} |
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
241 |
\end{center} |
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
242 |
|
418
010c5a03dca2
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
395
diff
changeset
|
243 |
\noindent Write down your simplified derivative in a readable |
010c5a03dca2
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
395
diff
changeset
|
244 |
notation using parentheses where necessary. That means you |
010c5a03dca2
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
395
diff
changeset
|
245 |
should use the infix notation $+$, $\cdot$, $^*$ and so on, |
492 | 246 |
instead of code.\bigskip |
395
e57d3d92b856
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
358
diff
changeset
|
247 |
|
492 | 248 |
\noindent |
249 |
Implement the simplification rules in your regular expression matcher. |
|
250 |
Consider the regular expression $/ \cdot * \cdot |
|
251 |
(\sim{}(\textit{ALL}^* \cdot * \cdot / \cdot \textit{ALL}^*)) \cdot * |
|
259
e5f4b8ff23b8
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
253
diff
changeset
|
252 |
\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
|
253 |
this regular expression. Answer yes or no. |
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
254 |
|
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
255 |
\begin{enumerate} |
216
f5ec7c597c5b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
256 |
\item \texttt{"/**/"} |
f5ec7c597c5b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
257 |
\item \texttt{"/*foobar*/"} |
f5ec7c597c5b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
258 |
\item \texttt{"/*test*/test*/"} |
f5ec7c597c5b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
259 |
\item \texttt{"/*test/*test*/"} |
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
260 |
\end{enumerate} |
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
261 |
|
418
010c5a03dca2
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
395
diff
changeset
|
262 |
\noindent |
492 | 263 |
Also let $r_1$ be the regular expression $a\cdot a\cdot a$ and $r_2$ be |
259
e5f4b8ff23b8
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
253
diff
changeset
|
264 |
$(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
|
265 |
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
|
266 |
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
|
267 |
with yes or no. \medskip |
130
5c4998375c46
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
129
diff
changeset
|
268 |
|
5c4998375c46
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
129
diff
changeset
|
269 |
\noindent |
259
e5f4b8ff23b8
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
253
diff
changeset
|
270 |
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
|
271 |
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
|
272 |
to not introducing any other character. |
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
273 |
|
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
274 |
\begin{enumerate} |
492 | 275 |
\setcounter{enumi}{4} |
216
f5ec7c597c5b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
276 |
\item \texttt{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\ |
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
277 |
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\ |
216
f5ec7c597c5b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
278 |
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"} |
f5ec7c597c5b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
279 |
\item \texttt{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\ |
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
280 |
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\ |
216
f5ec7c597c5b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
281 |
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"} |
f5ec7c597c5b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
282 |
\item \texttt{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\ |
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
283 |
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\ |
216
f5ec7c597c5b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
284 |
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"} |
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
285 |
\end{enumerate} |
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
286 |
|
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
287 |
|
492 | 288 |
|
127
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
289 |
\end{document} |
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
290 |
|
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
291 |
%%% Local Variables: |
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
292 |
%%% mode: latex |
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
293 |
%%% TeX-master: t |
41ef073ac6c4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
294 |
%%% End: |