# HG changeset patch # User Christian Urban # Date 1598960647 -3600 # Node ID e93a9e74ca8ed3851a72a22e24fd36718be3c892 # Parent bb2335a5ca5868f40d74072a5ca508f2e9eb51c6 updated diff -r bb2335a5ca58 -r e93a9e74ca8e coursework/cw01.pdf Binary file coursework/cw01.pdf has changed diff -r bb2335a5ca58 -r e93a9e74ca8e coursework/cw01.tex --- a/coursework/cw01.tex Mon Aug 31 18:15:12 2020 +0100 +++ b/coursework/cw01.tex Tue Sep 01 12:44:07 2020 +0100 @@ -25,7 +25,7 @@ -\subsubsection*{Disclaimer} +\subsubsection*{Disclaimer\alert} It should be understood that the work you submit represents your own effort. You have not copied from anyone else. An diff -r bb2335a5ca58 -r e93a9e74ca8e coursework/cw02.pdf Binary file coursework/cw02.pdf has changed diff -r bb2335a5ca58 -r e93a9e74ca8e coursework/cw02.tex --- a/coursework/cw02.tex Mon Aug 31 18:15:12 2020 +0100 +++ b/coursework/cw02.tex Tue Sep 01 12:44:07 2020 +0100 @@ -16,7 +16,7 @@ submit as code. Please package everything in a zip-file that creates a directory with the name \texttt{YournameYourfamilyname} on my end. Thanks! -\subsection*{Disclaimer} +\subsection*{Disclaimer\alert} It should be understood that the work you submit represents your own effort. You have not copied from anyone else. An diff -r bb2335a5ca58 -r e93a9e74ca8e coursework/cw03.pdf Binary file coursework/cw03.pdf has changed diff -r bb2335a5ca58 -r e93a9e74ca8e coursework/cw03.tex --- a/coursework/cw03.tex Mon Aug 31 18:15:12 2020 +0100 +++ b/coursework/cw03.tex Tue Sep 01 12:44:07 2020 +0100 @@ -7,11 +7,9 @@ \section*{Coursework 3} -TODO: Testcases for expressions -\url{https://github.com/ArashPartow/math-parser-benchmark-project} -\noindent This coursework is worth 5\% and is due on \cwTHREE{} at +\noindent This coursework is worth 10\% and is due on \cwTHREE{} at 18:00. You are asked to implement a parser for the WHILE language and also an interpreter. You can do the implementation in any programming language you like, but you need to submit the source code with which @@ -20,13 +18,13 @@ parser. Please package everything(!) in a zip-file that creates a directory with the name \texttt{YournameYourFamilyname} on my end. -\subsection*{Disclaimer} +\subsection*{Disclaimer\alert} -It should be understood that the work you submit represents -your own effort. You have not copied from anyone else. An -exception is the Scala code I showed during the lectures, -which you can use. You can also use your own code from the -CW~1 and CW~2. +It should be understood that the work you submit represents your own +effort. You have not copied from anyone else. An exception is the +Scala code I showed during the lectures or uploaded to KEATS, which +you can both use. You can also use your own code from the CW~1 and +CW~2. \subsection*{Question 1} @@ -54,22 +52,21 @@ You should implement a parser for the WHILE language using parser combinators. Be careful that the parser takes as input a stream, or -list, of tokens generated by the tokenizer from the previous +list, of \emph{tokens} generated by the tokenizer from the previous coursework. For this you might want to filter out whitespaces and comments. Your parser should be able to handle the WHILE programs in -Figures~\ref{fib}, \ref{loop} and \ref{primes} (if your lexer cannot -deal with comments you can delete them from the prime number program). -In addition give the parse tree for the statement: +Figures~\ref{fib}, \ref{loop} and \ref{primes}. In addition give the +parse tree for the statement: \begin{lstlisting}[language=While,numbers=none] if (a < b) then skip else a := a * b + 1 \end{lstlisting} \noindent -A (possibly incomplete) datatype for parse trees in Scala would -look as in Figure~\ref{trees}. +A (possibly incomplete) datatype for parse trees in Scala is shown +in Figure~\ref{trees}. -\begin{figure} +\begin{figure}[p] \begin{lstlisting}[language=Scala] abstract class Stmt abstract class AExp @@ -81,6 +78,10 @@ case class If(a: BExp, bl1: Block, bl2: Block) extends Stmt case class While(b: BExp, bl: Block) extends Stmt case class Assign(s: String, a: AExp) extends Stmt +case class Read(s: String) extends Stmt +case class WriteVar(s: String) extends Stmt +case class WriteStr(s: String) extends Stmt + // for printing variables and strings case class Var(s: String) extends AExp case class Num(i: Int) extends AExp @@ -90,6 +91,7 @@ case object False extends BExp case class Bop(o: String, a1: AExp, a2: AExp) extends BExp case class Lop(o: String, b1: BExp, b2: BExp) extends BExp + // logical operations: and, or \end{lstlisting} \caption{The datatype for parse trees in Scala.\label{trees}} \end{figure} @@ -124,7 +126,8 @@ if-statement will ``run'' the if-branch if the boolean evaluates to \pcode{true}, otherwise the else-branch. Loops should be run as long as the boolean is \pcode{true}. - +Programs you should be able to run are shown in +Figures \ref{fib} -- \ref{collatz}. Give some time measurements for your interpreter @@ -134,20 +137,26 @@ you scale this value if you are willing to wait, say 1 Minute? -\begin{figure}[p] -\lstinputlisting[language=while,xleftmargin=20mm]{../progs/fib.while} +\begin{figure}[h] +\lstinputlisting[language=while,xleftmargin=20mm]{../progs/while-tests/fib.while} \caption{Fibonacci program in the WHILE language.\label{fib}} \end{figure} -\begin{figure}[p] -\lstinputlisting[language=while,xleftmargin=20mm]{../progs/loops.while} +\begin{figure}[h] +\lstinputlisting[language=while,xleftmargin=20mm]{../progs/while-tests/loops.while} \caption{The three-nested-loops program in the WHILE language. Usually used for timing measurements.\label{loop}} \end{figure} +\begin{figure}[h] +\lstinputlisting[language=while,xleftmargin=0mm]{../progs/while-tests/primes.while} +\caption{Prime number program.\label{primes}} +\end{figure} + + \begin{figure}[p] -\lstinputlisting[language=while,xleftmargin=0mm]{../progs/primes.while} -\caption{Prime number program.\label{primes}} +\lstinputlisting[language=while,xleftmargin=0mm]{../progs/while-tests/collatz2.while} +\caption{Collatz series program.\label{collatz}} \end{figure} \end{document} diff -r bb2335a5ca58 -r e93a9e74ca8e coursework/cw04.pdf Binary file coursework/cw04.pdf has changed diff -r bb2335a5ca58 -r e93a9e74ca8e coursework/cw05.pdf Binary file coursework/cw05.pdf has changed diff -r bb2335a5ca58 -r e93a9e74ca8e progs/while-tests/collatz2.while --- a/progs/while-tests/collatz2.while Mon Aug 31 18:15:12 2020 +0100 +++ b/progs/while-tests/collatz2.while Tue Sep 01 12:44:07 2020 +0100 @@ -17,11 +17,11 @@ then n := n / 2 else n := 3 * n+1; - cnt := cnt + 1; + cnt := cnt + 1 }; write " => "; write cnt; write "\n"; - bnd := bnd + 1; -}; \ No newline at end of file + bnd := bnd + 1 +} \ No newline at end of file diff -r bb2335a5ca58 -r e93a9e74ca8e progs/while-tests/primes.while --- a/progs/while-tests/primes.while Mon Aug 31 18:15:12 2020 +0100 +++ b/progs/while-tests/primes.while Tue Sep 01 12:44:07 2020 +0100 @@ -1,5 +1,4 @@ -// prints out prime numbers from -// 2 to 100 (end) +// prints out prime numbers from 2 to 100 end := 100; n := 2; diff -r bb2335a5ca58 -r e93a9e74ca8e slides/slides06.tex --- a/slides/slides06.tex Mon Aug 31 18:15:12 2020 +0100 +++ b/slides/slides06.tex Tue Sep 01 12:44:07 2020 +0100 @@ -112,6 +112,10 @@ : \meta{B} ::= b\\ \end{plstx}} + +TODO: Testcases for math expressions +\url{https://github.com/ArashPartow/math-parser-benchmark-project} + \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%