author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Fri, 26 Sep 2014 14:06:55 +0100 | |
changeset 258 | 1e4da6d2490c |
parent 146 | 9da175d5eb63 |
child 264 | 4deef8ac5d72 |
permissions | -rw-r--r-- |
23 | 1 |
\documentclass{article} |
2 |
\usepackage{charter} |
|
3 |
\usepackage{hyperref} |
|
4 |
\usepackage{amssymb} |
|
5 |
\usepackage{amsmath} |
|
6 |
||
7 |
\begin{document} |
|
8 |
||
9 |
\section*{Homework 3} |
|
10 |
||
11 |
\begin{enumerate} |
|
132
04264d0c43bb
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
102
diff
changeset
|
12 |
\item What is a regular language? |
04264d0c43bb
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
102
diff
changeset
|
13 |
|
258
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
14 |
\item Assume you have an alphabet consisting of the letters |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
15 |
$a$, $b$ and $c$ only. (1) Find a regular expression |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
16 |
that recognises the two strings $ab$ and $ac$. (2) Find |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
17 |
a regular expression that matches all strings |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
18 |
\emph{except} these two strings. Note, you can only use |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
19 |
regular expressions of the form |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
20 |
|
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
21 |
\begin{center} $r ::= |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
22 |
\varnothing \;|\; \epsilon \;|\; c \;|\; r_1 + r_2 \;|\; |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
23 |
r_1 \cdot r_2 \;|\; r^*$ |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
24 |
\end{center} |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
25 |
|
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
26 |
\item Define the function \textit{zeroable} which takes a |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
27 |
regular expression as argument and returns a boolean. |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
28 |
The function should satisfy the following property: |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
29 |
|
23 | 30 |
\begin{center} |
258
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
31 |
$\textit{zeroable(r)} \;\text{if and only if}\; L(r) = \varnothing$ |
23 | 32 |
\end{center} |
33 |
||
27 | 34 |
\item Define the tokens and regular expressions for a language |
258
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
35 |
consisting of numbers, left-parenthesis $($, |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
36 |
right-parenthesis $)$, identifiers and the operations $+$, |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
37 |
$-$ and $*$. Can the following strings in this language |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
38 |
be lexed? |
27 | 39 |
|
40 |
\begin{itemize} |
|
258
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
41 |
\item $(a + 3) * b$ |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
42 |
\item $)()++ -33$ |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
43 |
\item $(a / 3) * 3$ |
27 | 44 |
\end{itemize} |
31 | 45 |
|
258
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
46 |
In case they can, can you give the corresponding token |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
146
diff
changeset
|
47 |
sequences. |
31 | 48 |
|
23 | 49 |
\end{enumerate} |
50 |
||
31 | 51 |
|
27 | 52 |
|
23 | 53 |
\end{document} |
54 |
||
55 |
%%% Local Variables: |
|
56 |
%%% mode: latex |
|
57 |
%%% TeX-master: t |
|
58 |
%%% End: |