coursework/cw02.tex
changeset 180 50e8dcd95ae3
parent 179 d575895689b5
child 181 1f98d215df71
--- a/coursework/cw02.tex	Sun Nov 03 00:45:49 2013 +0000
+++ b/coursework/cw02.tex	Sun Nov 03 11:10:07 2013 +0100
@@ -62,53 +62,64 @@
 
 \section*{Coursework 2}
 
-This coursework is worth 3\% and is due on 26 November at 16:00. You are asked to implement 
-a tokeniser for the WHILE language,  an evaluator for boolean and arithmetic expressions and
-a WHILE program for printing prime numbers.
+This coursework is worth 3\% and is due on 27 November at 16:00. You are asked to 
 
+\begin{enumerate}
+\item implement a tokeniser for the WHILE language,
+\item implement a parser and an evaluator for boolean and arithmetic expressions, and
+\item write a WHILE program for printing out prime numbers.
+\end{enumerate}
+
+\noindent
 You need to submit a document containing the answers for the questions 
 below. You can do the implementation in any programming language you like, but you need 
 to submit the source code with which you answered the questions. However, the coursework 
 will \emph{only} be judged according to the answers. You can submit your answers
-in a txt-file or pdf.\bigskip
+in a txt-file or as pdf.\bigskip
 
 
 \subsection*{Question 1 (marked with 1\%)}
 
-Implement a tokeniser for the WHILE language. (1) Keywords in this language
-are
+Implement a tokeniser for the WHILE language. You first need to design the appropriate
+regular expressions for the following nine syntactic entities:
 
-\begin{center}
+\begin{enumerate}
+\item keywords are
+
+\begin{quote}
 \texttt{while}, \texttt{if}, \texttt{then}, \texttt{else}, \texttt{do}, \texttt{for}, \texttt{to}, \texttt{true}, \texttt{false}
 \texttt{andalso}, \texttt{orelse}, \texttt{read}, \texttt{write}
-\end{center} 
+\end{quote} 
+
+\item operators are
+
+\begin{quote}
+\texttt{+}, \texttt{-}, \texttt{*}, \texttt{\%}, \texttt{==}, \texttt{!=}, \texttt{>}, \texttt{<}, \texttt{:=}
+\end{quote} 
+
+\item strings are enclosed by \texttt{"\ldots"} 
+\item parentheses are \texttt{(}, \texttt{\{}, \texttt{)} and \texttt{\}}
+\item there are semicolons \texttt{;}
+\item whitespaces are either \texttt{" "} or \texttt{$\backslash$n}
+\item comments either start with $\backslash\,\backslash$ and run to the end of the corresponding line 
+(indicated by \texttt{$\backslash$n}), or they can also run over several lines but then need to be enclosed by
+$\slash\texttt{*}$ as the beginning marker and $\texttt{*}\slash{}$\smallskip as the end marker
+\item identifiers are letters followed by underscores \texttt{\_\!\_}, letters
+or digits
+\item numbers are \texttt{0}, \text{1}, \ldots
+\end{enumerate}
 
 \noindent
-(2) Operators are
-
-\begin{center}
-\texttt{+}, \texttt{-}, \texttt{*}, \texttt{\%}, \texttt{==}, \texttt{!=}, \texttt{>}, \texttt{<}, \texttt{:=}
-\end{center} 
-
-\noindent
-(3) Strings are enclosed in \texttt{"\ldots"}, (4) you have parentheses \texttt{(}, \texttt{\{}, \texttt{)}, and \texttt{\}},
-(5) there are semicolons \texttt{;}, (6) whitespaces are either \texttt{" "} or \texttt{$\backslash$n},
-(7) comments either start with $\backslash\,\backslash$ and run to the end of the corresponding line 
-(\texttt{$\backslash$n}), comments can also been given by looking for $\slash\texttt{*}$ as the
-beginning marker and $\texttt{*}\slash{}$\smallskip as the end marker.
-
-\noindent
-(8) Identifiers are letters followed by underscores \texttt{\_}, letters
-or digits. (9) There are also numbers, like \texttt{0}, \text{1}, \ldots.\medskip
-
-Once you have implemented all regular expressions for (1) - (9), then
+Once you have implemented all regular expressions for 1 - 9, then
 give the token sequence for the Fibonacci program shown below.
 
 \subsection*{Question 2 (marked with 1\%)}
 
-Implement parser combinators and an evaluate function for arithmetic and boolean
-expressions.  Arithmetic operations should include $+$, $-$, $*$, $\%$ (quotient). Boolean
-operations should include $==$ (equal), $!=$ (unequal), $<$, $>$.
+Implement parser combinators and an evaluation function for arithmetic and boolean
+expressions.  Arithmetic operations should include \texttt{+}, \texttt{-}, \texttt{*} and 
+\texttt{\%} (quotient). Boolean
+operations should include \texttt{==} (equal), \texttt{!=} (unequal), \texttt{<} and  
+\texttt{>}.
  
 Using the parser and evaluation function, calculate the values for
 
@@ -122,8 +133,10 @@
 \subsection*{Question 3 (marked with 1\%)}
 
 Write a program in the WHILE programming language that prints out all prime numbers between
-0 and a fixed number (say 100). As a guidance have a look at the Fibonacci program
-and three nested loops program shown below.
+0 and a fixed number (say 100). Take the grammar of this language from the lectures. As another 
+guidance have a look at the Fibonacci program
+and ``three-nested-loops'' program shown below. For example, printing a variable \texttt{x} in the 
+WHILE language can be done by using the command \mbox{\texttt{write x}}. 
 
 
 \begin{center}