cws/cw04.tex
changeset 986 68b1a84efce6
parent 974 0cb4bf2469d1
equal deleted inserted replaced
985:c7e944977e39 986:68b1a84efce6
    17 at 16:00. You are asked to implement a compiler for
    17 at 16:00. You are asked to implement a compiler for
    18 the WHILE language that targets the assembler language
    18 the WHILE language that targets the assembler language
    19 provided by Jasmin or Krakatau (both have a very similar
    19 provided by Jasmin or Krakatau (both have a very similar
    20 syntax).  You can do the implementation in any programming
    20 syntax).  You can do the implementation in any programming
    21 language you like, but you need to submit the source code with
    21 language you like, but you need to submit the source code with
    22 which you answered the questions, otherwise a mark of 0\% will
    22 which you answered the tasks, otherwise a mark of 0\% will
    23 be awarded. You should use the lexer and parser from the
    23 be awarded. You should use the lexer and parser from the
    24 previous courseworks. Implement your compiler in the file \texttt{cw04.sc}.
    24 previous courseworks. Implement your compiler in the file \texttt{cw04.sc}.
    25 
    25 
    26 %Please package \emph{everything}(!) in
    26 %Please package \emph{everything}(!) in
    27 %a zip-file that creates a directory with the name
    27 %a zip-file that creates a directory with the name
   143 version---I assume it should produce the same output, but might be
   143 version---I assume it should produce the same output, but might be
   144 easier to install because it avoids Python's \emph{dependency hell}).
   144 easier to install because it avoids Python's \emph{dependency hell}).
   145 
   145 
   146 
   146 
   147 %\noindent You need to submit a document containing the answers
   147 %\noindent You need to submit a document containing the answers
   148 %for the two questions below. You can do the implementation in
   148 %for the two tasks below. You can do the implementation in
   149 %any programming language you like, but you need to submit the
   149 %any programming language you like, but you need to submit the
   150 %source code with which you answered the questions. Otherwise
   150 %source code with which you answered the tasks. Otherwise
   151 %the submission will not be counted. However, the coursework
   151 %the submission will not be counted. However, the coursework
   152 %will \emph{only} be judged according to the answers. You can
   152 %will \emph{only} be judged according to the answers. You can
   153 %submit your answers in a txt-file or as pdf.\bigskip
   153 %submit your answers in a txt-file or as pdf.\bigskip
   154 
   154 
   155 %\subsection*{Question 0 (Unmarked)}
   155 %\subsection*{Task 0 (Unmarked)}
   156 %
   156 %
   157 %Please include  in the PDF at the beginning your email address, your student
   157 %Please include  in the PDF at the beginning your email address, your student
   158 %number and whether you are BSc / MSci student and for the latter in which
   158 %number and whether you are BSc / MSci student and for the latter in which
   159 %year your are in. Thanks! 
   159 %year your are in. Thanks! 
   160 
   160 
   161 \subsection*{Question 1}
   161 \subsection*{Task 1}
   162 
   162 
   163 You need to lex and parse WHILE programs, and then generate Java Byte
   163 You need to lex and parse WHILE programs, and then generate Java Byte
   164 Code instructions for the Jasmin assembler (or Krakatau
   164 Code instructions for the Jasmin assembler (or Krakatau
   165 assembler). For this you should use the ASTs defined in CW3 (including
   165 assembler). For this you should use the ASTs defined in CW3 (including
   166 logical operators). As part of the solution you need to submit the assembler
   166 logical operators). As part of the solution you need to submit the assembler
   169 \begin{figure}[t]
   169 \begin{figure}[t]
   170 \lstinputlisting[language=while]{../cwtests/cw04/fib.while}
   170 \lstinputlisting[language=while]{../cwtests/cw04/fib.while}
   171 \caption{The Fibonacci program in the WHILE language.\label{fibs}}
   171 \caption{The Fibonacci program in the WHILE language.\label{fibs}}
   172 \end{figure}
   172 \end{figure}
   173 
   173 
   174 \subsection*{Question 2}
   174 \subsection*{Task 2}
   175 
   175 
   176 Extend the syntax of your language so that it contains also
   176 Extend the syntax of your language so that it contains also
   177 \texttt{for}-loops, like
   177 \texttt{for}-loops, like
   178 
   178 
   179 \begin{center}
   179 \begin{center}
   220 }
   220 }
   221 \end{lstlisting}
   221 \end{lstlisting}
   222 \end{minipage}
   222 \end{minipage}
   223 \end{center}
   223 \end{center}
   224 
   224 
   225 \subsection*{Question 3 (OPTIONAL)}
   225 \subsection*{Task 3 (OPTIONAL)}
   226 
   226 
   227 \noindent In this question you are asked to think about the following
   227 \noindent In this task you are asked to think about the following
   228 program:
   228 program:
   229 
   229 
   230 \begin{center}
   230 \begin{center}
   231 \begin{minipage}{12cm}
   231 \begin{minipage}{12cm}
   232 \begin{lstlisting}[language=While, numbers=none]
   232 \begin{lstlisting}[language=While, numbers=none]
   242 \noindent 
   242 \noindent 
   243 Note that in this program the variable \pcode{i} is used
   243 Note that in this program the variable \pcode{i} is used
   244 twice. Therefore you need to make a decision about how it should be compiled?
   244 twice. Therefore you need to make a decision about how it should be compiled?
   245 What should the program print?
   245 What should the program print?
   246 
   246 
   247 \subsection*{Question 4}
   247 \subsection*{Task 4}
   248 
   248 
   249 Extend the lexer and parser to add a \textcolor{codepurple}{\pcode{break}} keyword.  Modify
   249 Extend the lexer and parser to add a \textcolor{codepurple}{\pcode{break}} keyword.  Modify
   250 the compiler (including lexer and parser) such that when a \textcolor{codepurple}{\texttt{break}}-statement is encountered
   250 the compiler (including lexer and parser) such that when a \textcolor{codepurple}{\texttt{break}}-statement is encountered
   251 the code should jump out of the ``enclosing'' for/while-loop, or in case it
   251 the code should jump out of the ``enclosing'' for/while-loop, or in case it
   252 is not inside such a loop to the end of the program. For example the
   252 is not inside such a loop to the end of the program. For example the
   279 should print out 0 to 10 with the first for-loop, but only 0
   279 should print out 0 to 10 with the first for-loop, but only 0
   280 to 4 in the second. Similarly it should print out \code{"Should print"},
   280 to 4 in the second. Similarly it should print out \code{"Should print"},
   281 but not \code{"Should not print"}. For this you need to add
   281 but not \code{"Should not print"}. For this you need to add
   282 a label to the end of every for- and while-loop and also to the end of the
   282 a label to the end of every for- and while-loop and also to the end of the
   283 whole program just in case you need to jump to that label via a
   283 whole program just in case you need to jump to that label via a
   284 \code{break}. The file you need to be able to process for this question
   284 \code{break}. The file you need to be able to process for this task
   285 is called \texttt{break.while}.
   285 is called \texttt{break.while}.
   286 
   286 
   287 
   287 
   288 \subsection*{Further Information}
   288 \subsection*{Further Information}
   289 
   289