author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Tue, 20 Sep 2016 12:13:11 +0100 | |
changeset 420 | 25bc57b32efa |
parent 401 | 5d85dc9779b1 |
child 444 | 3056a4c071b0 |
permissions | -rw-r--r-- |
31 | 1 |
\documentclass{article} |
264
4deef8ac5d72
uodated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
166
diff
changeset
|
2 |
\usepackage{../style} |
292
7ed2a25dd115
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
267
diff
changeset
|
3 |
\usepackage{../graphics} |
146
9da175d5eb63
added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
102
diff
changeset
|
4 |
|
31 | 5 |
\begin{document} |
6 |
||
7 |
\section*{Homework 4} |
|
8 |
||
347
22b5294daa2a
updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
294
diff
changeset
|
9 |
\HEADER |
22b5294daa2a
updated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
294
diff
changeset
|
10 |
|
31 | 11 |
\begin{enumerate} |
34 | 12 |
|
166
ef48e378c44e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
13 |
\item If a regular expression $r$ does not contain any occurrence of $\varnothing$, |
42 | 14 |
is it possible for $L(r)$ to be empty? |
32 | 15 |
|
264
4deef8ac5d72
uodated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
166
diff
changeset
|
16 |
\item Define the tokens and regular expressions for a language |
267
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
17 |
consisting of numbers, left-parenthesis $($, right-parenthesis $)$, |
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
18 |
identifiers and the operations $+$, $-$ and $*$. Can the following |
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
19 |
strings in this language be lexed? |
264
4deef8ac5d72
uodated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
166
diff
changeset
|
20 |
|
267
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
21 |
\begin{itemize} |
264
4deef8ac5d72
uodated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
166
diff
changeset
|
22 |
\item $(a + 3) * b$ |
4deef8ac5d72
uodated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
166
diff
changeset
|
23 |
\item $)()++ -33$ |
4deef8ac5d72
uodated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
166
diff
changeset
|
24 |
\item $(a / 3) * 3$ |
267
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
25 |
\end{itemize} |
264
4deef8ac5d72
uodated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
166
diff
changeset
|
26 |
|
267
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
27 |
In case they can, can you give the corresponding token |
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
28 |
sequences. |
264
4deef8ac5d72
uodated hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
166
diff
changeset
|
29 |
|
32 | 30 |
\item Assume that $s^{-1}$ stands for the operation of reversing a |
267
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
31 |
string $s$. Given the following \emph{reversing} function on regular |
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
32 |
expressions |
32 | 33 |
|
267
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
34 |
\begin{center} |
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
35 |
\begin{tabular}{r@{\hspace{1mm}}c@{\hspace{1mm}}l} |
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
359
diff
changeset
|
36 |
$rev(\ZERO)$ & $\dn$ & $\ZERO$\\ |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
359
diff
changeset
|
37 |
$rev(\ONE)$ & $\dn$ & $\ONE$\\ |
267
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
38 |
$rev(c)$ & $\dn$ & $c$\\ |
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
39 |
$rev(r_1 + r_2)$ & $\dn$ & $rev(r_1) + rev(r_2)$\\ |
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
40 |
$rev(r_1 \cdot r_2)$ & $\dn$ & $rev(r_2) \cdot rev(r_1)$\\ |
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
41 |
$rev(r^*)$ & $\dn$ & $rev(r)^*$\\ |
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
42 |
\end{tabular} |
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
43 |
\end{center} |
34 | 44 |
|
267
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
45 |
and the set |
32 | 46 |
|
267
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
47 |
\begin{center} |
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
48 |
$Rev\,A \dn \{s^{-1} \;|\; s \in A\}$ |
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
49 |
\end{center} |
31 | 50 |
|
267
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
51 |
prove whether |
32 | 52 |
|
267
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
53 |
\begin{center} |
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
54 |
$L(rev(r)) = Rev (L(r))$ |
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
55 |
\end{center} |
31 | 56 |
|
267
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
57 |
holds. |
42 | 58 |
|
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
359
diff
changeset
|
59 |
\item Assume the delimiters for comments are |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
359
diff
changeset
|
60 |
\texttt{$\slash$*} and \texttt{*$\slash$}. Give a |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
359
diff
changeset
|
61 |
regular expression that can recognise comments of the |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
359
diff
changeset
|
62 |
form |
42 | 63 |
|
267
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
64 |
\begin{center} |
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
65 |
\texttt{$\slash$*~\ldots{}~*$\slash$} |
a1544b804d1e
updated homeworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
264
diff
changeset
|
66 |
\end{center} |
42 | 67 |
|
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
359
diff
changeset
|
68 |
where the three dots stand for arbitrary characters, but |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
359
diff
changeset
|
69 |
not comment delimiters. (Hint: You can assume you are |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
359
diff
changeset
|
70 |
already given a regular expression written \texttt{ALL}, |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
359
diff
changeset
|
71 |
that can recognise any character, and a regular |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
359
diff
changeset
|
72 |
expression \texttt{NOT} that recognises the complement |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
359
diff
changeset
|
73 |
of a regular expression.) |
355
a259eec25156
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
347
diff
changeset
|
74 |
|
a259eec25156
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
347
diff
changeset
|
75 |
\item Simplify the regular expression |
42 | 76 |
|
355
a259eec25156
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
347
diff
changeset
|
77 |
\[ |
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
359
diff
changeset
|
78 |
(\ZERO \cdot (b \cdot c)) + |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
359
diff
changeset
|
79 |
((\ZERO \cdot c) + \ONE) |
355
a259eec25156
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
347
diff
changeset
|
80 |
\] |
a259eec25156
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
347
diff
changeset
|
81 |
|
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
359
diff
changeset
|
82 |
Does simplification always preserve the meaning of a |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
359
diff
changeset
|
83 |
regular expression? |
355
a259eec25156
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
347
diff
changeset
|
84 |
|
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
359
diff
changeset
|
85 |
\item The Sulzmann \& Lu algorithm contains the function |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
359
diff
changeset
|
86 |
$mkeps$ which answers how a regular expression can match |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
359
diff
changeset
|
87 |
the empty string. What is the answer of $mkeps$ for the |
355
a259eec25156
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
347
diff
changeset
|
88 |
regular expressions: |
146
9da175d5eb63
added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
102
diff
changeset
|
89 |
|
355
a259eec25156
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
347
diff
changeset
|
90 |
\[ |
a259eec25156
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
347
diff
changeset
|
91 |
\begin{array}{l} |
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
359
diff
changeset
|
92 |
(\ZERO \cdot (b \cdot c)) + |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
359
diff
changeset
|
93 |
((\ZERO \cdot c) + \ONE)\\ |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
359
diff
changeset
|
94 |
(a + \ONE) \cdot (\ONE + \ONE) |
355
a259eec25156
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
347
diff
changeset
|
95 |
\end{array} |
a259eec25156
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
347
diff
changeset
|
96 |
\] |
a259eec25156
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
347
diff
changeset
|
97 |
|
401
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
359
diff
changeset
|
98 |
\item What is the purpose of the record regular expression in |
5d85dc9779b1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
359
diff
changeset
|
99 |
the Sulzmann \& Lu algorithm? |
355
a259eec25156
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
347
diff
changeset
|
100 |
|
a259eec25156
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
347
diff
changeset
|
101 |
|
146
9da175d5eb63
added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
102
diff
changeset
|
102 |
%\item (Optional) The tokenizer in \texttt{regexp3.scala} takes as |
9da175d5eb63
added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
102
diff
changeset
|
103 |
%argument a string and a list of rules. The result is a list of tokens. Improve this tokenizer so |
9da175d5eb63
added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
102
diff
changeset
|
104 |
%that it filters out all comments and whitespace from the result. |
9da175d5eb63
added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
102
diff
changeset
|
105 |
|
9da175d5eb63
added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
102
diff
changeset
|
106 |
%\item (Optional) Modify the tokenizer in \texttt{regexp2.scala} so that it |
9da175d5eb63
added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
102
diff
changeset
|
107 |
%implements the \texttt{findAll} function. This function takes a regular |
9da175d5eb63
added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
102
diff
changeset
|
108 |
%expressions and a string, and returns all substrings in this string that |
9da175d5eb63
added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
102
diff
changeset
|
109 |
%match the regular expression. |
31 | 110 |
\end{enumerate} |
111 |
||
112 |
||
113 |
\end{document} |
|
114 |
||
115 |
%%% Local Variables: |
|
116 |
%%% mode: latex |
|
117 |
%%% TeX-master: t |
|
118 |
%%% End: |