cws/cw04.tex
author Christian Urban <christian.urban@kcl.ac.uk>
Fri, 11 Oct 2024 19:13:00 +0100
changeset 967 ce5de01b9632
parent 959 64ec1884d860
child 974 0cb4bf2469d1
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
630
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
     1
% !TEX program = xelatex
200
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
\documentclass{article}
309
640e4a05cd9b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 298
diff changeset
     3
\usepackage{../style}
216
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 214
diff changeset
     4
\usepackage{../langs}
200
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
\begin{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
354
86b2aeae3e98 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 333
diff changeset
     8
%https://github.com/Storyyeller/Krakatau
86b2aeae3e98 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 333
diff changeset
     9
%https://docs.oracle.com/javase/specs/jvms/se7/html/
86b2aeae3e98 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 333
diff changeset
    10
706
b560f78781b9 updated
Christian Urban <urbanc@in.tum.de>
parents: 630
diff changeset
    11
% Jasmin Tutorial
b560f78781b9 updated
Christian Urban <urbanc@in.tum.de>
parents: 630
diff changeset
    12
%http://saksagan.ceng.metu.edu.tr/courses/ceng444/link/jvm-cpm.html
b560f78781b9 updated
Christian Urban <urbanc@in.tum.de>
parents: 630
diff changeset
    13
751
4b208d81e002 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 748
diff changeset
    14
\section*{Coursework 4}
200
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
836
a3418ee8c404 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 823
diff changeset
    16
\noindent This coursework is worth 15\% and is due on \cwFOUR{}
877
43460c7b2010 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 859
diff changeset
    17
at 16:00. You are asked to implement a compiler for
309
640e4a05cd9b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 298
diff changeset
    18
the WHILE language that targets the assembler language
823
bde572a54112 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 752
diff changeset
    19
provided by Jasmin or Krakatau (both have a very similar
bde572a54112 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 752
diff changeset
    20
syntax). Please submit your answers to the questions
bde572a54112 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 752
diff changeset
    21
below as PDF. You can do the implementation in any programming
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
    22
language you like, but you need to submit the source code with
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
    23
which you answered the questions, otherwise a mark of 0\% will
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
    24
be awarded. You should use the lexer and parser from the
952
33b3e790e1d4 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 951
diff changeset
    25
previous courseworks. Implement your compiler in the file \texttt{cw04.sc}.
920
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
    26
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
    27
%Please package \emph{everything}(!) in
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
    28
%a zip-file that creates a directory with the name
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
    29
%\texttt{YournameYourFamilyname} on my end.
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 354
diff changeset
    30
751
4b208d81e002 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 748
diff changeset
    31
\subsection*{Disclaimer\alert}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 354
diff changeset
    32
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 354
diff changeset
    33
It should be understood that the work you submit represents
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 354
diff changeset
    34
your own effort. You have not copied from anyone else. An
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 354
diff changeset
    35
exception is the Scala code I showed during the lectures,
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 354
diff changeset
    36
which you can use. You can also use your own code from the
886
8a8d87394608 texupdate
Christian Urban <christian.urban@kcl.ac.uk>
parents: 877
diff changeset
    37
CW~1, CW~2 and CW~3. But do not
8a8d87394608 texupdate
Christian Urban <christian.urban@kcl.ac.uk>
parents: 877
diff changeset
    38
be tempted to ask Github Copilot for help or do any other
8a8d87394608 texupdate
Christian Urban <christian.urban@kcl.ac.uk>
parents: 877
diff changeset
    39
shenanigans like this!
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 354
diff changeset
    40
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 354
diff changeset
    41
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
    42
\subsection*{Jasmin Assembler}
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 354
diff changeset
    43
951
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
    44
For this coursework you will need an assembler. 
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 354
diff changeset
    45
The Jasmin assembler is available from
201
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    46
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    47
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    48
\url{http://jasmin.sourceforge.net}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    49
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    50
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    51
\noindent
951
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
    52
This is a jar-file you can run on the commandline.
201
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    53
There is a user guide for Jasmin
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    54
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    55
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    56
\url{http://jasmin.sourceforge.net/guide.html}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    57
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    58
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
    59
\noindent and also a description of some of the instructions
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
    60
that the JVM understands
201
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    61
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    62
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    63
\url{http://jasmin.sourceforge.net/instructions.html}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    64
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    65
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
    66
\noindent If you generated a correct assembler file for
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
    67
Jasmin, for example \texttt{loops.j}, you can use
200
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
205
0b59588d28d2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
    69
\begin{center}
951
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
    70
\texttt{java -jar jasmin.jar loops.j}
205
0b59588d28d2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
    71
\end{center}
0b59588d28d2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
    72
852
8706b846a3e0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 836
diff changeset
    73
\noindent in order to translate it into Java Byte Code. If needed, you
8706b846a3e0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 836
diff changeset
    74
need to give the path to the Jasmin jar-file.  The resulting class
8706b846a3e0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 836
diff changeset
    75
file can be run with
205
0b59588d28d2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
    76
0b59588d28d2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
    77
\begin{center}
0b59588d28d2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
    78
\texttt{java loops}
0b59588d28d2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
    79
\end{center}
0b59588d28d2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
    80
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
    81
\noindent where you might need to give the correct path to the
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
    82
class file. For example:
322
698ed1c96cd0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 321
diff changeset
    83
698ed1c96cd0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 321
diff changeset
    84
\begin{center}
698ed1c96cd0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 321
diff changeset
    85
\texttt{java -cp . loops/loops}
698ed1c96cd0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 321
diff changeset
    86
\end{center}
698ed1c96cd0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 321
diff changeset
    87
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
    88
\noindent There are also other resources about Jasmin on the
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
    89
Internet, for example
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
    90
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
    91
\begin{center}
836
a3418ee8c404 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 823
diff changeset
    92
\small\url{https://saksagan.ceng.metu.edu.tr/courses/ceng444/link/f3jasmintutorial.html}
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
    93
\end{center}
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
    94
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
    95
\noindent and
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
    96
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
    97
\begin{center}
905
15973df32613 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 900
diff changeset
    98
  \small\url{http://www.csc.villanova.edu/~tway/courses/csc4181/s2022/labs/finalproject/JVM.pdf}
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
    99
\end{center}
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   100
951
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   101
\noindent
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   102
If possible use Jasmin for the coursework. The Krakatau assembler
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   103
below as a slightly different syntax.
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   104
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   105
959
64ec1884d860 updated and added pascal.while file
Christian Urban <christian.urban@kcl.ac.uk>
parents: 952
diff changeset
   106
\subsection*{Krakatau Assembler (Version 1 \& 2)}
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   107
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   108
The Krakatau assembler is available from
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   109
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   110
\begin{center}
951
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   111
  \url{https://github.com/Storyyeller/Krakatau/tree/master}
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   112
\end{center}
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   113
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   114
\noindent This assembler requires Python and a package called
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   115
\pcode{ply} available from
313
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   116
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   117
\begin{center}
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   118
\url{https://pypi.python.org/pypi/ply}
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   119
\end{center}
313
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   120
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   121
\noindent This assembler is largely compatible with the Jasmin
959
64ec1884d860 updated and added pascal.while file
Christian Urban <christian.urban@kcl.ac.uk>
parents: 952
diff changeset
   122
syntax---that means for the files we are concerned with here, it
64ec1884d860 updated and added pascal.while file
Christian Urban <christian.urban@kcl.ac.uk>
parents: 952
diff changeset
   123
understands the same input syntax (no changes to your compiler need to
64ec1884d860 updated and added pascal.while file
Christian Urban <christian.urban@kcl.ac.uk>
parents: 952
diff changeset
   124
be made; ok maybe some small syntactic adjustments are needed, for
64ec1884d860 updated and added pascal.while file
Christian Urban <christian.urban@kcl.ac.uk>
parents: 952
diff changeset
   125
example labels need to start with a capital '\texttt{L}'). You can generate Java
64ec1884d860 updated and added pascal.while file
Christian Urban <christian.urban@kcl.ac.uk>
parents: 952
diff changeset
   126
Byte Code by using
313
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   127
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   128
\begin{center}
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   129
\texttt{python Krakatau-master/assemble.py loops.j}
313
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   130
\end{center}
200
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   131
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   132
\noindent where you may have to adapt the directory where
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   133
Krakatau is installed (I just downloaded the zip file from
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   134
Github and \pcode{Krakatau-master} was the directory where it
473
dc528091eb70 updated
Christian Urban <urbanc@in.tum.de>
parents: 428
diff changeset
   135
was installed). Again the resulting class-file you can run with
951
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   136
\texttt{java}. There is also a newer version of Krakatau available at
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   137
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   138
\begin{center}
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   139
\url{https://github.com/Storyyeller/Krakatau/tree/v2}
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   140
\end{center}
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   141
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   142
\noindent
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   143
This is now a Rust program using Cargo as package manager (I have not tried this
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   144
version---I assume it should produce the same output, but might be
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   145
easier to install because it avoids Python's \emph{dependency hell}).
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   146
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   147
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   148
%\noindent You need to submit a document containing the answers
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   149
%for the two questions below. You can do the implementation in
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   150
%any programming language you like, but you need to submit the
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   151
%source code with which you answered the questions. Otherwise
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   152
%the submission will not be counted. However, the coursework
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   153
%will \emph{only} be judged according to the answers. You can
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   154
%submit your answers in a txt-file or as pdf.\bigskip
200
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   155
920
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   156
%\subsection*{Question 0 (Unmarked)}
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   157
%
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   158
%Please include  in the PDF at the beginning your email address, your student
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   159
%number and whether you are BSc / MSci student and for the latter in which
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   160
%year your are in. Thanks! 
200
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   161
419
4110ab35e5d8 updated courseworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 391
diff changeset
   162
\subsection*{Question 1}
200
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   163
959
64ec1884d860 updated and added pascal.while file
Christian Urban <christian.urban@kcl.ac.uk>
parents: 952
diff changeset
   164
You need to lex and parse WHILE programs, and then generate Java Byte
64ec1884d860 updated and added pascal.while file
Christian Urban <christian.urban@kcl.ac.uk>
parents: 952
diff changeset
   165
Code instructions for the Jasmin assembler (or Krakatau
64ec1884d860 updated and added pascal.while file
Christian Urban <christian.urban@kcl.ac.uk>
parents: 952
diff changeset
   166
assembler). For this you should use the ASTs defined in CW3 (including
64ec1884d860 updated and added pascal.while file
Christian Urban <christian.urban@kcl.ac.uk>
parents: 952
diff changeset
   167
logical operators). As part of the solution you need to submit the assembler
64ec1884d860 updated and added pascal.while file
Christian Urban <christian.urban@kcl.ac.uk>
parents: 952
diff changeset
   168
instructions for the Fibonacci and Factorial programs. Both should be
64ec1884d860 updated and added pascal.while file
Christian Urban <christian.urban@kcl.ac.uk>
parents: 952
diff changeset
   169
so modified that a user can input on the console which Fibonacci
64ec1884d860 updated and added pascal.while file
Christian Urban <christian.urban@kcl.ac.uk>
parents: 952
diff changeset
   170
number and which Factorial should be calculated. The Fibonacci program
64ec1884d860 updated and added pascal.while file
Christian Urban <christian.urban@kcl.ac.uk>
parents: 952
diff changeset
   171
is given in Figure~\ref{fibs}. You can write your own program for
64ec1884d860 updated and added pascal.while file
Christian Urban <christian.urban@kcl.ac.uk>
parents: 952
diff changeset
   172
calculating factorials. Submit your assembler code as a file that can
64ec1884d860 updated and added pascal.while file
Christian Urban <christian.urban@kcl.ac.uk>
parents: 952
diff changeset
   173
be run, not as PDF-text.
200
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   174
313
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   175
\begin{figure}[t]
852
8706b846a3e0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 836
diff changeset
   176
\lstinputlisting[language=while]{../cwtests/cw04/fib.while}
320
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 313
diff changeset
   177
\caption{The Fibonacci program in the WHILE language.\label{fibs}}
313
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   178
\end{figure}
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   179
419
4110ab35e5d8 updated courseworks
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 391
diff changeset
   180
\subsection*{Question 2}
201
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   181
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   182
Extend the syntax of your language so that it contains also
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   183
\texttt{for}-loops, like
201
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   184
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   185
\begin{center}
391
f352cb238c32 updated meaning of for-loop
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 390
diff changeset
   186
\lstset{language=While}
f352cb238c32 updated meaning of for-loop
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 390
diff changeset
   187
\code{for} \;\textit{Id} \texttt{:=} \textit{AExp}\; \code{upto} 
f352cb238c32 updated meaning of for-loop
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 390
diff changeset
   188
\;\textit{AExp}\; \code{do} \textit{Block} 
201
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   189
\end{center}
200
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   190
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   191
\noindent The intended meaning is to first assign the variable
951
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   192
\textit{Id} the value of the first arithmetic expression, then test
598
e3ad67cd5123 updated
Christian Urban <urbanc@in.tum.de>
parents: 567
diff changeset
   193
whether this value is less or equal than the value of the
391
f352cb238c32 updated meaning of for-loop
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 390
diff changeset
   194
second arithmetic expression. If yes, go through the loop, and
f352cb238c32 updated meaning of for-loop
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 390
diff changeset
   195
at the end increase the value of the loop variable by 1 and
f352cb238c32 updated meaning of for-loop
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 390
diff changeset
   196
start again with the test. If no, leave the loop. For example
f352cb238c32 updated meaning of for-loop
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 390
diff changeset
   197
the following instance of a \code{for}-loop is supposed to
f352cb238c32 updated meaning of for-loop
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 390
diff changeset
   198
print out the numbers \pcode{2}, \pcode{3}, \pcode{4}.
202
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 201
diff changeset
   199
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 201
diff changeset
   200
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 201
diff changeset
   201
\begin{center}
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   202
\begin{minipage}{12cm}
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   203
\begin{lstlisting}[language=While, numbers=none]
202
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 201
diff changeset
   204
for i := 2 upto 4 do {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 201
diff changeset
   205
    write i	
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 201
diff changeset
   206
}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 201
diff changeset
   207
\end{lstlisting}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 201
diff changeset
   208
\end{minipage}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 201
diff changeset
   209
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 201
diff changeset
   210
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   211
\noindent There are two ways how this can be implemented: one
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   212
is to adapt the code generation part of the compiler and
391
f352cb238c32 updated meaning of for-loop
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 390
diff changeset
   213
generate specific code for \code{for}-loops; the other is to
f352cb238c32 updated meaning of for-loop
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 390
diff changeset
   214
translate the abstract syntax tree of \code{for}-loops into
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   215
an abstract syntax tree using existing language constructs.
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   216
For example the loop above could be translated to the
391
f352cb238c32 updated meaning of for-loop
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 390
diff changeset
   217
following \code{while}-loop:
203
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 202
diff changeset
   218
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 202
diff changeset
   219
\begin{center}
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   220
\begin{minipage}{12cm}
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   221
\begin{lstlisting}[language=While, numbers=none]
203
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 202
diff changeset
   222
i := 2;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 202
diff changeset
   223
while (i <= 4) do {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 202
diff changeset
   224
    write i;
905
15973df32613 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 900
diff changeset
   225
    i := i + 1
203
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 202
diff changeset
   226
}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 202
diff changeset
   227
\end{lstlisting}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 202
diff changeset
   228
\end{minipage}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 202
diff changeset
   229
\end{center}
202
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 201
diff changeset
   230
630
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 607
diff changeset
   231
\subsection*{Question 3}
333
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   232
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   233
\noindent In this question you are supposed to give the
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   234
assembler instructions for the program
205
0b59588d28d2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   235
0b59588d28d2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   236
\begin{center}
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   237
\begin{minipage}{12cm}
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   238
\begin{lstlisting}[language=While, numbers=none]
333
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   239
for i := 1 upto 10 do {
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   240
  for i := 1 upto 10 do {
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   241
    write i
205
0b59588d28d2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   242
  }
0b59588d28d2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   243
} 
0b59588d28d2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   244
\end{lstlisting}
0b59588d28d2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   245
\end{minipage}
0b59588d28d2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   246
\end{center}
0b59588d28d2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   247
313
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   248
\noindent 
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   249
Note that in this program the variable \pcode{i} is used
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   250
twice. You need to make a decision how it should be compiled?
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   251
Explain your decision and indicate what this program would
952
33b3e790e1d4 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 951
diff changeset
   252
print out. Give your answer in the file \texttt{q3-answer.txt}.
202
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 201
diff changeset
   253
920
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   254
\subsection*{Question 4}
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   255
943
5365ef60707e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 920
diff changeset
   256
Extend the lexer and parser to add a \textcolor{codepurple}{\pcode{break}} keyword.  Modify
5365ef60707e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 920
diff changeset
   257
the compiler (including lexer and parser) such that when a \textcolor{codepurple}{\texttt{break}}-statement is encountered
959
64ec1884d860 updated and added pascal.while file
Christian Urban <christian.urban@kcl.ac.uk>
parents: 952
diff changeset
   258
the code should jump out of the ``enclosing'' for/while-loop, or in case it
64ec1884d860 updated and added pascal.while file
Christian Urban <christian.urban@kcl.ac.uk>
parents: 952
diff changeset
   259
is not inside such a loop to the end of the program. For example the
920
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   260
program
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   261
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   262
\begin{center}
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   263
\begin{minipage}{12cm}
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   264
\begin{lstlisting}[language=While, numbers=none]
943
5365ef60707e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 920
diff changeset
   265
// should print 0 .. 10    
920
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   266
for i := 0 upto 10 do {
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   267
  write i;
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   268
  write "\n"
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   269
};
910
b655ce68983f added break
Christian Urban <christian.urban@kcl.ac.uk>
parents: 905
diff changeset
   270
943
5365ef60707e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 920
diff changeset
   271
// should print 0 .. 4  
920
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   272
for i := 0 upto 10 do {
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   273
  if i > 4 then break else skip;
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   274
  write i;
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   275
  write "\n"
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   276
};
910
b655ce68983f added break
Christian Urban <christian.urban@kcl.ac.uk>
parents: 905
diff changeset
   277
920
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   278
write "Should print\n";
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   279
break;
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   280
write "Should not print\n"
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   281
\end{lstlisting}
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   282
\end{minipage}
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   283
\end{center}
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   284
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   285
\noindent
951
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   286
should print out 0 to 10 with the first for-loop, but only 0
920
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   287
to 4 in the second. Similarly it should print out \code{"Should print"},
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   288
but not \code{"Should not print"}. For this you need to add
959
64ec1884d860 updated and added pascal.while file
Christian Urban <christian.urban@kcl.ac.uk>
parents: 952
diff changeset
   289
a label to the end of every for- and while-loop and also to the end of the
920
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   290
whole program just in case you need to jump to that label via a
952
33b3e790e1d4 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 951
diff changeset
   291
\code{break}. The file you need to be able to process for this question
33b3e790e1d4 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 951
diff changeset
   292
is called \texttt{break.while}.
920
7af2eea19646 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 910
diff changeset
   293
910
b655ce68983f added break
Christian Urban <christian.urban@kcl.ac.uk>
parents: 905
diff changeset
   294
204
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   295
\subsection*{Further Information}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   296
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   297
The Java infrastructure unfortunately does not contain an
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   298
assembler out-of-the-box (therefore you need to download the
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   299
additional package Jasmin or Krakatau---see above). But it
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   300
does contain a disassembler, called \texttt{javap}. A
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   301
dissembler does the ``opposite'' of an assembler: it generates
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   302
readable assembler code from Java Byte Code. Have a look at
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   303
the following example: Compile using the usual Java compiler
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   304
the simple Hello World program below:
204
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   305
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   306
\begin{center}
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   307
\begin{minipage}{12cm}
313
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   308
\begin{lstlisting}[language=Java,numbers=none]
204
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   309
class HelloWorld {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   310
    public static void main(String[] args) {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   311
        System.out.println("Hello World!");
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   312
    }
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   313
}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   314
\end{lstlisting}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   315
\end{minipage}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   316
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   317
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   318
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   319
You can use the command
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   320
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   321
\begin{center}
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   322
\begin{minipage}{12cm}
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   323
\begin{lstlisting}[language={},numbers=none]
951
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   324
javap -c HelloWorld
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   325
\end{lstlisting}
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   326
\end{minipage}
204
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   327
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   328
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   329
\noindent to see the assembler instructions of the Java Byte
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   330
Code that has been generated for this program. You can compare
313
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   331
this with the code generated for the Scala version of Hello
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   332
World.
204
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   333
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   334
\begin{center}
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   335
\begin{minipage}{12cm}
313
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   336
\begin{lstlisting}[language=Scala,numbers=none]
204
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   337
object HelloWorld {
951
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   338
   def main(args: Array[String]) = {
204
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   339
      println("Hello World!")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   340
  }
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   341
}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   342
\end{lstlisting}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   343
\end{minipage}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   344
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 203
diff changeset
   345
222
b712519b41d3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 216
diff changeset
   346
210
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   347
\subsection*{Library Functions}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   348
313
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   349
You need to generate code for the commands \texttt{write} and
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   350
\texttt{read}. This will require the addition of some
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   351
``library'' functions to your generated code. The first
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   352
command even needs two versions, because you need to write out
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   353
an integer and string. The Java byte code will need two
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   354
separate functions for this. For writing out an integer, you
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   355
can use the assembler code
210
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   356
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   357
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   358
\begin{minipage}{12cm}
313
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   359
\begin{lstlisting}[language=JVMIS, numbers=none]
210
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   360
.method public static write(I)V 
859
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   361
  .limit locals 1 
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   362
  .limit stack 2  
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   363
  getstatic java/lang/System/out Ljava/io/PrintStream; 
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   364
  iload 0
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   365
  invokevirtual java/io/PrintStream/println(I)V 
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   366
  return 
210
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   367
.end method
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   368
\end{lstlisting}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   369
\end{minipage}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   370
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   371
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   372
\noindent This function will invoke Java's \texttt{println}
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   373
function for integers. Then if you need to generate code for
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   374
\texttt{write x} where \texttt{x} is an integer variable, you
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   375
can generate
210
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   376
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   377
\begin{center}
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   378
\begin{minipage}{12cm}
313
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   379
\begin{lstlisting}[language=JVMIS, numbers=none]
210
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   380
iload n 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   381
invokestatic XXX/XXX/write(I)V
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   382
\end{lstlisting}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   383
\end{minipage}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   384
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   385
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   386
\noindent where \texttt{n} is the index where the value of the
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   387
variable \texttt{x} is stored. The \texttt{XXX/XXX} needs to
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   388
be replaced with the class name which you use to generate the
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   389
code (for example \texttt{fib/fib} in case of the Fibonacci
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   390
numbers).
210
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   391
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   392
Writing out a string is similar. The corresponding library
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   393
function uses strings instead of integers:
210
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   394
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   395
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   396
\begin{minipage}{12cm}
313
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   397
\begin{lstlisting}[language=JVMIS, numbers=none]
210
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   398
.method public static writes(Ljava/lang/String;)V
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   399
   .limit stack 2
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   400
   .limit locals 1
210
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   401
   getstatic java/lang/System/out Ljava/io/PrintStream;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   402
   aload 0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   403
   invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   404
   return
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   405
.end method
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   406
\end{lstlisting}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   407
\end{minipage}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   408
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   409
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   410
\noindent The code that needs to be generated for \code{write
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   411
"some_string"} commands is
210
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   412
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   413
\begin{center}
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   414
\begin{minipage}{12cm}
313
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   415
\begin{lstlisting}[language=JVMIS,numbers=none]
210
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   416
ldc "some_string"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   417
invokestatic XXX/XXX/writes(Ljava/lang/String;)V
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   418
\end{lstlisting}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   419
\end{minipage}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   420
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 205
diff changeset
   421
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   422
\noindent Again you need to adjust the \texttt{XXX/XXX} part
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   423
in each call.
202
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 201
diff changeset
   424
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   425
The code for \texttt{read} is more complicated. The reason is
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   426
that inputting a string will need to be transformed into an
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   427
integer. The code in Figure~\ref{read} does this. It can be
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   428
called with
214
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 213
diff changeset
   429
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 213
diff changeset
   430
\begin{center}
390
a1fe591a3df3 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 373
diff changeset
   431
\begin{minipage}{12cm}
313
90ccc385c547 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   432
\begin{lstlisting}[language=JVMIS,numbers=none]
214
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 213
diff changeset
   433
invokestatic XXX/XXX/read()I 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 213
diff changeset
   434
istore n
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 213
diff changeset
   435
\end{lstlisting}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 213
diff changeset
   436
\end{minipage}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 213
diff changeset
   437
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 213
diff changeset
   438
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 213
diff changeset
   439
\noindent 
951
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   440
where \texttt{n} is the index of the variable that requires an input.
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   441
%If you
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   442
%use Windows you need to take into account that a ``return'' is not just a newline,
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   443
%\code{'\\10'}, but \code{'\\13\\10'}. This means you need to change line~12 in 
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   444
%Figure~\ref{read} to \pcode{ldc 13}.  
214
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 213
diff changeset
   445
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 213
diff changeset
   446
321
c5850f8f3f5e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 320
diff changeset
   447
\begin{figure}[t]\small
540
86f1acf60df3 updated
Christian Urban <urbanc@in.tum.de>
parents: 499
diff changeset
   448
\begin{lstlisting}[language=JVMIS,numbers=left]
214
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 213
diff changeset
   449
.method public static read()I 
859
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   450
    .limit locals 10 
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   451
    .limit stack 10
214
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 213
diff changeset
   452
859
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   453
    ldc 0 
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   454
    istore 1  ; this will hold our final integer 
214
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 213
diff changeset
   455
Label1: 
859
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   456
    getstatic java/lang/System/in Ljava/io/InputStream; 
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   457
    invokevirtual java/io/InputStream/read()I 
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   458
    istore 2 
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   459
    iload 2 
951
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   460
    ldc 10  ; test for the newline delimiter for Unix
859
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   461
    isub 
951
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   462
    ifeq Label2
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   463
    iload 2
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   464
    ldc 13  ; test for the carriage-return in Windows 
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   465
    isub
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   466
    ifeq Label2
859
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   467
    iload 2 
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   468
    ldc 32   ; the space delimiter 
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   469
    isub 
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   470
    ifeq Label2
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   471
    iload 2 
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   472
    ldc 48   ; we have our digit in ASCII, have to subtract it from 48 
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   473
    isub 
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   474
    ldc 10 
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   475
    iload 1 
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   476
    imul 
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   477
    iadd 
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   478
    istore 1 
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   479
    goto Label1 
214
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 213
diff changeset
   480
Label2: 
859
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   481
    ; when we come here we have our integer computed
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   482
    ; in local variable 1 
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   483
    iload 1 
f766d3486c9d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 852
diff changeset
   484
    ireturn 
214
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 213
diff changeset
   485
.end method
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 213
diff changeset
   486
\end{lstlisting}\normalsize
951
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   487
\caption{Assembler code for reading an integer from the console.
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   488
  This code is portable for Unix and Windows (see Lines 11--18 for 2 separate
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   489
  tests for the various end-of-line markers). Thanks to Harry
9e7147f33219 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 943
diff changeset
   490
  Dilnot to make it portable.\label{read}}
214
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 213
diff changeset
   491
\end{figure}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 213
diff changeset
   492
200
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   493
\end{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   494
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   495
%%% Local Variables: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   496
%%% mode: latex
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   497
%%% TeX-master: t
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   498
%%% End: