coursework/cw03.tex
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Sat, 23 Nov 2013 09:17:59 +0000
changeset 201 c813506e0ee8
parent 200 7415871b1ef5
child 202 180cbfc1520a
permissions -rw-r--r--
added
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
200
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
\documentclass{article}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
\usepackage{charter}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
\usepackage{hyperref}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
\usepackage{amssymb}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
\usepackage{amsmath}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
\usepackage{listings}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
\usepackage{xcolor}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
\begin{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
\definecolor{javared}{rgb}{0.6,0,0} % for strings
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
\definecolor{javagreen}{rgb}{0.25,0.5,0.35} % comments
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
\definecolor{javapurple}{rgb}{0.5,0,0.35} % keywords
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
\definecolor{javadocblue}{rgb}{0.25,0.35,0.75} % javadoc
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
\lstdefinelanguage{scala}{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
  morekeywords={abstract,case,catch,class,def,%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
    do,else,extends,false,final,finally,%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
    for,if,implicit,import,match,mixin,%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
    new,null,object,override,package,%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
    private,protected,requires,return,sealed,%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
    super,this,throw,trait,true,try,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
    type,val,var,while,with,yield},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
  otherkeywords={=>,<-,<\%,<:,>:,\#,@},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
  sensitive=true,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
  morecomment=[l]{//},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
  morecomment=[n]{/*}{*/},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
  morestring=[b]",
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
  morestring=[b]',
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
  morestring=[b]"""
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
\lstdefinelanguage{while}{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
  morekeywords={while, if, then. else, read, write},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
  otherkeywords={=>,<-,<\%,<:,>:,\#,@},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
  sensitive=true,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
  morecomment=[l]{//},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
  morecomment=[n]{/*}{*/},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
  morestring=[b]",
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
  morestring=[b]',
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
  morestring=[b]"""
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
\lstset{language=Scala,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
	basicstyle=\ttfamily,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
	keywordstyle=\color{javapurple}\bfseries,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
	stringstyle=\color{javagreen},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
	commentstyle=\color{javagreen},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
	morecomment=[s][\color{javadocblue}]{/**}{*/},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
	numbers=left,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
	numberstyle=\tiny\color{black},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
	stepnumber=1,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
	numbersep=10pt,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
	tabsize=2,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
	showspaces=false,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
	showstringspaces=false}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
\section*{Coursework 3}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
This coursework is worth 4\% and is due on 13 December at 16:00. You are asked to 
201
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    67
implement a compiler for the WHILE language which targets the
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    68
assembler language provided by the Jasmin. This assembler 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    69
is available from
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    70
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    71
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    72
\url{http://jasmin.sourceforge.net}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    73
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    74
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    75
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    76
There is a user guide for Jasmin
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    77
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    78
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    79
\url{http://jasmin.sourceforge.net/guide.html}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    80
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    81
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    82
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    83
and also a description of some of the instructions that the JVM understands
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    84
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    85
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    86
\url{http://jasmin.sourceforge.net/instructions.html}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    87
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    88
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    89
\noindent
200
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    90
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
\noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
You need to submit a document containing the answers for the questions 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    94
below. You can do the implementation in any programming language you like, but you need 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
to submit the source code with which you answered the questions. However, the coursework 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
will \emph{only} be judged according to the answers. You can submit your answers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
in a txt-file or as pdf.\bigskip
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    98
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    99
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   100
\subsection*{Question 1 (marked with 1\%)}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   101
201
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   102
You need to lex and parse WHILE programs and submit the assembler 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   103
instructions for the Fibonacci program and for the program you submitted
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   104
in Coursework 2 in Question 3. The latter should be so modified that 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   105
a user can input the upper bound on the console (in the original question
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   106
it was fixed to 100).
200
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   107
201
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   108
\subsection*{Question 2 (marked with 2\%)}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   109
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   110
Extend the syntax of you language so that it contains also \texttt{for}-loops, like
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   111
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   112
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   113
\texttt{for} \;\textit{Id} \texttt{:=} \textit{AExp}\; \texttt{upto} \;\textit{AExp}\; \texttt{do} \textit{Block} 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   114
\end{center}
200
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   115
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   116
\end{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   117
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   118
%%% Local Variables: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   119
%%% mode: latex
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   120
%%% TeX-master: t
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   121
%%% End: