Binary file coursework/cw02.pdf has changed
--- a/coursework/cw02.tex Wed Oct 16 11:06:32 2019 +0100
+++ b/coursework/cw02.tex Wed Oct 16 11:14:53 2019 +0100
@@ -172,7 +172,7 @@
Extend your lexer from Q2 to also simplify regular expressions
after each derivation step and rectify the computed values after each
injection. Use this lexer to tokenize the programs in
-Figure~\ref{fib} and \ref{loop}. Give the tokens of these
+Figure~\ref{fib}, \ref{loop} and \ref{factor}. Give the tokens of these
programs where whitespaces are filtered out. Make sure you can
tokenise \textbf{exactly} these programs.\bigskip
@@ -188,6 +188,12 @@
(Usually used for timing measurements.)\label{loop}}
\end{figure}
+\begin{figure}[h]
+\mbox{\lstinputlisting[language=While,xleftmargin=10mm]{../progs/factors.while}}
+\caption{A program that calculates factors for numbers in the WHILE
+ language.\label{factors}}
+\end{figure}
+
\end{document}
%%% Local Variables:
--- a/progs/factors.while Wed Oct 16 11:06:32 2019 +0100
+++ b/progs/factors.while Wed Oct 16 11:14:53 2019 +0100
@@ -1,14 +1,14 @@
-// Find all factors of a given input number - J.R. Cordy August 2005
-var n;
+// Find all factors of a given input number
+// by J.R. Cordy August 2005
+
write "Input n please";
read n;
write "The factors of n are";
-var f;
f := 2;
-while n != 1 do
- while (n / f) * f = n do
+while n != 1 do {
+ while (n / f) * f == n do {
write f;
- n := n / f;
- end
- f := f + 1;
-end
\ No newline at end of file
+ n := n / f
+ };
+ f := f + 1
+}
\ No newline at end of file