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