author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Sat, 17 Oct 2015 11:24:41 +0100 | |
changeset 355 | a259eec25156 |
parent 305 | 23045b2b0b7b |
child 359 | db106e5b7c4d |
permissions | -rw-r--r-- |
59 | 1 |
\documentclass{article} |
292
7ed2a25dd115
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
194
diff
changeset
|
2 |
\usepackage{../style} |
59 | 3 |
|
4 |
\begin{document} |
|
5 |
||
6 |
\section*{Homework 7} |
|
7 |
||
8 |
\begin{enumerate} |
|
194
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
9 |
\item Suppose the context-sensitive grammar |
59 | 10 |
|
11 |
\begin{center} |
|
194
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
12 |
\begin{tabular}{lcl} |
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
13 |
$S$ & $\rightarrow$ & $bSAA\;|\; \epsilon$\\ |
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
14 |
$A$ & $\rightarrow$ & $a$\\ |
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
15 |
$bA$ & $\rightarrow$ & $Ab$\\ |
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
16 |
\end{tabular} |
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
17 |
\end{center} |
183
b17eff695c7f
added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
102
diff
changeset
|
18 |
|
194
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
19 |
where $S$ is the starting symbol of the grammar. |
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
20 |
Give a derivation of the string $"\!aaabaaabb"$. |
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
21 |
What can you say about the number of as and bs in the |
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
22 |
strings recognised by this grammar. |
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
23 |
|
59 | 24 |
|
25 |
\item Consider the following grammar |
|
26 |
||
27 |
\begin{center} |
|
28 |
\begin{tabular}{l} |
|
29 |
$S \rightarrow N\cdot P$\\ |
|
30 |
$P \rightarrow V\cdot N$\\ |
|
31 |
$N \rightarrow N\cdot N$\\ |
|
32 |
$N \rightarrow A \cdot N$\\ |
|
33 |
$N \rightarrow \texttt{student} \;|\; \texttt{trainer} \;|\; \texttt{team} \;|\; \texttt{trains}$\\ |
|
34 |
$V \rightarrow \texttt{trains} \;|\; \texttt{team}$\\ |
|
35 |
$A \rightarrow \texttt{The} \;|\; \texttt{the}$\\ |
|
36 |
\end{tabular} |
|
37 |
\end{center} |
|
38 |
||
39 |
where $S$ is the start symbol and $S$, $P$, $N$, $V$ and $A$ are non-terminals. |
|
40 |
Using the CYK-algorithm, check whether or not the following string can be parsed |
|
41 |
by the grammar: |
|
42 |
||
43 |
\begin{center} |
|
44 |
\texttt{The trainer trains the student team} |
|
45 |
\end{center} |
|
46 |
||
194
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
47 |
\item Transform the grammar |
59 | 48 |
|
60 | 49 |
\begin{center} |
194
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
50 |
\begin{tabular}{lcl} |
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
51 |
$A$ & $\rightarrow$ & $0A1 \;|\; BB$\\ |
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
52 |
$B$ & $\rightarrow$ & $\epsilon \;|\; 2B$ |
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
53 |
\end{tabular} |
60 | 54 |
\end{center} |
194
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
55 |
|
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
56 |
\noindent |
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
57 |
into Chomsky normal form. |
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
58 |
|
305
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
59 |
\item Consider the following grammar $G$ |
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
60 |
|
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
61 |
\begin{center} |
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
62 |
\begin{tabular}{l} |
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
63 |
$S \rightarrow \texttt{if0} \cdot E \cdot \texttt{then} \cdot S$\\ |
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
64 |
$S \rightarrow \texttt{print} \cdot S$\\ |
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
65 |
$S \rightarrow \texttt{begin} \cdot B\cdot \texttt{end}$\\ |
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
66 |
$B \rightarrow S\cdot \texttt{;}$\\ |
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
67 |
$B \rightarrow S\cdot \texttt{;} \cdot B$\\ |
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
68 |
$E \rightarrow num$ |
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
69 |
\end{tabular} |
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
70 |
\end{center} |
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
71 |
|
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
72 |
where $S$ is the start symbol and $S$, $E$ and $B$ are |
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
73 |
non-terminals. |
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
74 |
|
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
75 |
Check each rule below and decide whether, when added to $G$, |
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
76 |
the combined grammar is ambiguous. If yes, give a string that |
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
77 |
has more than one parse tree. |
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
78 |
|
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
79 |
\begin{center} |
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
80 |
\begin{tabular}{rl} |
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
81 |
(i) & $S \rightarrow \texttt{if0} \cdot E\cdot \texttt{then} \cdot S\cdot \texttt{else} \cdot S$\\ |
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
82 |
(ii) & $B \rightarrow B \cdot B$\\ |
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
83 |
(iii) & $E \rightarrow ( \cdot E \cdot )$\\ |
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
84 |
(iv) & $E \rightarrow E \cdot + \cdot E$ |
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
85 |
\end{tabular} |
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
86 |
\end{center} |
23045b2b0b7b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
87 |
|
194
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
88 |
|
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
89 |
%\item {\bf (Optional)} The task is to match strings where the letters are in alphabetical order---for example, |
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
90 |
%\texttt{abcfjz} would pass, but \texttt{acb} would not. Whitespace should be ignored---for example |
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
91 |
%\texttt{ab c d} should pass. The point is to try to get the regular expression as short as possible! |
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
92 |
%See: |
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
93 |
|
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
94 |
%\begin{center} |
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
95 |
%\url{http://callumacrae.github.com/regex-tuesday/challenge11.html} |
90796ee3c17a
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
183
diff
changeset
|
96 |
%\end{center} |
59 | 97 |
\end{enumerate} |
98 |
||
99 |
\end{document} |
|
100 |
||
101 |
%%% Local Variables: |
|
102 |
%%% mode: latex |
|
103 |
%%% TeX-master: t |
|
104 |
%%% End: |