126 lines 7 and 8. The program should be interpreted |
127 lines 7 and 8. The program should be interpreted |
127 according to straightforward rules: for example an |
128 according to straightforward rules: for example an |
128 if-statement will ``run'' the if-branch if the boolean |
129 if-statement will ``run'' the if-branch if the boolean |
129 evaluates to \pcode{true}, otherwise the else-branch. |
130 evaluates to \pcode{true}, otherwise the else-branch. |
130 Loops should be run as long as the boolean is \pcode{true}. |
131 Loops should be run as long as the boolean is \pcode{true}. |
|
132 Note also that some programs contain a read-statement, |
|
133 which means you need to read and integer from the commandline |
|
134 and store the value in the corresponding variable. |
131 Programs you should be able to run are shown in |
135 Programs you should be able to run are shown in |
132 Figures \ref{fib} -- \ref{collatz}. |
136 Figures \ref{fib} -- \ref{collatz}. The output |
133 |
137 of the \texttt{primes.while} should look as follows: |
134 |
138 |
|
139 \begin{figure}[h] |
|
140 {\small |
|
141 \begin{lstlisting}[numbers=none] |
|
142 2 |
|
143 3 |
|
144 5 |
|
145 7 |
|
146 11 |
|
147 13 |
|
148 17 |
|
149 19 |
|
150 23 |
|
151 29 |
|
152 31 |
|
153 37 |
|
154 41 |
|
155 43 |
|
156 47 |
|
157 53 |
|
158 59 |
|
159 61 |
|
160 67 |
|
161 71 |
|
162 73 |
|
163 79 |
|
164 83 |
|
165 89 |
|
166 97 |
|
167 Map(end -> 100, n -> 100, f -> 4, tmp -> 1) |
|
168 \end{lstlisting}} |
|
169 \caption{Sample output for the file \texttt{primes.while}.\label{fib}} |
|
170 \end{figure} |
|
171 |
|
172 \noindent |
135 Give some time measurements for your interpreter |
173 Give some time measurements for your interpreter |
136 and the loop program in Figure~\ref{loop}. For example |
174 and the loop program in Figure~\ref{loop}. For example |
137 how long does your interpreter take when \pcode{start} |
175 how long does your interpreter take when \pcode{start} |
138 is initialised with 100, 500 and so on. How far can |
176 is initialised with 100, 500 and so on. How far can |
139 you scale this value if you are willing to wait, say |
177 you scale this value if you are willing to wait, say |
140 1 Minute? |
178 1 Minute? |
141 |
179 |
|
180 \clearpage |
|
181 |
142 \begin{figure}[h] |
182 \begin{figure}[h] |
143 \lstinputlisting[language=while,xleftmargin=20mm]{../cwtests/cw03/fib.while} |
183 \lstinputlisting[language=while,xleftmargin=20mm]{../cwtests/cw03/fib.while} |
144 \caption{Fibonacci program in the WHILE language.\label{fib}} |
184 \caption{Fibonacci program in the WHILE language.\label{fib}} |
145 \end{figure} |
185 \end{figure} |
146 |
186 |