# HG changeset patch # User Christian Urban # Date 1495348535 -3600 # Node ID d0fc671bcbbf576ce5fbfd7f61dd996a565816b1 # Parent 4e97783862ff9f1e3df5721f9ead2e85a0fd0f72 updated diff -r 4e97783862ff -r d0fc671bcbbf coursework/cw01.pdf Binary file coursework/cw01.pdf has changed diff -r 4e97783862ff -r d0fc671bcbbf coursework/cw01.tex --- a/coursework/cw01.tex Sun May 21 00:46:21 2017 +0100 +++ b/coursework/cw01.tex Sun May 21 07:35:35 2017 +0100 @@ -59,7 +59,7 @@ $0$. In the case of $r^{\{n,m\}}$ you can also assume $0 \le n \le m$.\bigskip \noindent {\bf Important!} Your implementation should have explicit -cases for the basic regular expressions, but also explicit cases for +cases for the basic regular expressions, but also for explicit cases for the extended regular expressions. That means do not treat the extended regular expressions by just translating them into the basic ones. See also Question 2, where you are asked to explicitly give the rules for @@ -172,23 +172,25 @@ \subsection*{Question 3} -There are a number of explicit regular expressions that deal with single or several -characters, for example: +As you can see, there are a number of explicit regular expressions +that deal with single or several characters, for example: \begin{center} \begin{tabular}{ll} - $c$ & match a single character\\ - $[c_1,c_2,\ldots,c_n]$ & match a set of characters---for character ranges\\ - $\textit{ALL}$ & match any character + $c$ & matches a single character\\ + $[c_1,c_2,\ldots,c_n]$ & matches a set of characters---for character ranges\\ + $\textit{ALL}$ & matches any character \end{tabular} \end{center} \noindent the latter is useful for matching any string (for example -$\textit{ALL}^*$). In order to avoid having an explicit constructor -for each case, we can generalise all such cases and introduce a single +by using $\textit{ALL}^*$). In order to avoid having an explicit constructor +for each case, we can generalise all these cases and introduce a single constructor $\textit{CFUN}(f)$ where $f$ is a function from characters -to a boolean. Implement +to a boolean. The idea is that the function $f$ determines which character(s) +are matched, namely those where $f$ returns \texttt{true}. +In this question implement \textit{CFUN} and define \begin{center} \begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}} @@ -197,7 +199,7 @@ \end{tabular} \end{center} -\noindent in your matcher and then give definitions for +\noindent in your matcher and then also give definitions for \begin{center} \begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}} diff -r 4e97783862ff -r d0fc671bcbbf coursework/cw02.pdf Binary file coursework/cw02.pdf has changed diff -r 4e97783862ff -r d0fc671bcbbf coursework/cw02.tex --- a/coursework/cw02.tex Sun May 21 00:46:21 2017 +0100 +++ b/coursework/cw02.tex Sun May 21 07:35:35 2017 +0100 @@ -88,7 +88,7 @@ \begin{center} \begin{tabular}{ll} -$[c_1 c_2 \ldots c_n]$ & a range of characters\\ +$[c_1,c_2,\ldots,c_n]$ & a set of characters\\ $r^+$ & one or more times $r$\\ $r^?$ & optional $r$\\ $r^{\{n\}}$ & n-times $r$\\ @@ -105,8 +105,9 @@ \end{center} \noindent Try to design your regular expressions to be as -small as possible. For example you should use character ranges -for identifiers and numbers. +small as possible. For example you should use character sets +for identifiers and numbers. Feel free to use the general +character constructor \textit{CFUN} introduced in CW 1. \subsection*{Question 2} @@ -119,11 +120,11 @@ \begin{center} \begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}} -$mkeps([c_1 c_2 \ldots c_n])$ & $\dn$ & $?$\\ +$mkeps([c_1,c_2,\ldots,c_n])$ & $\dn$ & $?$\\ $mkeps(r^+)$ & $\dn$ & $?$\\ $mkeps(r^?)$ & $\dn$ & $?$\\ $mkeps(r^{\{n\}})$ & $\dn$ & $?$\medskip\\ -$inj\, ([c_1 c_2 \ldots c_n])\,c\,\ldots$ & $\dn$ & $?$\\ +$inj\, ([c_1,c_2,\ldots,c_n])\,c\,\ldots$ & $\dn$ & $?$\\ $inj\, (r^+)\,c\,\ldots$ & $\dn$ & $?$\\ $inj\, (r^?)\,c\,\ldots$ & $\dn$ & $?$\\ $inj\, (r^{\{n\}})\,c\,\ldots$ & $\dn$ & $?$\\ @@ -175,16 +176,12 @@ \begin{figure}[p] -\begin{center} \mbox{\lstinputlisting[language=while]{../progs/fib.while}} -\end{center} \caption{Fibonacci program in the WHILE language.\label{fib}} \end{figure} \begin{figure}[p] -\begin{center} \mbox{\lstinputlisting[language=while]{../progs/loops.while}} -\end{center} \caption{The three-nested-loops program in the WHILE language. Usually used for timing measurements.\label{loop}} \end{figure}