mirror of
https://github.com/MartinThoma/LaTeX-examples.git
synced 2025-04-25 06:18:05 +02:00
First- und Follow hinzugefügt
This commit is contained in:
parent
f5b2145486
commit
fac84dbab3
5 changed files with 97 additions and 1 deletions
|
@ -184,6 +184,79 @@ Maschinencode oder Assembler zu erstellen. Dabei muss folgendes beachtet werden:
|
|||
\item \textbf{Nachoptimierung}\todo{?}
|
||||
\end{itemize}
|
||||
|
||||
\section{Weiteres}
|
||||
\subsection{First- und Follow}
|
||||
\begin{definition}[$k$-Präfix]\xindex{Präfix}\xindex{\# (Compilerbau)}%
|
||||
Sei $G = (\Sigma, V, P, S)$ eine Grammatik, $k \in \mdn_{> 0}$ und
|
||||
$x \in (V \cup \Sigma)^*$ mit
|
||||
\[x = x_1 \dots x_m \text{ mit } x_i \in (V \cup \Sigma) \text{ wobei } i \in 1, \dots, m\]
|
||||
|
||||
Dann heißt $\tilde{x} \in (V \cup \Sigma \cup \Set{\#})^+$ ein $k$-\textbf{Präfix} von $x$,
|
||||
wenn gilt:
|
||||
\[\tilde{x} =
|
||||
\begin{cases}
|
||||
x\# &\text{falls } x = x_1 \dots x_m \text{ und } m < k\\
|
||||
x_1 \dots x_k &\text{sonst}
|
||||
\end{cases}\]
|
||||
wobei $\#$ das Ende der Eingabe bezeichnet. In diesem Fall schreibt man
|
||||
\[ \tilde{x} = k\ :\ x\]
|
||||
\end{definition}
|
||||
|
||||
\begin{beispiel}[$k$-Präfixe]
|
||||
Sei $G = (\Set{A, B, C, S}, \Set{a, b, c}, P, S)$ mit
|
||||
\begin{align*}
|
||||
P = \{ &A \rightarrow aa | ab, \\
|
||||
&B \rightarrow AC,\\
|
||||
&C \rightarrow c,\\
|
||||
&S \rightarrow ABC\}
|
||||
\end{align*}
|
||||
|
||||
Dann gilt:
|
||||
\begin{bspenum}
|
||||
\item $A = 1 : S$
|
||||
\item $a = 1 : S$
|
||||
\end{bspenum}
|
||||
|
||||
\todo[inline]{Das ist ein Problem! Damit wäre $k : x$ nicht wohldefiniert!}
|
||||
\end{beispiel}
|
||||
|
||||
\begin{definition}[First- und Follow-Menge]\xindex{Firstkx@$\text{First}_k(x)$}\xindex{Followkx@$\text{Follow}_k(x)$}%
|
||||
Sei $G = (\Sigma, V, P, S)$ eine Grammatik und $x \in V$.
|
||||
|
||||
\begin{defenum}
|
||||
\item $\begin{aligned}[t]\First_k (x) := \{u \in (V \cup \Sigma)^+ | &\exists y \in \Sigma^*:\\
|
||||
&x \Rightarrow^* y\\
|
||||
\land &u = k : y \}\end{aligned}$
|
||||
\item $\begin{aligned}[t]\Follow_k(x) := \{u \in (V \cup \Sigma)^+ | &\exists m, y \in (V \cup \Sigma)^* :\\
|
||||
&S \Rightarrow^* mxy\\
|
||||
\land &u \in \First_k(y)\}\end{aligned}$
|
||||
\end{defenum}
|
||||
\end{definition}
|
||||
|
||||
\begin{beispiel}[First- und Follow-Mengen\footnotemark]
|
||||
Sei $G = (\Sigma, V, P, E)$ mit
|
||||
\begin{align*}
|
||||
\Sigma &= \Set{+, *, (, )}\\
|
||||
V &= \Set{T, T', E, E', F}\\
|
||||
P &= \{ E \rightarrow T E'\\
|
||||
&\hphantom{= \{ } E' \rightarrow \varepsilon | +TE'\\
|
||||
&\hphantom{= \{ } T \rightarrow FT'\\
|
||||
&\hphantom{= \{ } T' \rightarrow \varepsilon | *FT'\\
|
||||
&\hphantom{= \{ } F \rightarrow \id | (E)\}
|
||||
\end{align*}
|
||||
|
||||
Dann gilt:
|
||||
\begin{bspenum}
|
||||
\item $\First(E) = \First(T) = \First(F) = \Set{\id, (\ )}$
|
||||
\item $\First(E') = \Set{\#, +}$
|
||||
\item $\First(T') = \Set{\#, *}$
|
||||
\item $\Follow(E) = \Follow(E') = \Set{\#, )}$
|
||||
\item $\Follow(T) = \Follow(T') = \Set{\#, ), +}$
|
||||
\item $\Follow(F) = \Set{\#, ), +, *}$
|
||||
\end{bspenum}
|
||||
\end{beispiel}
|
||||
\footnotetext{Folie 348}
|
||||
|
||||
\section{Literatur}
|
||||
Ich kann das folgende Buch empfehlen:
|
||||
|
||||
|
|
|
@ -172,9 +172,12 @@ Verteilt Daten vom Prozess \texttt{root} unter alle anderen Prozesse in der Grup
|
|||
\inputminted[numbersep=5pt, tabsize=4]{c}{scripts/mpi/mpi-reduce-example.c}
|
||||
|
||||
\section{Beispiele}
|
||||
|
||||
\subsection{sum-reduce Implementierung}
|
||||
\inputminted[numbersep=5pt, tabsize=4]{c}{scripts/mpi/mpi-sum-reduce.c}
|
||||
|
||||
\subsection[broadcast Implementierung]{broadcast Implementierung\footnote{Klausur WS 2012 / 2013}}
|
||||
\inputminted[numbersep=5pt, tabsize=4]{c}{scripts/mpi/mpi-mybroadcast.c}
|
||||
|
||||
\section{Weitere Informationen}
|
||||
\begin{itemize}
|
||||
\item \url{http://mpitutorial.com/}
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,18 @@
|
|||
void my_bcast(void* data, int count, MPI_Datatype type,
|
||||
int root, MPI_Comm comm) {
|
||||
int my_rank;
|
||||
MPI_Comm_rank(comm, &my_rank);
|
||||
int comm_size;
|
||||
MPI_Comm_size(comm, &comm_size);
|
||||
if (my_rank == root) {
|
||||
// If we are the root process, send our data to every one
|
||||
for (int i = 0; i < comm_size; i++) {
|
||||
if (i != my_rank) {
|
||||
MPI_Send(data, count, type, i, 0, comm);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If we are a receiver process, receive the data from root
|
||||
MPI_Recv(data, count, type, root, 0, comm, MPI_STATUS_IGNORE);
|
||||
}
|
||||
}
|
|
@ -83,6 +83,8 @@
|
|||
\DeclareMathOperator{\VAR}{VAR}
|
||||
\DeclareMathOperator{\CONST}{CONST}
|
||||
\DeclareMathOperator{\APP}{APP}
|
||||
\DeclareMathOperator{\First}{First}
|
||||
\DeclareMathOperator{\Follow}{Follow}
|
||||
\let\succ\relax% Set equal to \relax so that LaTeX thinks it's not defined
|
||||
\DeclareMathOperator{\succ}{succ}
|
||||
\newcommand{\iu}{{i\mkern1mu}} % imaginary unit
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue