equal
deleted
inserted
replaced
15 |
15 |
16 \noindent This coursework is worth 15\% and is due on \cwFOUR{} |
16 \noindent This coursework is worth 15\% and is due on \cwFOUR{} |
17 at 16:00. You are asked to implement a compiler for |
17 at 16:00. You are asked to implement a compiler for |
18 the WHILE language that targets the assembler language |
18 the WHILE language that targets the assembler language |
19 provided by Jasmin or Krakatau (both have a very similar |
19 provided by Jasmin or Krakatau (both have a very similar |
20 syntax). Please submit your answers to the questions |
20 syntax). You can do the implementation in any programming |
21 below as PDF. You can do the implementation in any programming |
|
22 language you like, but you need to submit the source code with |
21 language you like, but you need to submit the source code with |
23 which you answered the questions, otherwise a mark of 0\% will |
22 which you answered the questions, otherwise a mark of 0\% will |
24 be awarded. You should use the lexer and parser from the |
23 be awarded. You should use the lexer and parser from the |
25 previous courseworks. Implement your compiler in the file \texttt{cw04.sc}. |
24 previous courseworks. Implement your compiler in the file \texttt{cw04.sc}. |
26 |
25 |
98 \small\url{http://www.csc.villanova.edu/~tway/courses/csc4181/s2022/labs/finalproject/JVM.pdf} |
97 \small\url{http://www.csc.villanova.edu/~tway/courses/csc4181/s2022/labs/finalproject/JVM.pdf} |
99 \end{center} |
98 \end{center} |
100 |
99 |
101 \noindent |
100 \noindent |
102 If possible use Jasmin for the coursework. The Krakatau assembler |
101 If possible use Jasmin for the coursework. The Krakatau assembler |
103 below as a slightly different syntax. |
102 below has a slightly different syntax. |
104 |
103 |
105 |
104 |
106 \subsection*{Krakatau Assembler (Version 1 \& 2)} |
105 \subsection*{Krakatau Assembler (Version 1 \& 2)} |
107 |
106 |
108 The Krakatau assembler is available from |
107 The Krakatau assembler is available from |
163 |
162 |
164 You need to lex and parse WHILE programs, and then generate Java Byte |
163 You need to lex and parse WHILE programs, and then generate Java Byte |
165 Code instructions for the Jasmin assembler (or Krakatau |
164 Code instructions for the Jasmin assembler (or Krakatau |
166 assembler). For this you should use the ASTs defined in CW3 (including |
165 assembler). For this you should use the ASTs defined in CW3 (including |
167 logical operators). As part of the solution you need to submit the assembler |
166 logical operators). As part of the solution you need to submit the assembler |
168 instructions for the Fibonacci and Factorial programs. Both should be |
167 instructions for the Fibonacci and Factorial programs. |
169 so modified that a user can input on the console which Fibonacci |
|
170 number and which Factorial should be calculated. The Fibonacci program |
|
171 is given in Figure~\ref{fibs}. You can write your own program for |
|
172 calculating factorials. Submit your assembler code as a file that can |
|
173 be run, not as PDF-text. |
|
174 |
168 |
175 \begin{figure}[t] |
169 \begin{figure}[t] |
176 \lstinputlisting[language=while]{../cwtests/cw04/fib.while} |
170 \lstinputlisting[language=while]{../cwtests/cw04/fib.while} |
177 \caption{The Fibonacci program in the WHILE language.\label{fibs}} |
171 \caption{The Fibonacci program in the WHILE language.\label{fibs}} |
178 \end{figure} |
172 \end{figure} |
226 } |
220 } |
227 \end{lstlisting} |
221 \end{lstlisting} |
228 \end{minipage} |
222 \end{minipage} |
229 \end{center} |
223 \end{center} |
230 |
224 |
231 \subsection*{Question 3} |
225 \subsection*{Question 3 (OPTIONAL)} |
232 |
226 |
233 \noindent In this question you are supposed to give the |
227 \noindent In this question you are asked to think about the following |
234 assembler instructions for the program |
228 program: |
235 |
229 |
236 \begin{center} |
230 \begin{center} |
237 \begin{minipage}{12cm} |
231 \begin{minipage}{12cm} |
238 \begin{lstlisting}[language=While, numbers=none] |
232 \begin{lstlisting}[language=While, numbers=none] |
239 for i := 1 upto 10 do { |
233 for i := 1 upto 10 do { |
245 \end{minipage} |
239 \end{minipage} |
246 \end{center} |
240 \end{center} |
247 |
241 |
248 \noindent |
242 \noindent |
249 Note that in this program the variable \pcode{i} is used |
243 Note that in this program the variable \pcode{i} is used |
250 twice. You need to make a decision how it should be compiled? |
244 twice. Therefore you need to make a decision about how it should be compiled? |
251 Explain your decision and indicate what this program would |
245 What should the program print? |
252 print out. Give your answer in the file \texttt{q3-answer.txt}. |
|
253 |
246 |
254 \subsection*{Question 4} |
247 \subsection*{Question 4} |
255 |
248 |
256 Extend the lexer and parser to add a \textcolor{codepurple}{\pcode{break}} keyword. Modify |
249 Extend the lexer and parser to add a \textcolor{codepurple}{\pcode{break}} keyword. Modify |
257 the compiler (including lexer and parser) such that when a \textcolor{codepurple}{\texttt{break}}-statement is encountered |
250 the compiler (including lexer and parser) such that when a \textcolor{codepurple}{\texttt{break}}-statement is encountered |