7 %https://github.com/Storyyeller/Krakatau |
7 %https://github.com/Storyyeller/Krakatau |
8 %https://docs.oracle.com/javase/specs/jvms/se7/html/ |
8 %https://docs.oracle.com/javase/specs/jvms/se7/html/ |
9 |
9 |
10 \section*{Coursework 4 (Strand 1)} |
10 \section*{Coursework 4 (Strand 1)} |
11 |
11 |
12 \noindent This coursework is worth 6\% and is due on 13 |
12 \noindent This coursework is worth 6\% and is due on 7 |
13 December at 16:00. You are asked to implement a compiler for |
13 December at 16:00. You are asked to implement a compiler for |
14 the WHILE language that targets the assembler language |
14 the WHILE language that targets the assembler language |
15 provided by Jasmin or Krakatau (both have very similar |
15 provided by Jasmin or Krakatau (both have very similar |
16 syntax). You can do the implementation in any programming |
16 syntax). You can do the implementation in any programming |
17 language you like, but you need to submit the source code with |
17 language you like, but you need to submit the source code with |
98 \begin{center} |
98 \begin{center} |
99 \url{https://pypi.python.org/pypi/ply} |
99 \url{https://pypi.python.org/pypi/ply} |
100 \end{center} |
100 \end{center} |
101 |
101 |
102 \noindent This assembler is largely compatible with the Jasmin |
102 \noindent This assembler is largely compatible with the Jasmin |
103 syntax---that means for the files we look are concerned with, |
103 syntax---that means for the files we are concerned with here, |
104 it understands the same input syntax (no changes to your |
104 it understands the same input syntax (no changes to your |
105 compiler need to be made). You can generate Java Byte Code by |
105 compiler need to be made; ok maybe some small syntactic |
|
106 adjustments are needed). You can generate Java Byte Code by |
106 using |
107 using |
107 |
108 |
108 \begin{center} |
109 \begin{center} |
109 \texttt{python Krakatau-master/assemble.py loops.j} |
110 \texttt{python Krakatau-master/assemble.py loops.j} |
110 \end{center} |
111 \end{center} |
111 |
112 |
112 \noindent where you may have to adapt the directory where |
113 \noindent where you may have to adapt the directory where |
113 Krakatau is installed (I just downloaded the zip file from |
114 Krakatau is installed (I just downloaded the zip file from |
114 Github and \pcode{Krakatau-master} was the directory where it |
115 Github and \pcode{Krakatau-master} was the directory where it |
115 was installed). |
116 was installed). Again the resulting class-file you can run with |
|
117 \texttt{java}. |
116 |
118 |
117 |
119 |
118 %\noindent You need to submit a document containing the answers |
120 %\noindent You need to submit a document containing the answers |
119 %for the two questions below. You can do the implementation in |
121 %for the two questions below. You can do the implementation in |
120 %any programming language you like, but you need to submit the |
122 %any programming language you like, but you need to submit the |
132 assembler instructions for the Fibonacci and Factorial |
134 assembler instructions for the Fibonacci and Factorial |
133 programs. Both should be so modified that a user can input on |
135 programs. Both should be so modified that a user can input on |
134 the console which Fibonacci number and which Factorial should |
136 the console which Fibonacci number and which Factorial should |
135 be calculated. The Fibonacci program is given in |
137 be calculated. The Fibonacci program is given in |
136 Figure~\ref{fibs}. You can write your own program for |
138 Figure~\ref{fibs}. You can write your own program for |
137 calculating factorials. |
139 calculating factorials. Submit your assembler code as |
|
140 a file that can be run, not as PDF-text. |
138 |
141 |
139 \begin{figure}[t] |
142 \begin{figure}[t] |
140 \lstinputlisting[language=while]{../progs/fib.while} |
143 \lstinputlisting[language=while]{../progs/fib.while} |
141 \caption{The Fibonacci program in the WHILE language.\label{fibs}} |
144 \caption{The Fibonacci program in the WHILE language.\label{fibs}} |
142 \end{figure} |
145 \end{figure} |