diff -r c813506e0ee8 -r 180cbfc1520a coursework/cw03.tex --- a/coursework/cw03.tex Sat Nov 23 09:17:59 2013 +0000 +++ b/coursework/cw03.tex Sat Nov 23 11:09:27 2013 +0000 @@ -97,7 +97,7 @@ in a txt-file or as pdf.\bigskip -\subsection*{Question 1 (marked with 1\%)} +\subsection*{Question 1 (marked with 2\%)} You need to lex and parse WHILE programs and submit the assembler instructions for the Fibonacci program and for the program you submitted @@ -113,6 +113,32 @@ \texttt{for} \;\textit{Id} \texttt{:=} \textit{AExp}\; \texttt{upto} \;\textit{AExp}\; \texttt{do} \textit{Block} \end{center} +\noindent +The intended meaning is to first assign the variable \textit{Id} the value of the first arithmetic +expression, then go through the loop, at the end increase the value of the variable by 1, +and finally test wether the value is not less or equal anymore to the value of the second +arithmetic expression. For example the following instance of a \texttt{for}-loop +is supposed to print out the numbers \texttt{2}, \texttt{3}, \texttt{4}. + + +\begin{center} +\begin{minipage}{6cm} +\begin{lstlisting}[language=While,basicstyle=\ttfamily, numbers=none] +for i := 2 upto 4 do { + write i +} +\end{lstlisting} +\end{minipage} +\end{center} + +\noindent +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). + + + \end{document} %%% Local Variables: