1 % !TEX program = xelatex |
1 % !TEX program = xelatex |
2 \documentclass{article} |
2 \documentclass{article} |
3 \usepackage{../style} |
3 \usepackage{../style} |
4 \usepackage{../langs} |
4 \usepackage{../langs} |
|
5 \usepackage[normalem]{ulem} |
5 |
6 |
6 \begin{document} |
7 \begin{document} |
7 |
8 |
8 \section*{Coursework 2} |
9 \section*{Coursework 2} |
9 |
10 |
10 \noindent This coursework is worth 10\% and is due on \cwTWO{} at |
11 \noindent This coursework is worth 10\% and is due on \cwTWO{} at |
11 16:00. You are asked to implement the Sulzmann \& Lu lexer for the |
12 16:00. You are asked to implement the Sulzmann \& Lu lexer for the |
12 WHILE language. You can do the implementation in any programming |
13 WHILE language. You can do the implementation in any programming |
13 language you like, but you need to submit the source code with which |
14 language you like, but you need to submit the source code with which |
14 you answered the questions, otherwise a mark of 0\% will be |
15 you answered the questions, otherwise a mark of 0\% will be |
15 awarded. You can submit your answers in a txt-file or as pdf. Code |
16 awarded. You need to submit your written |
16 submit as code. Please package everything in a zip-file that creates a |
17 answers as pdf---see attached questionaire. Code send as code. If you use |
17 directory with the name \texttt{YournameYourfamilyname} on my end. Thanks! |
18 Scala in your code, a good place to start is the file \texttt{re3.sc} |
|
19 that is uploaded to Github. |
18 |
20 |
19 \subsection*{Disclaimer\alert} |
21 \subsection*{Disclaimer\alert} |
20 |
22 |
21 It should be understood that the work you submit represents |
23 It should be understood that the work you submit represents |
22 your own effort. You have not copied from anyone else. An |
24 your own effort. You have not copied from anyone else |
|
25 including CoPilot, ChatGPT \& Co. An |
23 exception is the Scala code from KEATS and the code I showed |
26 exception is the Scala code from KEATS and the code I showed |
24 during the lectures, which you can both freely use. You can |
27 during the lectures, which you can both freely use. You can |
25 also use your own code from the CW~1. But do not |
28 also use your own code from the CW~1. |
26 be tempted to ask Github Copilot for help or do any other |
29 %But do not |
27 shenanigans like this! |
30 %be tempted to ask Github Copilot for help or do any other |
|
31 %shenanigans like this! |
28 |
32 |
29 \subsection*{Question 1} |
33 \subsection*{Question 1} |
30 |
34 |
31 To implement a lexer for the WHILE language, you first |
35 To implement a lexer for the WHILE language, you first |
32 need to design the appropriate regular expressions for the |
36 need to design the appropriate regular expressions for the |
130 |
134 |
131 Implement the Sulzmann \& Lu lexer from the lectures. For |
135 Implement the Sulzmann \& Lu lexer from the lectures. For |
132 this you need to implement the functions $nullable$ and $der$ |
136 this you need to implement the functions $nullable$ and $der$ |
133 (you can use your code from CW~1), as well as $mkeps$ and |
137 (you can use your code from CW~1), as well as $mkeps$ and |
134 $inj$. These functions need to be appropriately extended for |
138 $inj$. These functions need to be appropriately extended for |
135 the extended regular expressions from Q1. Write down the |
139 the extended regular expressions from Q1. Write down in the |
|
140 questionaire at the end the |
136 clauses for |
141 clauses for |
137 |
142 |
138 \begin{center} |
143 \begin{center} |
139 \begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}} |
144 \begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}} |
140 $mkeps([c_1,c_2,\ldots,c_n])$ & $\dn$ & $?$\\ |
145 $mkeps([c_1,c_2,\ldots,c_n])$ & $\dn$ & $?$\\ |
215 \mbox{\lstinputlisting[language=While,xleftmargin=10mm]{../progs/while-tests/collatz2.while}} |
220 \mbox{\lstinputlisting[language=While,xleftmargin=10mm]{../progs/while-tests/collatz2.while}} |
216 \caption{A program that calculates the Collatz series for numbers |
221 \caption{A program that calculates the Collatz series for numbers |
217 between 1 and 100.\label{collatz}} |
222 between 1 and 100.\label{collatz}} |
218 \end{figure} |
223 \end{figure} |
219 |
224 |
|
225 \clearpage |
|
226 \newpage |
|
227 \section*{Answers} |
|
228 |
|
229 \mbox{} |
|
230 |
|
231 \noindent |
|
232 \textbf{Question 2:} |
|
233 |
|
234 \begin{center} |
|
235 \def\arraystretch{1.6} |
|
236 \begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}} |
|
237 $mkeps([c_1,c_2,\ldots,c_n])$ & $\dn$ & \uline{\hspace{8cm}}\\ |
|
238 $mkeps(r^+)$ & $\dn$ & \uline{\hspace{8cm}}\\ |
|
239 $mkeps(r^?)$ & $\dn$ & \uline{\hspace{8cm}}\\ |
|
240 $mkeps(r^{\{n\}})$ & $\dn$ & \uline{\hspace{8cm}}\bigskip\\ |
|
241 $inj\, ([c_1,c_2,\ldots,c_n])\,c\,\ldots$ & $\dn$ & \uline{\hspace{8cm}}\\ |
|
242 $inj\, (r^+)\,c\,\ldots$ & $\dn$ & \uline{\hspace{8cm}}\\ |
|
243 $inj\, (r^?)\,c\,\ldots$ & $\dn$ & \uline{\hspace{8cm}}\\ |
|
244 $inj\, (r^{\{n\}})\,c\,\ldots$ & $\dn$ & \uline{\hspace{8cm}}\\ |
|
245 \end{tabular} |
|
246 \end{center}\bigskip |
|
247 |
|
248 \noindent |
|
249 Tokens for \code{"read n;"}\\ |
|
250 |
|
251 \noindent |
|
252 \uline{\hfill}\medskip |
|
253 |
|
254 \noindent |
|
255 \uline{\hfill}\medskip |
|
256 |
|
257 \noindent |
|
258 \uline{\hfill}\medskip |
|
259 |
|
260 \noindent |
|
261 \uline{\hfill}\medskip |
|
262 |
|
263 |
220 \end{document} |
264 \end{document} |
221 |
265 |
222 %%% Local Variables: |
266 %%% Local Variables: |
223 %%% mode: latex |
267 %%% mode: latex |
224 %%% TeX-master: t |
268 %%% TeX-master: t |