updated
authorChristian Urban <christian.urban@kcl.ac.uk>
Wed, 17 Sep 2025 15:11:48 +0100
changeset 986 68b1a84efce6
parent 985 c7e944977e39
child 987 ad5ad452223c
updated
cws/cw01.pdf
cws/cw01.tex
cws/cw02.pdf
cws/cw02.tex
cws/cw03.pdf
cws/cw03.tex
cws/cw04.pdf
cws/cw04.tex
cws/cw05.pdf
Binary file cws/cw01.pdf has changed
--- a/cws/cw01.tex	Wed Sep 17 14:29:52 2025 +0100
+++ b/cws/cw01.tex	Wed Sep 17 15:11:48 2025 +0100
@@ -81,13 +81,13 @@
   \code{RANGE}, \code{PLUS}, \code{OPTIONAL}, \code{INTER}, \code{NTIMES},
   \code{UPTO}, \code{FROM} and \code{BETWEEN}.} 
   That means do not treat the extended regular expressions
-by just translating them into the basic ones. See also Question 1,
+by just translating them into the basic ones. See also Task 1,
 where you are asked to explicitly give the rules for \textit{nullable}
 and \textit{der} for the extended regular expressions. Something like
 
 \[der\,c\,(r^+) \dn der\,c\,(r\cdot r^*)\]
 
-\noindent is \emph{not} allowed as answer in Question 1 and \emph{not}
+\noindent is \emph{not} allowed as answer in Task 1 and \emph{not}
 allowed in your code.\medskip
 
 \noindent
@@ -116,7 +116,7 @@
 \noindent
 Be careful that your implementation of \textit{nullable} and
 \textit{der} satisfies for every regular expression $r$ the following
-two properties (see also Question 1):
+two properties (see also Task 1):
 
 \begin{itemize}
 \item $\textit{nullable}(r)$ if and only if $[]\in L(r)$
@@ -139,7 +139,7 @@
 %at least a good working day fiddling with a program)?  This is just
 %for my curiosity to estimate what your background is.
 
-\subsection*{Question 1}
+\subsection*{Task 1}
 
 From the lectures you have seen the definitions for the functions
 \textit{nullable} and \textit{der} for the basic regular
@@ -179,7 +179,7 @@
 Does your matcher produce the expected results? Make sure you
 also test corner-cases, like $a^{\{0\}}$!
 
-\subsection*{Question 2}
+\subsection*{Task 2}
 
 As you can see, there are a number of explicit regular expressions
 that deal with single or several characters, for example:
@@ -229,12 +229,12 @@
 
 \noindent
 You can either add the constructor $CFUN$ to your implementation in
-Question 3, or you can implement this questions first
-and then use $CFUN$ instead of \code{RANGE} and \code{CHAR} in Question 3.
+Task 3, or you can implement this questions first
+and then use $CFUN$ instead of \code{RANGE} and \code{CHAR} in Task 3.
 In an ideal world one would do this task first, but this might confuse
 you with what you need to do in the previous question.
 
-\subsection*{Question 3}
+\subsection*{Task 3}
 
 Suppose $[a\mbox{-}z0\mbox{-}9\_\,.\mbox{-}]$ stands for the regular expression
 
@@ -270,7 +270,7 @@
 instead of raw code.\bigskip
 
 
-\subsection*{Question 4}
+\subsection*{Task 4}
 
 Implement the simplification rules in your regular expression matcher.
 Consider the regular expression $/ \cdot * \cdot
@@ -285,7 +285,7 @@
 \item \texttt{"/*test/*test*/"}
 \end{enumerate}
 
-\subsection*{Question 5}
+\subsection*{Task 5}
 
 Let $r_1$ be the regular expression $a\cdot a\cdot a$ and $r_2$ be
 $(a^{\{19,19\}}) \cdot (a^?)$.\medskip
@@ -338,7 +338,7 @@
 \uline{\hfill}\bigskip\bigskip
 
 \noindent
-\textbf{Question 1:}
+\textbf{Task 1:}
 
 \begin{center}
 \def\arraystretch{1.6}  
@@ -378,7 +378,7 @@
 
 
 \noindent
-\textbf{Question 2:}
+\textbf{Task 2:}
 
 \begin{center}
 \def\arraystretch{1.6}    
@@ -398,7 +398,7 @@
 \newpage
 
 \noindent
-\textbf{Question 3 (`mathematical' notation):}
+\textbf{Task 3 (`mathematical' notation):}
 
 \noindent
 \uline{\hfill}\medskip
@@ -416,7 +416,7 @@
 \uline{\hfill}\bigskip\bigskip
 
 \noindent
-\textbf{Question 4:}\medskip
+\textbf{Task 4:}\medskip
 
 \noindent
 \textbf{1)}\; Yes / No\qquad
@@ -426,7 +426,7 @@
 
 
 \noindent
-\textbf{Question 5:}\medskip
+\textbf{Task 5:}\medskip
 
 \def\arraystretch{1.5}
 \begin{tabular}{l|c|c}
Binary file cws/cw02.pdf has changed
--- a/cws/cw02.tex	Wed Sep 17 14:29:52 2025 +0100
+++ b/cws/cw02.tex	Wed Sep 17 15:11:48 2025 +0100
@@ -44,7 +44,7 @@
 %be tempted to ask Github Copilot for help or do any other
 %shenanigans like this!
 
-\subsection*{Question 1}
+\subsection*{Task 1}
 
 To implement a lexer for the WHILE language, you first
 need to design the appropriate regular expressions for the
@@ -146,7 +146,7 @@
 for identifiers and numbers. Feel free to use the general
 character constructor \textit{CFUN} introduced in CW 1.
 
-\subsection*{Question 2}
+\subsection*{Task 2}
 
 Implement the Sulzmann \& Lu lexer from the lectures. For
 this you need to implement the functions $nullable$ and $der$
@@ -191,7 +191,7 @@
 lectures to your lexer and complete the function
 \pcode{env} so that it returns all assignments from a value (this then 
 allows you to extract easily the tokens from a value in the next
-question).\medskip 
+task).\medskip 
 
 \noindent
 Finally make that the function \texttt{lexing\_simp} generates
@@ -212,7 +212,7 @@
 
 
 
-\subsection*{Question 3}
+\subsection*{Task 3}
 
 Make sure your lexer from Q2 also simplifies regular expressions after
 each derivation step and rectifies the computed values after each
@@ -251,7 +251,7 @@
 % \mbox{}
 
 % \noindent
-% \textbf{Question 2:}\\ (Use mathematical notation, such as $r^+$, rather than code, such as \code{PLUS(r)})
+% \textbf{Task 2:}\\ (Use mathematical notation, such as $r^+$, rather than code, such as \code{PLUS(r)})
 
 % \begin{center}
 %   \def\arraystretch{1.6}  
Binary file cws/cw03.pdf has changed
--- a/cws/cw03.tex	Wed Sep 17 14:29:52 2025 +0100
+++ b/cws/cw03.tex	Wed Sep 17 15:11:48 2025 +0100
@@ -17,7 +17,8 @@
 you need to submit the source code with which you answered the
 questions, otherwise a mark of 0\% will be awarded. If you use Scala
 in your code, a good place to start is the file \texttt{comb1.sc} and
-\texttt{comb2.sc} uploaded to KEATS. Feel free to use the ``hack''
+\texttt{comb2.sc} uploaded to KEATS. Make sure your parser combinators 
+process list of tokens as input, not strings. Feel free to use the ``hack''
 explained during the lectures. This might make your grammar
 simpler. However, make sure you understand the code involved in the
 ``hack'' because if you just do ``mix-and-match'' you will receive
@@ -27,7 +28,7 @@
 ``runs'' the program. The marks will be distributed such that 6 marks
 are given for the correct grammar (and parsers); 4 marks for the correct
 \texttt{eval} function.  You should use the lexer from CW2 for the
-parser - you potentially need to make additions for CW2.  
+parser - you potentially need to make additions for CW3.  
 
 \subsection*{Disclaimer\alert}
 
@@ -35,35 +36,36 @@
 effort. You have not copied from anyone else. An exception is the
 Scala code I showed during the lectures or uploaded to KEATS, which
 you can both use. You can also use your own code from the CW~1 and
-CW~2. But do not
-be tempted to ask Github Copilot for help or do any other
-shenanigans like this!
-
-\subsection*{Syntax Error in Template File cw03.sc\alert}
-
-Apologies, there is a small syntax error in the template file where a variable
-needs to be called \texttt{tks} instead of \texttt{tk}. The code
-in question is at the end of \texttt{cw03.sc} and should be like
-this (see lines 5, 6 and 8):
+CW~2. 
+%But do not
+%be tempted to ask Github Copilot for help or do any other
+%shenanigans like this!
 
-\begin{lstlisting}[language=Scala,numbers=left]
-@main
-def test(file: String) = {
-  val contents = os.read(os.pwd / "examples" / file)
-  println(s"Lex $file: ")
-  val tks = tokenise(contents)
-  println(tks.mkString(","))
-  println(s"Parse $file: ")
-  val ast = Stmts.parse_all(tks).head
-  println(ast)
-  println(s"Eval $file: ")
-  println(eval(ast))
-}
-\end{lstlisting}  
+%\subsection*{Syntax Error in Template File cw03.sc\alert}
+%
+%Apologies, there is a small syntax error in the template file where a variable
+%needs to be called \texttt{tks} instead of \texttt{tk}. The code
+%in question is at the end of \texttt{cw03.sc} and should be like
+%this (see lines 5, 6 and 8):
+%
+%\begin{lstlisting}[language=Scala,numbers=left]
+%@main
+%def test(file: String) = {
+%  val contents = os.read(os.pwd / "examples" / file)
+%  println(s"Lex $file: ")
+%  val tks = tokenise(contents)
+%  println(tks.mkString(","))
+%  println(s"Parse $file: ")
+%  val ast = Stmts.parse_all(tks).head
+%  println(ast)
+%  println(s"Eval $file: ")
+%  println(eval(ast))
+%}
+%\end{lstlisting}  
 
 
 
