Binary file coursework/cw03.pdf has changed
--- a/coursework/cw03.tex Sat Nov 23 11:09:27 2013 +0000
+++ b/coursework/cw03.tex Sat Nov 23 11:16:35 2013 +0000
@@ -33,7 +33,7 @@
}
\lstdefinelanguage{while}{
- morekeywords={while, if, then. else, read, write},
+ morekeywords={while, if, then. else, read, write, for, upto, do},
otherkeywords={=>,<-,<\%,<:,>:,\#,@},
sensitive=true,
morecomment=[l]{//},
@@ -135,7 +135,20 @@
There are two ways how this can be implemented: one is to adapt the code generation
part of the compiler and generate specific code for \texttt{for}-loops; the other is to
translate the abstract syntax tree of \texttt{for}-loops into an abstract syntax tree using
-existing language constructs (for example while loops).
+existing language constructs. For example the loop above could be translated
+to the following \texttt{while}-loop:
+
+\begin{center}
+\begin{minipage}{6cm}
+\begin{lstlisting}[language=While,basicstyle=\ttfamily, numbers=none]
+i := 2;
+while (i <= 4) do {
+ write i;
+ i := i + 1;
+}
+\end{lstlisting}
+\end{minipage}
+\end{center}