--- a/cws/cw02.tex Sun Oct 01 12:04:51 2023 +0100
+++ b/cws/cw02.tex Sun Oct 01 13:35:51 2023 +0100
@@ -15,8 +15,9 @@
you answered the questions, otherwise a mark of 0\% will be
awarded. You need to submit your written
answers as pdf---see attached questionaire. Code send as code. If you use
-Scala in your code, a good place to start is the file \texttt{re3.sc}
-that is uploaded to Github.
+Scala in your code, a good place to start is the file \texttt{lexer.sc}
+and \texttt{token.sc}
+that are uploaded to Github.
\subsection*{Disclaimer\alert}
@@ -83,18 +84,20 @@
\texttt{$\backslash$} and
\texttt{:}
-\item strings are enclosed by double quotes, like \texttt{"\ldots"}, and consisting of
- symbols, whitespaces and digits
\item parentheses are \texttt{(}, \texttt{\{}, \texttt{)} and \texttt{\}}
+\item digits are \pcode{0} to \pcode{9}
\item there are semicolons \texttt{;}
\item whitespaces are either \texttt{" "} (one or more) or \texttt{$\backslash$n} or
\texttt{$\backslash$t} or \texttt{$\backslash$r}
\item identifiers are letters followed by underscores \texttt{\_\!\_}, letters
-or digits
-\item numbers are \pcode{0}, \pcode{1}, \ldots and so on; give
+ or digits
+\item numbers for numbers give
a regular expression that can recognise \pcode{0}, but not numbers
with leading zeroes, such as \pcode{001}
-\item comments start with \texttt{//} and contain symbols, spaces and digits until the end of the line
+\item strings are enclosed by double quotes, like \texttt{"\ldots"}, and consisting of
+ symbols, digits, parentheses, whitespaces and \texttt{$\backslash$n} (note the latter is not the escaped version but \texttt{$\backslash$} followed by \texttt{n}, otherwise we would not be able to indicate in our strings when to write a newline).
+\item comments start with \texttt{//} and contain symbols, spaces and digits until the end-of-the-line markers
+\item endo-of-line-markers are \texttt{$\backslash$n} and \texttt{$\backslash$r$\backslash$n}
\end{enumerate}
\noindent
@@ -177,7 +180,7 @@
that you can extract easily the tokens from a value).\medskip
\noindent
-Finally give the tokens for your regular expressions from Q1 and the
+Finally give \textbf{all} the tokens for your regular expressions from Q1 and the
string
\begin{center}
@@ -192,9 +195,10 @@
Extend your lexer from Q2 to also simplify regular expressions after
each derivation step and rectify the computed values after each
-injection. Use this lexer to tokenize the programs in
-Figures~\ref{fib} -- \ref{collatz}. You can find the programms also on
-KEATS. Give the tokens of these programs where whitespaces are
+injection. Use this lexer to tokenize six WHILE programs some of which
+are given in Figures~\ref{fib} -- \ref{collatz}. You can find these programms also on
+Github under the \texttt{cw2} directory. Give the tokens of these
+programs where whitespaces and comments are
filtered out. Make sure you can tokenise \textbf{exactly} these
programs.\bigskip
@@ -217,7 +221,7 @@
\end{figure}
\begin{figure}[h]
-\mbox{\lstinputlisting[language=While,xleftmargin=10mm]{../progs/while-tests/collatz2.while}}
+\mbox{\lstinputlisting[language=While,xleftmargin=10mm]{../cwtests/cw02/collatz2.while}}
\caption{A program that calculates the Collatz series for numbers
between 1 and 100.\label{collatz}}
\end{figure}
@@ -229,7 +233,7 @@
\mbox{}
\noindent
-\textbf{Question 2:}
+\textbf{Question 2:}\\ (Use mathematical notation, such as $r^+$, rather than code, such as \code{PLUS(r)})
\begin{center}
\def\arraystretch{1.6}