equal
deleted
inserted
replaced
42 also use your own code from the CW~1. |
42 also use your own code from the CW~1. |
43 %But do not |
43 %But do not |
44 %be tempted to ask Github Copilot for help or do any other |
44 %be tempted to ask Github Copilot for help or do any other |
45 %shenanigans like this! |
45 %shenanigans like this! |
46 |
46 |
47 \subsection*{Question 1} |
47 \subsection*{Task 1} |
48 |
48 |
49 To implement a lexer for the WHILE language, you first |
49 To implement a lexer for the WHILE language, you first |
50 need to design the appropriate regular expressions for the |
50 need to design the appropriate regular expressions for the |
51 following eleven syntactic entities: |
51 following eleven syntactic entities: |
52 |
52 |
144 \noindent Try to design your regular expressions to be as |
144 \noindent Try to design your regular expressions to be as |
145 small as possible. For example you should use character sets |
145 small as possible. For example you should use character sets |
146 for identifiers and numbers. Feel free to use the general |
146 for identifiers and numbers. Feel free to use the general |
147 character constructor \textit{CFUN} introduced in CW 1. |
147 character constructor \textit{CFUN} introduced in CW 1. |
148 |
148 |
149 \subsection*{Question 2} |
149 \subsection*{Task 2} |
150 |
150 |
151 Implement the Sulzmann \& Lu lexer from the lectures. For |
151 Implement the Sulzmann \& Lu lexer from the lectures. For |
152 this you need to implement the functions $nullable$ and $der$ |
152 this you need to implement the functions $nullable$ and $der$ |
153 (you can use your code from CW~1), as well as $mkeps$ and |
153 (you can use your code from CW~1), as well as $mkeps$ and |
154 $inj$. These functions need to be appropriately extended for |
154 $inj$. These functions need to be appropriately extended for |
189 |
189 |
190 Also add the record regular expression from the |
190 Also add the record regular expression from the |
191 lectures to your lexer and complete the function |
191 lectures to your lexer and complete the function |
192 \pcode{env} so that it returns all assignments from a value (this then |
192 \pcode{env} so that it returns all assignments from a value (this then |
193 allows you to extract easily the tokens from a value in the next |
193 allows you to extract easily the tokens from a value in the next |
194 question).\medskip |
194 task).\medskip |
195 |
195 |
196 \noindent |
196 \noindent |
197 Finally make that the function \texttt{lexing\_simp} generates |
197 Finally make that the function \texttt{lexing\_simp} generates |
198 with the regular expression from Q1 for the string |
198 with the regular expression from Q1 for the string |
199 |
199 |
210 |
210 |
211 |
211 |
212 |
212 |
213 |
213 |
214 |
214 |
215 \subsection*{Question 3} |
215 \subsection*{Task 3} |
216 |
216 |
217 Make sure your lexer from Q2 also simplifies regular expressions after |
217 Make sure your lexer from Q2 also simplifies regular expressions after |
218 each derivation step and rectifies the computed values after each |
218 each derivation step and rectifies the computed values after each |
219 injection. Use this lexer to tokenise the six WHILE programs |
219 injection. Use this lexer to tokenise the six WHILE programs |
220 in the \texttt{examples} directory. Make sure that the \texttt{tokenise} |
220 in the \texttt{examples} directory. Make sure that the \texttt{tokenise} |
249 % \section*{Answers} |
249 % \section*{Answers} |
250 |
250 |
251 % \mbox{} |
251 % \mbox{} |
252 |
252 |
253 % \noindent |
253 % \noindent |
254 % \textbf{Question 2:}\\ (Use mathematical notation, such as $r^+$, rather than code, such as \code{PLUS(r)}) |
254 % \textbf{Task 2:}\\ (Use mathematical notation, such as $r^+$, rather than code, such as \code{PLUS(r)}) |
255 |
255 |
256 % \begin{center} |
256 % \begin{center} |
257 % \def\arraystretch{1.6} |
257 % \def\arraystretch{1.6} |
258 % \begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}} |
258 % \begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}} |
259 % $mkeps([c_1,c_2,\ldots,c_n])$ & $\dn$ & \uline{\hspace{8cm}}\\ |
259 % $mkeps([c_1,c_2,\ldots,c_n])$ & $\dn$ & \uline{\hspace{8cm}}\\ |