coursework/cw02.tex
changeset 181 1f98d215df71
parent 180 50e8dcd95ae3
child 182 9ce2414e470e
equal deleted inserted replaced
180:50e8dcd95ae3 181:1f98d215df71
   109 \item numbers are \texttt{0}, \text{1}, \ldots
   109 \item numbers are \texttt{0}, \text{1}, \ldots
   110 \end{enumerate}
   110 \end{enumerate}
   111 
   111 
   112 \noindent
   112 \noindent
   113 Once you have implemented all regular expressions for 1 - 9, then
   113 Once you have implemented all regular expressions for 1 - 9, then
   114 give the token sequence for the Fibonacci program shown below.
   114 give the token sequence for the Fibonacci program shown below in Fig.~\ref{fib}.
   115 
   115 
   116 \subsection*{Question 2 (marked with 1\%)}
   116 \subsection*{Question 2 (marked with 1\%)}
   117 
   117 
   118 Implement parser combinators and an evaluation function for arithmetic and boolean
   118 Implement parser combinators and an evaluation function for arithmetic and boolean
   119 expressions.  Arithmetic operations should include \texttt{+}, \texttt{-}, \texttt{*} and 
   119 expressions.  Arithmetic operations should include \texttt{+}, \texttt{-}, \texttt{*} and 
   136 0 and a fixed number (say 100). Take the grammar of this language from the lectures. As another 
   136 0 and a fixed number (say 100). Take the grammar of this language from the lectures. As another 
   137 guidance have a look at the Fibonacci program
   137 guidance have a look at the Fibonacci program
   138 and ``three-nested-loops'' program shown below. For example, printing a variable \texttt{x} in the 
   138 and ``three-nested-loops'' program shown below. For example, printing a variable \texttt{x} in the 
   139 WHILE language can be done by using the command \mbox{\texttt{write x}}. 
   139 WHILE language can be done by using the command \mbox{\texttt{write x}}. 
   140 
   140 
   141 
   141 \begin{figure}[h]
   142 \begin{center}
   142 \begin{center}
   143 \mbox{\lstinputlisting[language=while]{../progs/fib.while}}
   143 \mbox{\lstinputlisting[language=while]{../progs/fib.while}}
   144 \end{center}
   144 \end{center}
       
   145 \caption{Fibonacci program in the WHILE language.\label{fib}}
       
   146 \end{figure}
   145 
   147 
       
   148 \begin{figure}[h]
   146 \begin{center}
   149 \begin{center}
   147 \mbox{\lstinputlisting[language=while]{../progs/loops.while}}
   150 \mbox{\lstinputlisting[language=while]{../progs/loops.while}}
   148 \end{center}
   151 \end{center}
   149 
   152 \caption{The three-nested-loops program in the WHILE language. Usually used for timing measurements.\label{loop}}
       
   153 \end{figure}
   150 
   154 
   151 \end{document}
   155 \end{document}
   152 
   156 
   153 %%% Local Variables: 
   157 %%% Local Variables: 
   154 %%% mode: latex
   158 %%% mode: latex