24 \noindent |
24 \noindent |
25 You can do the implementation of your compiler in any programming |
25 You can do the implementation of your compiler in any programming |
26 language you like, but you need to submit the source code with which |
26 language you like, but you need to submit the source code with which |
27 you generated the LLVM-IR files, otherwise a mark of 0\% will be |
27 you generated the LLVM-IR files, otherwise a mark of 0\% will be |
28 awarded. You are asked to submit the code of your compiler, but also |
28 awarded. You are asked to submit the code of your compiler, but also |
29 the generated \texttt{.ll} files. You should use the lexer and parser |
29 the generated \texttt{.ll} files. No PDF is needed for this |
30 from the previous courseworks, but you need to make some modifications |
30 coursework. You should use the lexer and parser from the previous |
31 to them for the `typed' fun-language. I will award up to 5\% if a |
31 courseworks, but you need to make some modifications to them for the |
32 lexer and a parser are correctly implemented. At the end, please |
32 `typed' version of the Fun-language. I will award up to 5\% if a lexer |
33 package everything(!) in a zip-file that creates a directory with the |
33 and a parser are correctly implemented. At the end, please package |
34 name |
34 everything(!) in a zip-file that creates a directory with the name |
35 |
35 |
36 \begin{center} |
36 \begin{center} |
37 \texttt{YournameYourFamilyname} |
37 \texttt{YournameYourFamilyname} |
38 \end{center} |
38 \end{center} |
39 |
39 |
60 CW~4. |
60 CW~4. |
61 |
61 |
62 |
62 |
63 \subsection*{Task} |
63 \subsection*{Task} |
64 |
64 |
65 The main goal is to lex and parse 5 Fun-programs, including the |
65 The goal is to lex and parse 5 Fun-programs, including the |
66 Mandelbrot program shown in Figure~\ref{mand}, and generate |
66 Mandelbrot program shown in Figure~\ref{mand}, and generate |
67 corresponding code for the LLVM-IR. Unfortunately the calculations for |
67 corresponding code for the LLVM-IR. Unfortunately the calculations for |
68 the Mandelbrot Set require floating point arithmetic and therefore we |
68 the Mandelbrot Set require floating point arithmetic and therefore we |
69 cannot be as simple-minded about types as we have been so far |
69 cannot be as simple-minded about types as we have been so far |
70 (remember the LLVM-IR is a fully-typed language and needs to know the |
70 (remember the LLVM-IR is a fully-typed language and needs to know the |
79 val Ymin: Double = -1.3; |
79 val Ymin: Double = -1.3; |
80 val Maxiters: Int = 1000; |
80 val Maxiters: Int = 1000; |
81 \end{lstlisting} |
81 \end{lstlisting} |
82 |
82 |
83 \noindent |
83 \noindent |
84 where you want to assume that they are `normal' identifiers, just |
84 where you can assume that they are `normal' identifiers, just |
85 starting with a capital letter---all other identifiers should have |
85 starting with a capital letter---all other identifiers should have |
86 lower-case letters. Function definitions can take arguments of |
86 lower-case letters. Function definitions can take arguments of |
87 type \texttt{Int} or \texttt{Double}, and need to specify a return |
87 type \texttt{Int} or \texttt{Double}, and need to specify a return |
88 type, which can be \texttt{Void}, for example |
88 type, which can be \texttt{Void}, for example |
89 |
89 |
140 \includegraphics[scale=0.35]{../solution/cw5/out.png} |
140 \includegraphics[scale=0.35]{../solution/cw5/out.png} |
141 \caption{Ascii output of the Mandelbrot program.\label{mand}} |
141 \caption{Ascii output of the Mandelbrot program.\label{mand}} |
142 \end{figure} |
142 \end{figure} |
143 |
143 |
144 Also note that the second version of the Mandelbrot program and also |
144 Also note that the second version of the Mandelbrot program and also |
145 the Tower of Hanoi program uses character constants, like \texttt{'a'}, |
145 the Tower of Hanoi program use character constants, like \texttt{'a'}, |
146 \texttt{'1'}, \texttt{'$\backslash$n'} and so on. When they are tokenised, |
146 \texttt{'1'}, \texttt{'$\backslash$n'} and so on. When they are tokenised, |
147 such characters should be interpreted as the corresponding ASCII code (an |
147 such characters should be interpreted as the corresponding ASCII code (an |
148 integer), such that we can use them in calculations like \texttt{'a' + 10} |
148 integer), such that we can use them in calculations like \texttt{'a' + 10} |
149 where the result should be 107. As usual, the character \texttt{'$\backslash$n'} is the |
149 where the result should be 107. As usual, the character \texttt{'$\backslash$n'} is the |
150 ASCII code 10. |
150 ASCII code 10. |