| author | Christian Urban <christian dot urban at kcl dot ac dot uk> | 
| Fri, 22 Nov 2013 16:56:51 +0000 | |
| changeset 198 | f54972b0f641 | 
| parent 146 | 9da175d5eb63 | 
| child 258 | 1e4da6d2490c | 
| 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  | 
|
| 23 | 14  | 
\item Assume you have an alphabet consisting of the letters $a$, $b$ and $c$ only.  | 
| 
146
 
9da175d5eb63
added new hws
 
Christian Urban <christian dot urban at kcl dot ac dot uk> 
parents: 
132 
diff
changeset
 | 
15  | 
(1) Find a regular expression that recognises the two strings $ab$ and $ac$. (2)  | 
| 23 | 16  | 
Find a regular expression that matches all strings \emph{except} these two strings.
 | 
17  | 
Note, you can only use regular expressions of the form  | 
|
18  | 
\begin{center}
 | 
|
19  | 
$r ::= \varnothing \;|\; \epsilon \;|\; c \;|\; r_1 + r_2 \;|\; r_1 \cdot r_2 \;|\; r^*$  | 
|
20  | 
\end{center}
 | 
|
21  | 
||
22  | 
\item Define the function $zeroable$ which takes a regular expression as argument  | 
|
| 
132
 
04264d0c43bb
added
 
Christian Urban <christian dot urban at kcl dot ac dot uk> 
parents: 
102 
diff
changeset
 | 
23  | 
and returns a boolean. The  | 
| 30 | 24  | 
function should satisfy the following property:  | 
| 23 | 25  | 
\begin{center}
 | 
26  | 
$zeroable(r)$ \;if and only if\; $L(r) = \varnothing$  | 
|
27  | 
\end{center}
 | 
|
28  | 
||
| 27 | 29  | 
\item Define the tokens and regular expressions for a language  | 
30  | 
consisting of numbers, left-parenthesis (, right-parenthesis ),  | 
|
31  | 
identifiers and the operations $+$, $-$ and $*$. Can the following strings  | 
|
32  | 
in this language be lexed?  | 
|
33  | 
||
34  | 
\begin{itemize}
 | 
|
35  | 
\item \texttt{"}$(a + 3) * b$\texttt{"}
 | 
|
36  | 
\item \texttt{"}$)()++ -33$\texttt{"}
 | 
|
37  | 
\item \texttt{"}$(a / 3) * 3$\texttt{"}
 | 
|
38  | 
\end{itemize}
 | 
|
| 31 | 39  | 
|
40  | 
||
41  | 
In case they can, can you give the corresponding token sequences.  | 
|
| 23 | 42  | 
\end{enumerate}
 | 
43  | 
||
| 31 | 44  | 
|
| 27 | 45  | 
|
| 23 | 46  | 
\end{document}
 | 
47  | 
||
48  | 
%%% Local Variables:  | 
|
49  | 
%%% mode: latex  | 
|
50  | 
%%% TeX-master: t  | 
|
51  | 
%%% End:  |