cws/cw04.tex
changeset 920 7af2eea19646
parent 910 b655ce68983f
child 943 5365ef60707e
equal deleted inserted replaced
919:53f08d873e09 920:7af2eea19646
    20 syntax). Please submit your answers to the questions
    20 syntax). Please submit your answers to the questions
    21 below as PDF. You can do the implementation in any programming
    21 below as PDF. You can do the implementation in any programming
    22 language you like, but you need to submit the source code with
    22 language you like, but you need to submit the source code with
    23 which you answered the questions, otherwise a mark of 0\% will
    23 which you answered the questions, otherwise a mark of 0\% will
    24 be awarded. You should use the lexer and parser from the
    24 be awarded. You should use the lexer and parser from the
    25 previous courseworks. Please package \emph{everything}(!) in
    25 previous courseworks.
    26 a zip-file that creates a directory with the name
    26 
    27 \texttt{YournameYourFamilyname} on my end.
    27 %Please package \emph{everything}(!) in
       
    28 %a zip-file that creates a directory with the name
       
    29 %\texttt{YournameYourFamilyname} on my end.
    28 
    30 
    29 \subsection*{Disclaimer\alert}
    31 \subsection*{Disclaimer\alert}
    30 
    32 
    31 It should be understood that the work you submit represents
    33 It should be understood that the work you submit represents
    32 your own effort. You have not copied from anyone else. An
    34 your own effort. You have not copied from anyone else. An
   133 %source code with which you answered the questions. Otherwise
   135 %source code with which you answered the questions. Otherwise
   134 %the submission will not be counted. However, the coursework
   136 %the submission will not be counted. However, the coursework
   135 %will \emph{only} be judged according to the answers. You can
   137 %will \emph{only} be judged according to the answers. You can
   136 %submit your answers in a txt-file or as pdf.\bigskip
   138 %submit your answers in a txt-file or as pdf.\bigskip
   137 
   139 
   138 \subsection*{Question 0 (Unmarked)}
   140 %\subsection*{Question 0 (Unmarked)}
   139 
   141 %
   140 Please include  in the PDF at the beginning your email address, your student
   142 %Please include  in the PDF at the beginning your email address, your student
   141 number and whether you are BSc / MSci student and for the latter in which
   143 %number and whether you are BSc / MSci student and for the latter in which
   142 year your are in. Thanks! 
   144 %year your are in. Thanks! 
   143 
   145 
   144 \subsection*{Question 1}
   146 \subsection*{Question 1}
   145 
   147 
   146 You need to lex and parse WHILE programs, and then generate
   148 You need to lex and parse WHILE programs, and then generate
   147 Java Byte Code instructions for the Jasmin assembler (or
   149 Java Byte Code instructions for the Jasmin assembler (or
   231 Note that in this program the variable \pcode{i} is used
   233 Note that in this program the variable \pcode{i} is used
   232 twice. You need to make a decision how it should be compiled?
   234 twice. You need to make a decision how it should be compiled?
   233 Explain your decision and indicate what this program would
   235 Explain your decision and indicate what this program would
   234 print out.
   236 print out.
   235 
   237 
   236 \subsection*{Question 4 (Advanced)}
   238 \subsection*{Question 4}
   237 
   239 
   238 Extend the lexer and parser in order to add a \texttt{break} keyword.
   240 Extend the lexer and parser to add a \texttt{break} keyword.  Modify
   239 Modify the compiler such that when a \texttt{break} is encountered the
   241 the compiler such that when a \texttt{break}-statement is encountered
   240 code should jump out of the ``enclosing'' while loop, or in case it
   242 the code should jump out of the ``enclosing'' for-loop, or in case it
   241 is not inside a while loop to the end of the
   243 is not inside a for-loop to the end of the program. For example the
   242 program.
   244 program
   243 
   245 
   244 \bigskip\noindent
   246 \begin{center}
   245 \textcolor{red}{ADD EXAMPLE PROGRAMS}
   247 \begin{minipage}{12cm}
       
   248 \begin{lstlisting}[language=While, numbers=none]
       
   249 for i := 0 upto 10 do {
       
   250   write i;
       
   251   write "\n"
       
   252 };
       
   253 
       
   254 for i := 0 upto 10 do {
       
   255   if i > 4 then break else skip;
       
   256   write i;
       
   257   write "\n"
       
   258 };
       
   259 
       
   260 write "Should print\n";
       
   261 break;
       
   262 write "Should not print\n"
       
   263 \end{lstlisting}
       
   264 \end{minipage}
       
   265 \end{center}
       
   266 
       
   267 \noindent
       
   268 should print out 1 to 10 with the first for-loop, but only 1
       
   269 to 4 in the second. Similarly it should print out \code{"Should print"},
       
   270 but not \code{"Should not print"}. For this you need to add
       
   271 a label to the end of every for-loop and also to the end of the
       
   272 whole program just in case you need to jump to that label via a
       
   273 \code{break}.
       
   274 
   246 
   275 
   247 \subsection*{Further Information}
   276 \subsection*{Further Information}
   248 
   277 
   249 The Java infrastructure unfortunately does not contain an
   278 The Java infrastructure unfortunately does not contain an
   250 assembler out-of-the-box (therefore you need to download the
   279 assembler out-of-the-box (therefore you need to download the