cws/pre_cw03.tex
author Christian Urban <christian.urban@kcl.ac.uk>
Wed, 25 Nov 2020 17:28:48 +0000
changeset 369 569aea2d052b
parent 367 e6ae724255a8
child 379 5616b45d656f
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
257
ba4d976ca88d updated
Christian Urban <urbanc@in.tum.de>
parents: 253
diff changeset
     1
% !TEX program = xelatex
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
\documentclass{article}
62
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 6
diff changeset
     3
\usepackage{../style}
78
85f2f75abeeb updated
Christian Urban <urbanc@in.tum.de>
parents: 75
diff changeset
     4
\usepackage{../langs}
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
     5
\usepackage{disclaimer}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
     6
\usepackage{tikz}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
     7
\usepackage{pgf}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
     8
\usepackage{pgfplots}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
     9
\usepackage{stackengine}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    10
%% \usepackage{accents}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    11
\newcommand\barbelow[1]{\stackunder[1.2pt]{#1}{\raisebox{-4mm}{\boldmath$\uparrow$}}}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    12
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
\begin{document}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    16
% BF IDE
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    17
% https://www.microsoft.com/en-us/p/brainf-ck/9nblgggzhvq5
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    18
  
356
d1046d9d3213 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 355
diff changeset
    19
\section*{Preliminary Part 3 (Scala, 3 Marks)}
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
275
eb1b4ad23941 updated
Christian Urban <urbanc@in.tum.de>
parents: 257
diff changeset
    21
\mbox{}\hfill\textit{``[Google’s MapReduce] abstraction is inspired by the}\\
eb1b4ad23941 updated
Christian Urban <urbanc@in.tum.de>
parents: 257
diff changeset
    22
\mbox{}\hfill\textit{map and reduce primitives present in Lisp and many}\\
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 311
diff changeset
    23
\mbox{}\hfill\textit{other functional languages.''}\smallskip\\
284
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    24
\mbox{}\hfill\textit{ --- Dean and Ghemawat, who designed this concept at Google}
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 311
diff changeset
    25
\bigskip
275
eb1b4ad23941 updated
Christian Urban <urbanc@in.tum.de>
parents: 257
diff changeset
    26
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 311
diff changeset
    27
\IMPORTANT{This part is about the shunting yard algorithm by Dijkstra.
355
bc3980949af2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 347
diff changeset
    28
  The preliminary part is due on \cwEIGHT{} at 5pm and worth 3\%.
bc3980949af2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 347
diff changeset
    29
  Any 1\% you achieve in the preliminary part counts as your
bc3980949af2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 347
diff changeset
    30
  ``weekly engagement''.}
62
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 6
diff changeset
    31
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 6
diff changeset
    32
\noindent
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    33
Also note that the running time of each part will be restricted to a
257
ba4d976ca88d updated
Christian Urban <urbanc@in.tum.de>
parents: 253
diff changeset
    34
maximum of 30 seconds on my laptop.  
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    35
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    36
\DISCLAIMER{}
86
f8a781322499 updated
Christian Urban <urbanc@in.tum.de>
parents: 79
diff changeset
    37
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
    38
\subsection*{Reference Implementation}
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
    39
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 311
diff changeset
    40
This Scala assignment comes with two reference implementations in
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 311
diff changeset
    41
form of \texttt{jar}-files. This allows
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 311
diff changeset
    42
you to run any test cases on your own computer. For example you can
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 311
diff changeset
    43
call Scala on the command line with the option \texttt{-cp
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 311
diff changeset
    44
  postfix.jar} and then query any function from the
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 311
diff changeset
    45
\texttt{postfix.scala} file (similarly for file \texttt{postfix2.scala}). As
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 311
diff changeset
    46
usual you have to prefix the calls with \texttt{CW8a} and
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 311
diff changeset
    47
\texttt{CW8b}, respectively.
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
    48
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
    49
245
975d34506e88 added marking
Christian Urban <urbanc@in.tum.de>
parents: 224
diff changeset
    50
\begin{lstlisting}[xleftmargin=1mm,numbers=none,basicstyle=\ttfamily\small]
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 311
diff changeset
    51
$ scala -cp postfix.jar
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 311
diff changeset
    52
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 311
diff changeset
    53
scala> CW8a.syard(CW8a.split("( 5 + 7 ) * 2"))
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 311
diff changeset
    54
val res0: CW8a.Toks = List(5, 7, +, 2, *)
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
    55
\end{lstlisting}%$
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 218
diff changeset
    56
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
367
e6ae724255a8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 356
diff changeset
    58
\subsection*{Hints}
e6ae724255a8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 356
diff changeset
    59
e6ae724255a8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 356
diff changeset
    60
\noindent
e6ae724255a8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 356
diff changeset
    61
\textbf{For the Preliminary Part:} useful operations for determining
e6ae724255a8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 356
diff changeset
    62
whether a string is a number are \texttt{.forall} and \texttt{.isDigit}.
e6ae724255a8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 356
diff changeset
    63
One way to calculate the the power operation is to use \texttt{.pow}
e6ae724255a8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 356
diff changeset
    64
on \texttt{BigInt}s, like \texttt{BigInt(n).pow(m).toInt}.
e6ae724255a8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 356
diff changeset
    65
\bigskip
e6ae724255a8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 356
diff changeset
    66
e6ae724255a8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 356
diff changeset
    67
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 311
diff changeset
    68
\subsection*{Preliminary Part (3 Marks, files postfix.scala, postfix2.scala)}
284
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    69
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    70
The \emph{Shunting Yard Algorithm} has been developed by Edsger Dijkstra,
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    71
an influential computer scientist who developed many well-known
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    72
algorithms. This algorithm transforms the usual infix notation of
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    73
arithmetic expressions into the postfix notation, sometimes also
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    74
called reverse Polish notation.
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    75
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    76
Why on Earth do people use the postfix notation? It is much more
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    77
convenient to work with the usual infix notation for arithmetic
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 311
diff changeset
    78
expressions. Most modern pocket calculators (as opposed to the ones used 20
284
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    79
years ago) understand infix notation. So why on Earth? \ldots{}Well,
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    80
many computers under the hood, even nowadays, use postfix notation
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    81
extensively. For example if you give to the Java compiler the
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    82
expression $1 + ((2 * 3) + (4 - 3))$, it will generate the Java Byte
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    83
code
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    84
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    85
\begin{lstlisting}[language=JVMIS,numbers=none]
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    86
ldc 1 
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    87
ldc 2 
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    88
ldc 3 
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    89
imul 
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    90
ldc 4 
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    91
ldc 3 
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    92
isub 
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    93
iadd 
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    94
iadd
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    95
\end{lstlisting}
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    96
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    97
\noindent
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    98
where the command \texttt{ldc} loads a constant onto the stack, and \texttt{imul},
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
    99
\texttt{isub} and \texttt{iadd} are commands acting on the stack. Clearly this
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   100
is the arithmetic expression in postfix notation.\bigskip
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   101
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   102
\noindent
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   103
The shunting yard algorithm processes an input token list using an
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   104
operator stack and an output list. The input consists of numbers,
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   105
operators ($+$, $-$, $*$, $/$) and parentheses, and for the purpose of
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   106
the assignment we assume the input is always a well-formed expression
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   107
in infix notation.  The calculation in the shunting yard algorithm uses
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   108
information about the
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   109
precedences of the operators (given in the template file). The
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   110
algorithm processes the input token list as follows:
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   111
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   112
\begin{itemize}
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   113
\item If there is a number as input token, then this token is
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   114
  transferred directly to the output list. Then the rest of the input is
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   115
  processed.
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   116
\item If there is an operator as input token, then you need to check
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   117
  what is on top of the operator stack. If there are operators with
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   118
  a higher or equal precedence, these operators are first popped off
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   119
  from the stack and moved to the output list. Then the operator from the input
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   120
  is pushed onto the stack and the rest of the input is processed.
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   121
\item If the input is a left-parenthesis, you push it on to the stack
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   122
  and continue processing the input.
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   123
\item If the input is a right-parenthesis, then you pop off all operators
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   124
  from the stack to the output list until you reach the left-parenthesis.
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   125
  Then you discharge the $($ and $)$ from the input and stack, and continue
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   126
  processing the input list.
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   127
\item If the input is empty, then you move all remaining operators
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   128
  from the stack to the output list.  
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   129
\end{itemize}  
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   130
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   131
\subsubsection*{Tasks (file postfix.scala)}
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   132
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   133
\begin{itemize}
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   134
\item[(1)] Implement the shunting yard algorithm described above. The
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   135
  function, called \texttt{syard}, takes a list of tokens as first
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   136
  argument. The second and third arguments are the stack and output
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   137
  list represented as Scala lists. The most convenient way to
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   138
  implement this algorithm is to analyse what the input list, stack
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   139
  and output list look like in each step using pattern-matching. The
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   140
  algorithm transforms for example the input
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   141
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   142
  \[
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   143
  \texttt{List(3, +, 4, *, (, 2, -, 1, ))}
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   144
  \]
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   145
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   146
  into the postfix output
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   147
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   148
  \[
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   149
  \texttt{List(3, 4, 2, 1, -, *, +)}
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   150
  \]  
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   151
  
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   152
  You can assume the input list is always a  list representing
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   153
  a well-formed infix arithmetic expression.\hfill[1 Mark]
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   154
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   155
\item[(2)] Implement a compute function that takes a postfix expression
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   156
  as argument and evaluates it generating an integer as result. It uses a
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   157
  stack to evaluate the postfix expression. The operators $+$, $-$, $*$
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   158
  are as usual; $/$ is division on integers, for example $7 / 3 = 2$.
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   159
  \hfill[1 Mark]
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   160
\end{itemize}
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   161
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   162
\subsubsection*{Task (file postfix2.scala)}
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   163
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   164
\begin{itemize}
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 311
diff changeset
   165
\item[(3/4)] Extend the code in (1) and (2) to include the power
284
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   166
  operator.  This requires proper account of associativity of
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   167
  the operators. The power operator is right-associative, whereas the
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   168
  other operators are left-associative.  Left-associative operators
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   169
  are popped off if the precedence is bigger or equal, while
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   170
  right-associative operators are only popped off if the precedence is
347
4de31fdc0d67 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 311
diff changeset
   171
  bigger.\hfill[1 Marks]
284
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   172
\end{itemize}
9a04eb6a2291 updated
Christian Urban <urbanc@in.tum.de>
parents: 275
diff changeset
   173
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
\end{document}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
68
8da9e0c16194 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   176
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
%%% Local Variables: 
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
%%% mode: latex
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
%%% TeX-master: t
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
%%% End: