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