cws/cw04.tex
changeset 920 7af2eea19646
parent 910 b655ce68983f
child 943 5365ef60707e
--- a/cws/cw04.tex	Sun Sep 17 19:12:57 2023 +0100
+++ b/cws/cw04.tex	Tue Sep 19 09:54:41 2023 +0100
@@ -22,9 +22,11 @@
 language you like, but you need to submit the source code with
 which you answered the questions, otherwise a mark of 0\% will
 be awarded. You should use the lexer and parser from the
-previous courseworks. Please package \emph{everything}(!) in
-a zip-file that creates a directory with the name
-\texttt{YournameYourFamilyname} on my end.
+previous courseworks.
+
+%Please package \emph{everything}(!) in
+%a zip-file that creates a directory with the name
+%\texttt{YournameYourFamilyname} on my end.
 
 \subsection*{Disclaimer\alert}
 
@@ -135,11 +137,11 @@
 %will \emph{only} be judged according to the answers. You can
 %submit your answers in a txt-file or as pdf.\bigskip
 
-\subsection*{Question 0 (Unmarked)}
-
-Please include  in the PDF at the beginning your email address, your student
-number and whether you are BSc / MSci student and for the latter in which
-year your are in. Thanks! 
+%\subsection*{Question 0 (Unmarked)}
+%
+%Please include  in the PDF at the beginning your email address, your student
+%number and whether you are BSc / MSci student and for the latter in which
+%year your are in. Thanks! 
 
 \subsection*{Question 1}
 
@@ -233,16 +235,43 @@
 Explain your decision and indicate what this program would
 print out.
 
-\subsection*{Question 4 (Advanced)}
+\subsection*{Question 4}
+
+Extend the lexer and parser to add a \texttt{break} keyword.  Modify
+the compiler such that when a \texttt{break}-statement is encountered
+the code should jump out of the ``enclosing'' for-loop, or in case it
+is not inside a for-loop to the end of the program. For example the
+program
+
+\begin{center}
+\begin{minipage}{12cm}
+\begin{lstlisting}[language=While, numbers=none]
+for i := 0 upto 10 do {
+  write i;
+  write "\n"
+};
 
-Extend the lexer and parser in order to add a \texttt{break} keyword.
-Modify the compiler such that when a \texttt{break} is encountered the
-code should jump out of the ``enclosing'' while loop, or in case it
-is not inside a while loop to the end of the
-program.
+for i := 0 upto 10 do {
+  if i > 4 then break else skip;
+  write i;
+  write "\n"
+};
 
-\bigskip\noindent
-\textcolor{red}{ADD EXAMPLE PROGRAMS}
+write "Should print\n";
+break;
+write "Should not print\n"
+\end{lstlisting}
+\end{minipage}
+\end{center}
+
+\noindent
+should print out 1 to 10 with the first for-loop, but only 1
+to 4 in the second. Similarly it should print out \code{"Should print"},
+but not \code{"Should not print"}. For this you need to add
+a label to the end of every for-loop and also to the end of the
+whole program just in case you need to jump to that label via a
+\code{break}.
+
 
 \subsection*{Further Information}