4 |
4 |
5 \begin{document} |
5 \begin{document} |
6 |
6 |
7 \section*{Coursework 2 (Strand 1)} |
7 \section*{Coursework 2 (Strand 1)} |
8 |
8 |
9 \noindent |
9 \noindent This coursework is worth 5\% and is due on 6 |
10 This coursework is worth 5\% and is due on 6 November at 16:00. You |
10 November at 16:00. You are asked to implement the Sulzmann \& |
11 are asked to implement the Sulzmann tokeniser for the WHILE language. |
11 Lu tokeniser for the WHILE language. You can do the |
12 You need to submit a document containing the answers for the questions |
12 implementation in any programming language you like, but you |
13 below. You can do the implementation in any programming language you |
13 need to submit the source code with which you answered the |
14 like, but you need to submit the source code with which you answered |
14 questions, otherwise a mark of 0\% will be awarded. However, |
15 the questions. However, the coursework will \emph{only} be judged |
15 the coursework will \emph{only} be judged according to the |
16 according to the answers. You can submit your answers in a txt-file or |
16 answers. You can submit your answers in a txt-file or as pdf. |
17 as pdf. |
|
18 |
17 |
19 \subsection*{Disclaimer} |
18 \subsection*{Disclaimer} |
20 |
19 |
21 It should be understood that the work you submit represents your own |
20 It should be understood that the work you submit represents |
22 effort. You have not copied from anyone else. An exception is the |
21 your own effort. You have not copied from anyone else. An |
23 Scala code I showed during the lectures, which you can use. |
22 exception is the Scala code I showed during the lectures, |
24 You can also use your own code from the CW~1. |
23 which you can use. You can also use your own code from the |
|
24 CW~1. |
25 |
25 |
26 \subsection*{Question 1 (marked with 1\%)} |
26 \subsection*{Question 1 (marked with 1\%)} |
27 |
27 |
28 To implement a tokeniser for the WHILE language, you first need to design |
28 To implement a tokeniser for the WHILE language, you first |
29 the appropriate regular expressions for the following eight syntactic entities: |
29 need to design the appropriate regular expressions for the |
|
30 following eight syntactic entities: |
30 |
31 |
31 \begin{enumerate} |
32 \begin{enumerate} |
32 \item keywords are |
33 \item keywords are |
33 |
34 |
34 \begin{quote} |
35 \begin{quote} |
93 |
94 |
94 \noindent |
95 \noindent |
95 |
96 |
96 \subsection*{Question 2 (marked with 3\%)} |
97 \subsection*{Question 2 (marked with 3\%)} |
97 |
98 |
98 Implement the Sulzmann tokeniser from the lectures. For this you need |
99 Implement the Sulzmann \& Lu tokeniser from the lectures. For |
99 to implement the functions $nullable$ and $der$ (you can use your code |
100 this you need to implement the functions $nullable$ and $der$ |
100 from CW 1), as well as $mkeps$ and $inj$. These functions need to be |
101 (you can use your code from CW 1), as well as $mkeps$ and |
101 appropriately extended for the extended regular expressions from |
102 $inj$. These functions need to be appropriately extended for |
102 Q1. Also add the record regular expression from the lectures and |
103 the extended regular expressions from Q1. Also add the record |
103 implement a function, say \pcode{env}, that returns all assignments |
104 regular expression from the lectures and implement a function, |
104 from a value (such that you can extract easily the tokens from a |
105 say \pcode{env}, that returns all assignments from a value |
105 value). |
106 (such that you can extract easily the tokens from a value). |
106 |
107 |
107 The functions $mkeps$ and $inj$ return values. Calculate |
108 The functions $mkeps$ and $inj$ return values. Calculate the |
108 the value for your regular expressions from Q1 and the string |
109 value for your regular expressions from Q1 and the string |
109 |
110 |
110 \begin{center} |
111 \begin{center} |
111 \code{"read n;"} |
112 \code{"read n;"} |
112 \end{center} |
113 \end{center} |
113 |
114 |