cws/cw03.tex
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Fri, 11 Nov 2016 11:17:40 +0000
changeset 35 9fea5f751be4
parent 6 aae256985251
child 62 2151c77e1e24
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
\documentclass{article}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
\usepackage{style}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
%%\usepackage{../langs}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
\begin{document}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
\section*{Coursework 3}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
This coursework is worth XXX\% and is due on XXXX at
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
16:00. You are asked to implement a regular expression matcher.
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
\subsubsection*{Disclaimer}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
It should be understood that the work you submit represents
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
your own effort. You have not copied from anyone else. An
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
exception is the Scala code I showed during the lectures or
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
uploaded to KEATS, which you can freely use.\bigskip
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
\subsubsection*{Task}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
The task is to implement a regular expression matcher based on
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
derivatives of regular expressions. The implementation should
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
be able to deal with the usual (basic) regular expressions
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
\begin{center}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
\begin{tabular}{lcll}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
  $r$ & $::=$ & $\ZERO$     & cannot match anything\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
      &   $|$ & $\ONE$      & can only match the empty string\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
      &   $|$ & $c$         & can match a character $c$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
      &   $|$ & $r_1 + r_2$ & can match either with $r_1$ or with $r_2$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
      &   $|$ & $r_1 \cdot r_2$ & can match first with $r_1$ and then with $r_2$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
      &   $|$ & $r^*$       & can match zero or more times $r$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
      &   $|$ & $r^{\{\uparrow n\}}$ & can match zero upto $n$ times $r$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
      &   $|$ & $r^{\{n\}}$ & can match exactly $n$ times $r$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
\end{tabular}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
\end{center}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
\noindent
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
Implement a function called \textit{nullable} by recursion over
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
regular expressions:
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
\begin{center}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
\begin{tabular}{lcl}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
$\textit{nullable}(\ZERO)$ & $\dn$ & $\textit{false}$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
$\textit{nullable}(\ONE)$  & $\dn$ & $\textit{true}$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
$\textit{nullable}(c)$     & $\dn$ & $\textit{false}$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
$\textit{nullable}(r_1 + r_2)$ & $\dn$ & $\textit{nullable}(r_1) \vee \textit{nullable}(r_2)$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
$\textit{nullable}(r_1 \cdot r_2)$ & $\dn$ & $\textit{nullable}(r_1) \wedge \textit{nullable}(r_2)$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
$\textit{nullable}(r^*)$ & $\dn$ & $\textit{true}$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
$\textit{nullable}(r^{\{\uparrow n\}})$ & $\dn$ & $\textit{true}$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
$\textit{nullable}(r^{\{n\}})$ & $\dn$ & 
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
   $\textit{if}\;n = 0\; \textit{then} \; \textit{true} \; \textit{else} \; \textit{nullable}(r)$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
\end{tabular}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
\end{center}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
\begin{center}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
\begin{tabular}{lcl}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
$\textit{der}\;c\;(\ZERO)$ & $\dn$ & $\ZERO$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
$\textit{der}\;c\;(\ONE)$  & $\dn$ & $\ZERO$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
$\textit{der}\;c\;(d)$     & $\dn$ & $\textit{if}\; c = d\;\textit{then} \;\ONE \; \textit{else} \;\ZERO$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
$\textit{der}\;c\;(r_1 + r_2)$ & $\dn$ & $(\textit{der}\;c\;r_1) + (\textit{der}\;c\;r_2)$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
$\textit{der}\;c\;(r_1 \cdot r_2)$ & $\dn$ & $\textit{if}\;\textit{nullable}(r_1)$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
      & & $\textit{then}\;((\textit{der}\;c\;r_1)\cdot r_2) + (\textit{der}\;c\;r_2)$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
      & & $\textit{else}\;(\textit{der}\;c\;r_1)\cdot r_2$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
$\textit{der}\;c\;(r^*)$ & $\dn$ & $(\textit{der}\;c\;r)\cdot (r^*)$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
$\textit{der}\;c\;(r^{\{\uparrow n\}})$ & $\dn$ & $\textit{if}\;n = 0\;\textit{then}\;\ZERO\;\text{else}\;
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
   (\textit{der}\;c\;r)\cdot (r^{\{\uparrow n-1\}})$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
