cws/cw02.tex
changeset 992 c3dd3a98f919
parent 986 68b1a84efce6
equal deleted inserted replaced
991:5d01eccc2036 992:c3dd3a98f919
    33 
    33 
    34 
    34 
    35 \subsection*{Disclaimer\alert}
    35 \subsection*{Disclaimer\alert}
    36 
    36 
    37 It should be understood that the work you submit represents
    37 It should be understood that the work you submit represents
    38 your own effort. You have not copied from anyone else
    38 your own effort. 
    39 including CoPilot, ChatGPT \& Co. An
    39 %You have not copied from anyone else
       
    40 %including CoPilot, ChatGPT \& Co. 
       
    41 An
    40 exception is the Scala code from KEATS and the code I showed
    42 exception is the Scala code from KEATS and the code I showed
    41 during the lectures, which you can both freely use. You can
    43 during the lectures, which you can both freely use. You can
    42 also use your own code from the CW~1.
    44 also use your own code from CW~1.
    43 %But do not
    45 %But do not
    44 %be tempted to ask Github Copilot for help or do any other
    46 %be tempted to ask Github Copilot for help or do any other
    45 %shenanigans like this!
    47 %shenanigans like this!
    46 
    48 
    47 \subsection*{Task 1}
    49 \subsection*{Task 1}
   102 \item there are semicolons \texttt{;}
   104 \item there are semicolons \texttt{;}
   103 \item whitespaces are either \texttt{" "} (one or more) or \texttt{$\backslash$n} or
   105 \item whitespaces are either \texttt{" "} (one or more) or \texttt{$\backslash$n} or
   104   \texttt{$\backslash$t} or \texttt{$\backslash$r}
   106   \texttt{$\backslash$t} or \texttt{$\backslash$r}
   105 \item identifiers are letters followed by underscores \texttt{\_\!\_}, letters
   107 \item identifiers are letters followed by underscores \texttt{\_\!\_}, letters
   106   or digits  
   108   or digits  
   107 \item numbers for numbers give 
   109 \item for numbers give 
   108 a regular expression that can recognise \pcode{0}, but not numbers 
   110 a regular expression that can recognise \pcode{0}, but not numbers 
   109 with leading zeroes, such as \pcode{001}
   111 with leading zeroes, such as \pcode{001}
   110 \item strings are enclosed by double quotes, like \texttt{"\ldots"}, and consisting of
   112 \item strings are enclosed by double quotes, like \texttt{"\ldots"}, and consisting of
   111   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).
   113   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).
   112 \item comments start with \texttt{//} and contain symbols, spaces, parentheses and digits until the end-of-the-line markers
   114 \item comments start with \texttt{//} and contain symbols, spaces, parentheses and digits until the end-of-the-line markers
   150 
   152 
   151 Implement the Sulzmann \& Lu lexer from the lectures. For
   153 Implement the Sulzmann \& Lu lexer from the lectures. For
   152 this you need to implement the functions $nullable$ and $der$
   154 this you need to implement the functions $nullable$ and $der$
   153 (you can use your code from CW~1), as well as $mkeps$ and
   155 (you can use your code from CW~1), as well as $mkeps$ and
   154 $inj$. These functions need to be appropriately extended for
   156 $inj$. These functions need to be appropriately extended for
   155 the extended regular expressions from Q1. The definitions
   157 the extended regular expressions from Task 1. The definitions
   156 you need to create are:
   158 you need to create are:
   157 
   159 
   158 
   160 
   159 \begin{center}
   161 \begin{center}
   160 \begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
   162 \begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
   193 allows you to extract easily the tokens from a value in the next
   195 allows you to extract easily the tokens from a value in the next
   194 task).\medskip 
   196 task).\medskip 
   195 
   197 
   196 \noindent
   198 \noindent
   197 Finally make that the function \texttt{lexing\_simp} generates
   199 Finally make that the function \texttt{lexing\_simp} generates
   198 with the regular expression from Q1 for the string
   200 with the regular expression from Task 1 for the string
   199 
   201 
   200 \begin{center}
   202 \begin{center}
   201 \code{"read n;"}
   203 \code{"read n;"}
   202 \end{center} 
   204 \end{center} 
   203 
   205 
   212 
   214 
   213 
   215 
   214 
   216 
   215 \subsection*{Task 3}
   217 \subsection*{Task 3}
   216 
   218 
   217 Make sure your lexer from Q2 also simplifies regular expressions after
   219 Make sure your lexer from Task 2 also simplifies regular expressions after
   218 each derivation step and rectifies the computed values after each
   220 each derivation step and rectifies the computed values after each
   219 injection. Use this lexer to tokenise the six WHILE programs
   221 injection. Use this lexer to tokenise the six WHILE programs
   220 in the \texttt{examples} directory. Make sure that the \texttt{tokenise}
   222 in the \texttt{examples} directory. Make sure that the \texttt{tokenise}
   221 function filters out whitespaces and comments.\bigskip
   223 function filters out whitespaces and comments.\bigskip
   222 
   224