Binary file cws/cw03.pdf has changed
--- a/cws/cw03.tex Fri Nov 24 08:58:11 2017 +0000
+++ b/cws/cw03.tex Fri Nov 24 09:10:53 2017 +0000
@@ -421,16 +421,16 @@
integers to integers. The empty memory is represented by
\texttt{Map()}, that is nothing is stored in the
memory. \texttt{Map(0 -> 1, 2 -> 3)} clearly has stored \texttt{1}
- at memory location \texttt{0}, at \texttt{2} it stores
+ at memory location \texttt{0}; at \texttt{2} it stores
\texttt{3}. The convention is that if we query the memory at a
- location that is not defined in the \texttt{Map} we return
+ location that is not defined in the \texttt{Map}, we return
\texttt{0}. Write a function, \texttt{sread}, that takes a memory (a
\texttt{Map}) and a memory pointer (an \texttt{Int}) as argument,
and safely reads the corresponding memory location. If the map is not
- defined at the memory pointer it returns \texttt{0}.
+ defined at the memory pointer, \texttt{sread} returns \texttt{0}.
Write another function \texttt{write}, which takes a memory, a
- memory pointer and a integer value as argument and updates the map
+ memory pointer and an integer value as argument and updates the map
with the value at the given memory location. As usual the map is not
updated `in-place' but a new map is created with the same data,
except the value is stored at the given memory pointer.\hfill[1 Mark]
@@ -454,7 +454,7 @@
\texttt{--[..+>--]\barbelow{,}>,++}
\end{center}
- meaning it jumps after the loop. Similarly, if you in 8th position
+ meaning it jumps to after the loop. Similarly, if you in 8th position
then \texttt{jumpLeft} is supposed to jump to just after the opening
bracket (that is jumping to the beginning of the loop):
@@ -465,7 +465,7 @@
\end{center}
Unfortunately we have to take into account that there might be
- another opening and closing bracket on the `way' to find the
+ other opening and closing brackets on the `way' to find the
matching bracket. For example in the brainf*** program
\begin{center}
@@ -474,8 +474,8 @@
we do not want to return the index for the \texttt{'-'} in the 9th
position, but the program counter for \texttt{','} in 12th
- position. The easiest to find out whether a bracket is matched is to
- use levels (which are the third argument in \texttt{jumpLeft} and
+ position. The easiest to find out whether a bracket is matched is by
+ using levels (which are the third argument in \texttt{jumpLeft} and
\texttt{jumpLeft}). In case of \texttt{jumpRight} you increase the
level by one whenever you find an opening bracket and decrease by
one for a closing bracket. Then in \texttt{jumpRight} you are looking
@@ -507,16 +507,16 @@
\item[(2c)] Write a recursive function \texttt{run} that executes a
brainf*** program. It takes a program, a program counter, a memory
- counter and a memory as arguments. If the program counter is outside
+ pointer and a memory as arguments. If the program counter is outside
the program string, the execution stops and \texttt{run} returns the
memory. If the program counter is inside the string, it reads the
- corresponding character and updates the program counter \texttt{pc}, memory
- pointer \texttt{mp} and memory \texttt{mem} according to the rules shown
- in Figure~\ref{comms}. It the calls recursively \texttt{run} with the updated
- data.
+ corresponding character and updates the program counter \texttt{pc},
+ memory pointer \texttt{mp} and memory \texttt{mem} according to the
+ rules shown in Figure~\ref{comms}. It then calls recursively
+ \texttt{run} with the updated data.
Write another function \texttt{start} that calls \texttt{run} with a
- given brainfu** program and memory, and the program counter and memory counter
+ given brainfu** program and memory, and the program counter and memory pointer
set to~$0$. Like \texttt{run} it returns the memory after the execution
of the program finishes. You can test your brainf**k interpreter with the
Sierpinski triangle or the Hello world programs or have a look at
@@ -584,8 +584,8 @@
\hline
\end{tabular}
\end{center}
- \caption{The rules for how commands in the brainf*** language update the program counter,
- memory counter and memory.\label{comms}}
+ \caption{The rules for how commands in the brainf*** language update the program counter \texttt{pc},
+ memory pointer \texttt{mp} and memory \texttt{mem}.\label{comms}}
\end{figure}
\end{itemize}\bigskip