cws/cw02.tex
changeset 968 d8d8911a3d6f
parent 946 bee7c57c18c3
child 969 0dfa2923a7c6
--- a/cws/cw02.tex	Fri Oct 11 19:13:00 2024 +0100
+++ b/cws/cw02.tex	Wed Oct 16 13:14:13 2024 +0100
@@ -13,12 +13,20 @@
 WHILE language. 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 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
+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{lexer.sc} and
 \texttt{token.sc} uploaded to KEATS. The template file on Github is
-called \texttt{cw02.sc}. Your code needs to be uploaded to Github by
-the deadline.
+called \texttt{cw02.sc}. The example files are in the subdirectory
+\texttt{examples}. The main function that will be tested is
+called \texttt{tokenise}. The marks will be distributed such that
+3 marks are given for the correct \texttt{WHILE\_REGS} regular
+expression; 5 marks for the correct \texttt{inj} and \texttt{mkeps}
+definitions; and two marks when \texttt{tokenise} produces the correct
+results for the example files. 
+
+
 
 \subsection*{Disclaimer\alert}
 
@@ -140,9 +148,9 @@
 this you need to implement the functions $nullable$ and $der$
 (you can use your code from CW~1), as well as $mkeps$ and
 $inj$. These functions need to be appropriately extended for
-the extended regular expressions from Q1. Write down in the
-questionaire at the end the 
-clauses for
+the extended regular expressions from Q1. The definitions
+you need to create are:
+
 
 \begin{center}
 \begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
@@ -176,94 +184,99 @@
 
 
 Also add the record regular expression from the
-lectures to your lexer and implement a function, say
-\pcode{env}, that returns all assignments from a value (such
-that you can extract easily the tokens from a value).\medskip 
+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 
 
 \noindent
-Finally give \textbf{all} the tokens for your regular expressions from Q1 and the
-string
+Finally make that the function \texttt{lexing\_simp} generates
+with the regular expression from Q1 for the string
 
 \begin{center}
 \code{"read n;"}
 \end{center} 
 
 \noindent
-and use your \pcode{env} function to give the token sequence.
+the following pairs:
+
+\begin{center}
+\texttt{List((k,read), (w, ), (i,n), (s,;))}
+\end{center} 
+
+
+
 
 
 \subsection*{Question 3}
 
-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 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
+Make sure your lexer from Q2 also simplifies regular expressions after
+each derivation step and rectifies the computed values after each
+injection. Use this lexer to tokenise the six WHILE programs
+in the \texttt{examples} directory. Make sure that the \texttt{tokenise}
+function filters out whitespaces and comments.\bigskip
 
 
-\begin{figure}[h]
-\mbox{\lstinputlisting[language=While,xleftmargin=10mm]{../cwtests/cw02/fib.while}}
-\caption{Fibonacci program in the WHILE language.\label{fib}}
-\end{figure}
+% \begin{figure}[h]
+% \mbox{\lstinputlisting[language=While,xleftmargin=10mm]{../cwtests/cw02/fib.while}}
+% \caption{Fibonacci program in the WHILE language.\label{fib}}
+% \end{figure}
 
-\begin{figure}[h]
-\mbox{\lstinputlisting[language=While,xleftmargin=10mm]{../cwtests/cw02/loops.while}}
-\caption{The three-nested-loops program in the WHILE language. 
-(Usually used for timing measurements.)\label{loop}}
-\end{figure}
+% \begin{figure}[h]
+% \mbox{\lstinputlisting[language=While,xleftmargin=10mm]{../cwtests/cw02/loops.while}}
+% \caption{The three-nested-loops program in the WHILE language. 
+% (Usually used for timing measurements.)\label{loop}}
+% \end{figure}
 
-\begin{figure}[h]
-\mbox{\lstinputlisting[language=While,xleftmargin=10mm]{../cwtests/cw02/factors.while}}
-\caption{A program that calculates factors for numbers in the WHILE
-  language.\label{factors}}
-\end{figure}
+% \begin{figure}[h]
+% \mbox{\lstinputlisting[language=While,xleftmargin=10mm]{../cwtests/cw02/factors.while}}
+% \caption{A program that calculates factors for numbers in the WHILE
+%   language.\label{factors}}
+% \end{figure}
 
-\begin{figure}[h]
-\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}
+% \begin{figure}[h]
+% \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}
 
-\clearpage
-\newpage
-\section*{Answers}
+% \clearpage
+% \newpage
+% \section*{Answers}
 
-\mbox{}
+% \mbox{}
 
-\noindent
-\textbf{Question 2:}\\ (Use mathematical notation, such as $r^+$, rather than code, such as \code{PLUS(r)})
+% \noindent
+% \textbf{Question 2:}\\ (Use mathematical notation, such as $r^+$, rather than code, such as \code{PLUS(r)})
 
-\begin{center}
-  \def\arraystretch{1.6}  
-\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
-$mkeps([c_1,c_2,\ldots,c_n])$  & $\dn$ & \uline{\hspace{8cm}}\\
-$mkeps(r^+)$                   & $\dn$ & \uline{\hspace{8cm}}\\
-$mkeps(r^?)$                   & $\dn$ & \uline{\hspace{8cm}}\\
-$mkeps(r^{\{n\}})$             & $\dn$ & \uline{\hspace{8cm}}\bigskip\\
-$inj\, ([c_1,c_2,\ldots,c_n])\,c\,\ldots$  & $\dn$ & \uline{\hspace{8cm}}\\
-$inj\, (r^+)\,c\,\ldots$                   & $\dn$ & \uline{\hspace{8cm}}\\
-$inj\, (r^?)\,c\,\ldots$                   & $\dn$ & \uline{\hspace{8cm}}\\
-$inj\, (r^{\{n\}})\,c\,\ldots$             & $\dn$ & \uline{\hspace{8cm}}\\
-\end{tabular}
-\end{center}\bigskip
+% \begin{center}
+%   \def\arraystretch{1.6}  
+% \begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
+% $mkeps([c_1,c_2,\ldots,c_n])$  & $\dn$ & \uline{\hspace{8cm}}\\
+% $mkeps(r^+)$                   & $\dn$ & \uline{\hspace{8cm}}\\
+% $mkeps(r^?)$                   & $\dn$ & \uline{\hspace{8cm}}\\
+% $mkeps(r^{\{n\}})$             & $\dn$ & \uline{\hspace{8cm}}\bigskip\\
+% $inj\, ([c_1,c_2,\ldots,c_n])\,c\,\ldots$  & $\dn$ & \uline{\hspace{8cm}}\\
+% $inj\, (r^+)\,c\,\ldots$                   & $\dn$ & \uline{\hspace{8cm}}\\
+% $inj\, (r^?)\,c\,\ldots$                   & $\dn$ & \uline{\hspace{8cm}}\\
+% $inj\, (r^{\{n\}})\,c\,\ldots$             & $\dn$ & \uline{\hspace{8cm}}\\
+% \end{tabular}
+% \end{center}\bigskip
 
-\noindent
-Tokens for \code{"read n;"}\\
+% \noindent
+% Tokens for \code{"read n;"}\\
 
-\noindent
-\uline{\hfill}\medskip
+% \noindent
+% \uline{\hfill}\medskip
 
-\noindent
-\uline{\hfill}\medskip
+% \noindent
+% \uline{\hfill}\medskip
 
-\noindent
-\uline{\hfill}\medskip
+% \noindent
+% \uline{\hfill}\medskip
 
-\noindent
-\uline{\hfill}\medskip
+% \noindent
+% \uline{\hfill}\medskip
 
 
 \end{document}