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