-\subsection*{Question 1}
+\subsection*{Task 1}
 
 Design a grammar for the WHILE language and give the grammar
 rules. The main categories of non-terminals should be:
@@ -84,7 +86,7 @@
 \noindent
 Make sure the grammar is not left-recursive.
 
-\subsection*{Question 2}
+\subsection*{Task 2}
 
 You should implement a parser for the WHILE language using parser
 combinators. Be careful that the parser takes as input a list of
@@ -125,10 +127,28 @@
 \caption{The datatype for abstract syntax trees in Scala.\label{trees}}
 \end{figure}
 
-\subsection*{Question 3}
+\subsection*{Task 3}
+
+In addition to the simple assignments of the form \code{... := ...} 
+from Task 1, parse the assignments of the form
+
+\begin{quote}
+\texttt{... += ...} \;\;and\;\; \texttt{... *= ...}
+\end{quote}
+
+and translate them into simple assignments. For example
+
+\begin{quote}
+\texttt{cnt += 1}
+\end{quote}
+
+should give the assignment \texttt{cnt := cnt + 1}. Similarly
+for \texttt{*=}.
+
+\subsection*{Task 4}
 
 Implement an interpreter for the WHILE language you designed
-and parsed in Question 1 and 2. This interpreter should take
+and parsed in Tasks 1 and 2. This interpreter should take
 as input an AST. However be careful because, programs
 contain variables and variable assignments. This means
 you need to maintain a kind of memory, or environment,
@@ -156,7 +176,7 @@
 evaluates to \pcode{true}, otherwise the else-branch.
 Loops should be run as long as the boolean is \pcode{true}.
 Note also that some programs contain a read-statement,
-which means you need to read and integer from the commandline
+which means you need to read an integer from the commandline
 and store the value in the corresponding variable.
 Programs you should be able to run are given in  the
 \texttt{examples} directory. The output
Binary file cws/cw04.pdf has changed
--- a/cws/cw04.tex	Wed Sep 17 14:29:52 2025 +0100
+++ b/cws/cw04.tex	Wed Sep 17 15:11:48 2025 +0100
@@ -19,7 +19,7 @@
 provided by Jasmin or Krakatau (both have a very similar
 syntax).  You can do the implementation in any programming
 language you like, but you need to submit the source code with
-which you answered the questions, otherwise a mark of 0\% will
+which you answered the tasks, otherwise a mark of 0\% will
 be awarded. You should use the lexer and parser from the
 previous courseworks. Implement your compiler in the file \texttt{cw04.sc}.
 
@@ -145,20 +145,20 @@
 
 
 %\noindent You need to submit a document containing the answers
-%for the two questions below. You can do the implementation in
+%for the two tasks below. You can do the implementation in
 %any programming language you like, but you need to submit the
-%source code with which you answered the questions. Otherwise
+%source code with which you answered the tasks. Otherwise
 %the submission will not be counted. However, the coursework
 %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)}
+%\subsection*{Task 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}
+\subsection*{Task 1}
 
 You need to lex and parse WHILE programs, and then generate Java Byte
 Code instructions for the Jasmin assembler (or Krakatau
@@ -171,7 +171,7 @@
 \caption{The Fibonacci program in the WHILE language.\label{fibs}}
 \end{figure}
 
-\subsection*{Question 2}
+\subsection*{Task 2}
 
 Extend the syntax of your language so that it contains also
 \texttt{for}-loops, like
@@ -222,9 +222,9 @@
 \end{minipage}
 \end{center}
 
-\subsection*{Question 3 (OPTIONAL)}
+\subsection*{Task 3 (OPTIONAL)}
 
-\noindent In this question you are asked to think about the following
+\noindent In this task you are asked to think about the following
 program:
 
 \begin{center}
@@ -244,7 +244,7 @@
 twice. Therefore you need to make a decision about how it should be compiled?
 What should the program print?
 
-\subsection*{Question 4}
+\subsection*{Task 4}
 
 Extend the lexer and parser to add a \textcolor{codepurple}{\pcode{break}} keyword.  Modify
 the compiler (including lexer and parser) such that when a \textcolor{codepurple}{\texttt{break}}-statement is encountered
@@ -281,7 +281,7 @@
 but not \code{"Should not print"}. For this you need to add
 a label to the end of every for- and while-loop and also to the end of the
 whole program just in case you need to jump to that label via a
-\code{break}. The file you need to be able to process for this question
+\code{break}. The file you need to be able to process for this task
 is called \texttt{break.while}.
 
 
Binary file cws/cw05.pdf has changed