Als we de analyse op een compleet programma toepassen komt er een \textit{Piet}
programma uit dat behoorlijk fors is maar netjes zijn werk doet. Dit programma
berekent de faculteit van $x$ en stopt dat uiteindelijk in $y$.
-\begin{lstlisting}[
- mathescape=true,
- basicstyle=\scriptsize,
- keepspaces=true,
- columns=flexible,
- numbers=left,
- numbersep=2pt,
- title=Faculteit in \textit{While},
- ]
+\begin{lstlisting}[title=Faculteit in \textit{While}]
x:=5;
y:=1;
while $\neg$(x=1)
do (
- y:=y*x;
- x:=x-1
+ y:=y*x;
+ x:=x-1
)
\end{lstlisting}
-In piet ziet dit er als volgt uit...
+In \textit{Piet} ziet dit er als volgt uit...
+\begin{lstlisting}[title=Faculteit in \textit{Piet'}]
+push 5 // x:=5
+push 1 // y:=1
+
+MARKERING A:
+ // Un(2)
+ // $\neg$(x=1) $\equiv$ \neg(x-1)>0)
+
+
+ // x-1
+ // Un(2)
+push 2 //
+push 1 //
+roll //
+dup //
+push 3 //
+push 1 //
+roll //
+push 1 //
+sub //
+not // $\neg(x-1)$
+
+push 1 // zet $0$ op de stack
+push 1
+sub
+
+gre // $\neg(x-1)>0$ oftewel x=1
+
+pointer // als x=0 dan draait de DP niet en gaat het programma naar pad B
+ // als x$\neq$ dan draait de DP en gaat het programma naar pad A
+
+PAD A:
+skip // een oneindig aantal witte blokken, y is nu x!
+ // evt een outchar om $y$ naar standardout te printen
+
+PAD B:
+ // y:=y*x
+ // Bin(1, 2)
+dup // Un(1)
+push 3 // Un(2+1)
+push 2 //
+roll //
+dup //
+push 4 //
+push 1 //
+roll //
+mul // x*y
+push 3 // Ass(2)
+push 2
+roll
+pop
+push 2
+push 1
+roll
+ // x:=x-1
+push 2 // Un(2)
+push 1
+roll
+dup
+push 3
+push 1
+roll
+
+
+push 1 //
+sub // x-1
+push 3 // Ass(2)
+push 1
+roll
+pop
+ // nu gaat het programma weer via een wit pad naar markering A
+\end{lstlisting}