hws/hw03.tex
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Thu, 26 Sep 2013 10:41:47 +0100
changeset 102 1ab41c59e3d3
parent 93 hw/hw03.tex@4794759139ea
child 132 04264d0c43bb
permissions -rw-r--r--
links
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
\documentclass{article}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
\usepackage{charter}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
\usepackage{hyperref}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
\usepackage{amssymb}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
\usepackage{amsmath}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
\begin{document}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
\section*{Homework 3}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
\begin{enumerate}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
\item Assume you have an alphabet consisting of the letters $a$, $b$ and $c$ only.
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
(a) Find a regular expression that recognises the two strings $ab$ and $ac$. (b)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
Find a regular expression that matches all strings \emph{except} these two strings.
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
Note, you can only use regular expressions of the form 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
$r ::= \varnothing \;|\; \epsilon \;|\; c  \;|\; r_1 + r_2  \;|\; r_1 \cdot r_2 \;|\; r^*$
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
\end{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
\item Define the function $zeroable$ which takes a regular expression as argument
30
Christian Urban <urbanc@in.tum.de>
parents: 27
diff changeset
    21
and returns a boolean.\footnote{In an earlier version there was an error.} The 
Christian Urban <urbanc@in.tum.de>
parents: 27
diff changeset
    22
function should satisfy the following property:
23
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
$zeroable(r)$ \;if and only if\; $L(r) = \varnothing$
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
\end{center}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
27
Christian Urban <urbanc@in.tum.de>
parents: 23
diff changeset
    27
\item Define the tokens and regular expressions for a language
Christian Urban <urbanc@in.tum.de>
parents: 23
diff changeset
    28
consisting of numbers, left-parenthesis (, right-parenthesis ),
Christian Urban <urbanc@in.tum.de>
parents: 23
diff changeset
    29
identifiers and the operations $+$, $-$ and $*$. Can the following strings 
Christian Urban <urbanc@in.tum.de>
parents: 23
diff changeset
    30
in this language be lexed?
Christian Urban <urbanc@in.tum.de>
parents: 23
diff changeset
    31
Christian Urban <urbanc@in.tum.de>
parents: 23
diff changeset
    32
\begin{itemize}
Christian Urban <urbanc@in.tum.de>
parents: 23
diff changeset
    33
\item \texttt{"}$(a + 3) * b$\texttt{"}
Christian Urban <urbanc@in.tum.de>
parents: 23
diff changeset
    34
\item \texttt{"}$)()++ -33$\texttt{"}
Christian Urban <urbanc@in.tum.de>
parents: 23
diff changeset
    35
\item \texttt{"}$(a / 3) * 3$\texttt{"}
Christian Urban <urbanc@in.tum.de>
parents: 23
diff changeset
    36
\end{itemize}
31
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents: 30
diff changeset
    37
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents: 30
diff changeset
    38
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents: 30
diff changeset
    39
In case they can, can you give the corresponding token sequences.
23
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
\end{enumerate}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
31
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents: 30
diff changeset
    42
27
Christian Urban <urbanc@in.tum.de>
parents: 23
diff changeset
    43
23
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
\end{document}
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
%%% Local Variables: 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
%%% mode: latex
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
%%% TeX-master: t
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
%%% End: