coursework/cw03.tex
changeset 682 553b4d4e3719
parent 630 9b1c15c3eb6f
child 683 c6c79d21f8a8
equal deleted inserted replaced
681:7b7736bea3ca 682:553b4d4e3719
    29 Design a grammar for the WHILE language and give the grammar
    29 Design a grammar for the WHILE language and give the grammar
    30 rules. The main categories of non-terminals should be:
    30 rules. The main categories of non-terminals should be:
    31 
    31 
    32 \begin{itemize}
    32 \begin{itemize}
    33 \item arithmetic expressions (with the operations from the
    33 \item arithmetic expressions (with the operations from the
    34   previous coursework, such as \pcode{+}, \pcode{*} and so on)
    34   previous coursework, that is \pcode{+}, \pcode{-}, \pcode{*},
    35 \item boolean expressions (such as \pcode{<}, \code{!=} and 
    35   \pcode{/} and \pcode{\%})
    36   so on)
    36 \item boolean expressions (with the operations \pcode{==}, \pcode{<}, \pcode{>},
    37 \item single statements (such as \pcode{skip}, assignments, \pcode{if}s,
    37   \code{!=}, \pcode{&&}, \pcode{||}, \pcode{true} and \pcode{false})
    38   \pcode{while}-loops and so on)
    38 \item single statements (that is \pcode{skip}, assignments, \pcode{if}s,
       
    39   \pcode{while}-loops, \pcode{read} and \pcode{write})
    39 \item compound statements separated by semicolons
    40 \item compound statements separated by semicolons
    40 \item blocks which are enclosed in curly parentheses
    41 \item blocks which are enclosed in curly parentheses
    41 \end{itemize}
    42 \end{itemize}
    42 
    43 
    43 \subsection*{Question 2}
    44 \subsection*{Question 2}
    76 case class Aop(o: String, a1: AExp, a2: AExp) extends AExp
    77 case class Aop(o: String, a1: AExp, a2: AExp) extends AExp
    77 
    78 
    78 case object True extends BExp
    79 case object True extends BExp
    79 case object False extends BExp
    80 case object False extends BExp
    80 case class Bop(o: String, a1: AExp, a2: AExp) extends BExp
    81 case class Bop(o: String, a1: AExp, a2: AExp) extends BExp
       
    82 case class Lop(o: String, b1: BExp, b2: BExp) extends BExp
    81 \end{lstlisting}
    83 \end{lstlisting}
    82 \caption{The datatype for parse trees in Scala.\label{trees}}
    84 \caption{The datatype for parse trees in Scala.\label{trees}}
    83 \end{figure}
    85 \end{figure}
    84 
    86 
    85 \subsection*{Question 3}
    87 \subsection*{Question 3}