cws/cw03.tex
changeset 950 fa97d2f60f11
parent 943 5365ef60707e
child 956 ae9782e62bdd
equal deleted inserted replaced
949:61797848eede 950:fa97d2f60f11
     1 % !TEX program = xelatex
     1 % !TEX program = xelatex
     2 \documentclass{article}
     2 \documentclass{article}
     3 \usepackage{../style}
     3 \usepackage{../style}
     4 \usepackage{../langs}
     4 \usepackage{../langs}
       
     5 \usepackage[normalem]{ulem}
     5 
     6 
     6 \begin{document}
     7 \begin{document}
     7 
     8 
     8 \section*{Coursework 3}
     9 \section*{Coursework 3}
     9 
    10 
   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 
   163 
   203 
   164 \clearpage
   204 \clearpage
   165 \newpage
   205 \newpage
   166 \section*{Answers}
   206 \section*{Answers}
   167 
   207 
       
   208 \mbox{}  
       
   209 
       
   210 \noindent
       
   211 \textbf{Name:}\uline{\hfill}\bigskip
       
   212 
       
   213 
       
   214 
   168 \noindent
   215 \noindent
   169 \textbf{Question 1 (Grammar):}\\
   216 \textbf{Question 1 (Grammar):}\\
   170 
   217 
   171 \mbox{}\\[9cm]
   218 \mbox{}\\[9cm]
   172 
   219 
   173 \noindent
   220 \newpage
   174 \textbf{Question 2 (Prase Tree):}\\
   221 \noindent
       
   222 \textbf{Question 2 (Parse Tree):}\\
   175 
   223 
   176 \mbox{}\\[8cm]
   224 \mbox{}\\[8cm]
   177 
   225 
   178 
   226 
   179 \noindent
   227 \noindent