diff --git a/hw2/while-semantics.pdf b/hw2/while-semantics.pdf index d97dae0..fb59f46 100644 Binary files a/hw2/while-semantics.pdf and b/hw2/while-semantics.pdf differ diff --git a/hw2/while-semantics.tex b/hw2/while-semantics.tex index 31c9993..fe6f600 100644 --- a/hw2/while-semantics.tex +++ b/hw2/while-semantics.tex @@ -43,6 +43,7 @@ you will implement the semantics for a small imperative language, named WHILE. \newcommand{\whilee}[2]{\mbox{\tt while}~(#1)~#2} \newcommand{\true}{\mbox{\tt true}} \newcommand{\false}{\mbox{\tt false}} +\newcommand{\note}[1]{\mbox{\tt not}~{#1}} \begin{figure}\label{fig:lang} \caption{The WHILE language} @@ -56,12 +57,16 @@ you will implement the semantics for a small imperative language, named WHILE. \mydefcase{e ~op~ e}{binary operations} \mydefcase{\ife e e e}{conditional expressions} \mydefcase{\whilee e e}{while expressions} + \mydefcase{e ~boolop~ e}{boolean binary operations} + \mydefcase{\not e}{negation} \\ \mydefhead{v ::=\qquad\qquad\qquad\qquad}{Values} \mydefcase{i}{integer values} \mydefcase{b}{boolean values} \\ op ::= & + ~|~ - ~|~ * ~|~ / ~|~ > ~|~ >= ~|~ < ~|~ <= & \mbox{\emph{Binary operators}} \\ + \\ + boolop ::= & and ~|~ or & \mbox{\emph{Boolean binary operators}} \\ \end{array} \] \end{figure} @@ -366,6 +371,18 @@ Finally, implement the interpreter to match your semantics. % }{ % \bstep{\whilee{e_1}{e_2}}{\sigma}{\ife{v_1}{e_2;\whilee{e_1}{e_2}}{\false}}{\sigma''} % } +\bsrule{B-Not}{ + \bstep{e}{\sigma}{b}{\sigma'} +}{ + \bstep{\note{e}}{\sigma}{\neg b}{\sigma'} +} +\bsrule{B-BoolOp}{ + \bstep{e_1}{\sigma}{b_1}{\sigma'} \\ + \bstep{e_2}{\sigma'}{b_2}{\sigma''} \\ + b = apply(boolop, b_1, b_2) +}{ + \bstep{e_1~boolop~e_2}{\sigma}{b}{\sigma''} +} \end{array} \] \end{figure}