$\textit{der}\;c\;(r^{\{n\}})$ & $\dn$ & 
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
   $\textit{if}\;n = 0\; \textit{then} \; \ZERO\; \textit{else}\;$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
   & & $\textit{if} \;\textit{nullable}(r)\;\textit{then}\;(\textit{der}\;c\;r)\cdot (r^{\{\uparrow n-1\}})$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
   & & $\textit{else}\;(\textit{der}\;c\;r)\cdot (r^{\{n-1\}})$
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
\end{tabular}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
\end{center}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
Be careful that your implementation of \textit{nullable} and
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
\textit{der}\;c\; satisfies for every $r$ the following two
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
properties (see also Question 2):
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
\begin{itemize}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
\item $\textit{nullable}(r)$ if and only if $[]\in L(r)$
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
\item $L(der\,c\,r) = Der\,c\,(L(r))$
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
\end{itemize}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
\noindent {\bf Important!} Your implementation should have
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
explicit cases for the basic regular expressions, but also
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
explicit cases for the extended regular expressions. That
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
means do not treat the extended regular expressions by just
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
translating them into the basic ones. See also Question 2,
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
where you are asked to explicitly give the rules for
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
\textit{nullable} and \textit{der}\;c\; for the extended regular
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
expressions.
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
\subsection*{Question 1}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
What is your King's email address (you will need it in
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
Question 3)?
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
\subsection*{Question 2}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
This question does not require any implementation. From the
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
lectures you have seen the definitions for the functions
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
\textit{nullable} and \textit{der}\;c\; for the basic regular
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
expressions. Give the rules for the extended regular
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
expressions:
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
\begin{center}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
$\textit{nullable}([c_1 c_2 \ldots c_n])$  & $\dn$ & $?$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
$\textit{nullable}(r^+)$                   & $\dn$ & $?$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
$\textit{nullable}(r^?)$                   & $\dn$ & $?$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
$\textit{nullable}(r^{\{n,m\}})$            & $\dn$ & $?$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
$\textit{nullable}(\sim{}r)$               & $\dn$ & $?$\medskip\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
$der\, c\, ([c_1 c_2 \ldots c_n])$  & $\dn$ & $?$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
$der\, c\, (r^+)$                   & $\dn$ & $?$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
$der\, c\, (r^?)$                   & $\dn$ & $?$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
$der\, c\, (r^{\{n,m\}})$            & $\dn$ & $?$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
$der\, c\, (\sim{}r)$               & $\dn$ & $?$\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
\end{tabular}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
\end{center}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
\noindent
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
Remember your definitions have to satisfy the two properties
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
\begin{itemize}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
\item $\textit{nullable}(r)$ if and only if $[]\in L(r)$
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
\item $L(der\,c\,r)) = Der\,c\,(L(r))$
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
\end{itemize}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
\subsection*{Question 3}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
Implement the following regular expression for email addresses
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
\[
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
([a\mbox{-}z0\mbox{-}9\_\!\_\,.-]^+)\cdot @\cdot ([a\mbox{-}z0\mbox{-}9\,.-]^+)\cdot .\cdot ([a\mbox{-}z\,.]^{\{2,6\}})
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
\]
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
\noindent and calculate the derivative according to your email
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
address. When calculating the derivative, simplify all regular
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
expressions as much as possible by applying the
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
following 7 simplification rules:
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
\begin{center}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
\begin{tabular}{l@{\hspace{2mm}}c@{\hspace{2mm}}ll}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
$r \cdot \ZERO$ & $\mapsto$ & $\ZERO$\\ 
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
$\ZERO \cdot r$ & $\mapsto$ & $\ZERO$\\ 
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
$r \cdot \ONE$ & $\mapsto$ & $r$\\ 
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
$\ONE \cdot r$ & $\mapsto$ & $r$\\ 
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
$r + \ZERO$ & $\mapsto$ & $r$\\ 
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
$\ZERO + r$ & $\mapsto$ & $r$\\ 
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
$r + r$ & $\mapsto$ & $r$\\ 
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
\end{tabular}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
\end{center}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
\noindent Write down your simplified derivative in a readable
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
notation using parentheses where necessary. That means you
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
should use the infix notation $+$, $\cdot$, $^*$ and so on,
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
instead of code.
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
 
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
\subsection*{Question 4}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
Suppose \textit{[a-z]} stands for the range regular expression
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
$[a,b,c,\ldots,z]$.  Consider the regular expression $/ \cdot * \cdot
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
(\sim{}([a\mbox{-}z]^* \cdot * \cdot / \cdot [a\mbox{-}z]^*)) \cdot *
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
\cdot /$ and decide wether the following four strings are matched by
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
this regular expression. Answer yes or no.
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
\begin{enumerate}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
\item \texttt{"/**/"}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
\item \texttt{"/*foobar*/"}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
\item \texttt{"/*test*/test*/"}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
\item \texttt{"/*test/*test*/"}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
\end{enumerate}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
\noindent
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
Also test your regular expression matcher with the regular
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
expression $a^{\{3,5\}}$ and the strings
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
\begin{enumerate}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
\setcounter{enumi}{4}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
\item \texttt{aa}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
\item \texttt{aaa}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
\item \texttt{aaaaa}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
\item \texttt{aaaaaa}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
\end{enumerate}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
\noindent
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
Does your matcher produce the expected results?
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
\subsection*{Question 5}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
Let $r_1$ be the regular expression $a\cdot a\cdot a$ and $r_2$ be
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
$(a^{\{19,19\}}) \cdot (a^?)$.  Decide whether the following three
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
strings consisting of $a$s only can be matched by $(r_1^+)^+$.
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
Similarly test them with $(r_2^+)^+$. Again answer in all six cases
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
with yes or no. \medskip
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
\noindent
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
These are strings are meant to be entirely made up of $a$s. Be careful
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
when copy-and-pasting the strings so as to not forgetting any $a$ and
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
to not introducing any other character.
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   207
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
\begin{enumerate}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
\item \texttt{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
\item \texttt{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\ 
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\ 
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   214
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   215
\item \texttt{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\ 
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\ 
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   217
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
\end{enumerate}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   220
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
\end{document}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
%%% Local Variables: 
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   224
%%% mode: latex
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   225
%%% TeX-master: t
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   226
%%% End: