author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Fri, 23 Nov 2012 21:21:27 +0000 | |
changeset 75 | 898c25a4e399 |
parent 60 | hw07.tex@68d664c204d2 |
child 76 | 373cf55a3ca5 |
permissions | -rw-r--r-- |
59 | 1 |
\documentclass{article} |
2 |
\usepackage{charter} |
|
3 |
\usepackage{hyperref} |
|
4 |
\usepackage{amssymb} |
|
5 |
\usepackage{amsmath} |
|
6 |
\usepackage{tikz} |
|
7 |
\usetikzlibrary{automata} |
|
8 |
||
9 |
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions |
|
10 |
||
11 |
\begin{document} |
|
12 |
||
75
898c25a4e399
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
60
diff
changeset
|
13 |
\section*{Homework 8} |
59 | 14 |
|
15 |
\begin{enumerate} |
|
75
898c25a4e399
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
60
diff
changeset
|
16 |
\item Suppose the following grammar for the WHILE-language: |
59 | 17 |
|
18 |
\begin{center} |
|
75
898c25a4e399
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
60
diff
changeset
|
19 |
\begin{tabular}{l} |
898c25a4e399
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
60
diff
changeset
|
20 |
$S \rightarrow N\cdot P$\\ |
898c25a4e399
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
60
diff
changeset
|
21 |
$P \rightarrow V\cdot N$\\ |
898c25a4e399
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
60
diff
changeset
|
22 |
$N \rightarrow N\cdot N$\\ |
898c25a4e399
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
60
diff
changeset
|
23 |
$N \rightarrow A \cdot N$\\ |
898c25a4e399
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
60
diff
changeset
|
24 |
$N \rightarrow \texttt{student} \;|\; \texttt{trainer} \;|\; \texttt{team} \;|\; \texttt{trains}$\\ |
898c25a4e399
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
60
diff
changeset
|
25 |
$V \rightarrow \texttt{trains} \;|\; \texttt{team}$\\ |
898c25a4e399
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
60
diff
changeset
|
26 |
$A \rightarrow \texttt{The} \;|\; \texttt{the}$\\ |
898c25a4e399
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
60
diff
changeset
|
27 |
\end{tabular} |
59 | 28 |
\end{center} |
29 |
||
30 |
||
31 |
\item Consider the following grammar |
|
32 |
||
33 |
\begin{center} |
|
34 |
\begin{tabular}{l} |
|
35 |
$S \rightarrow N\cdot P$\\ |
|
36 |
$P \rightarrow V\cdot N$\\ |
|
37 |
$N \rightarrow N\cdot N$\\ |
|
38 |
$N \rightarrow A \cdot N$\\ |
|
39 |
$N \rightarrow \texttt{student} \;|\; \texttt{trainer} \;|\; \texttt{team} \;|\; \texttt{trains}$\\ |
|
40 |
$V \rightarrow \texttt{trains} \;|\; \texttt{team}$\\ |
|
41 |
$A \rightarrow \texttt{The} \;|\; \texttt{the}$\\ |
|
42 |
\end{tabular} |
|
43 |
\end{center} |
|
44 |
||
45 |
where $S$ is the start symbol and $S$, $P$, $N$, $V$ and $A$ are non-terminals. |
|
46 |
Using the CYK-algorithm, check whether or not the following string can be parsed |
|
47 |
by the grammar: |
|
48 |
||
49 |
\begin{center} |
|
50 |
\texttt{The trainer trains the student team} |
|
51 |
\end{center} |
|
52 |
||
60 | 53 |
\item {\bf (Optional)} The task is to match strings where the letters are in alphabetical order---for example, |
54 |
\texttt{abcfjz} would pass, but \texttt{acb} would not. Whitespace should be ignored---for example |
|
55 |
\texttt{ab c d} should pass. The point is to try to get the regular expression as short as possible! |
|
56 |
See: |
|
59 | 57 |
|
60 | 58 |
\begin{center} |
59 |
\url{http://callumacrae.github.com/regex-tuesday/challenge11.html} |
|
60 |
\end{center} |
|
59 | 61 |
\end{enumerate} |
62 |
||
63 |
\end{document} |
|
64 |
||
65 |
%%% Local Variables: |
|
66 |
%%% mode: latex |
|
67 |
%%% TeX-master: t |
|
68 |
%%% End: |