hw2: add boolean operators to semantics
This commit is contained in:
Binary file not shown.
@@ -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{\whilee}[2]{\mbox{\tt while}~(#1)~#2}
|
||||||
\newcommand{\true}{\mbox{\tt true}}
|
\newcommand{\true}{\mbox{\tt true}}
|
||||||
\newcommand{\false}{\mbox{\tt false}}
|
\newcommand{\false}{\mbox{\tt false}}
|
||||||
|
\newcommand{\note}[1]{\mbox{\tt not}~{#1}}
|
||||||
|
|
||||||
\begin{figure}\label{fig:lang}
|
\begin{figure}\label{fig:lang}
|
||||||
\caption{The WHILE language}
|
\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{e ~op~ e}{binary operations}
|
||||||
\mydefcase{\ife e e e}{conditional expressions}
|
\mydefcase{\ife e e e}{conditional expressions}
|
||||||
\mydefcase{\whilee e e}{while 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}
|
\mydefhead{v ::=\qquad\qquad\qquad\qquad}{Values}
|
||||||
\mydefcase{i}{integer values}
|
\mydefcase{i}{integer values}
|
||||||
\mydefcase{b}{boolean values}
|
\mydefcase{b}{boolean values}
|
||||||
\\
|
\\
|
||||||
op ::= & + ~|~ - ~|~ * ~|~ / ~|~ > ~|~ >= ~|~ < ~|~ <= & \mbox{\emph{Binary operators}} \\
|
op ::= & + ~|~ - ~|~ * ~|~ / ~|~ > ~|~ >= ~|~ < ~|~ <= & \mbox{\emph{Binary operators}} \\
|
||||||
|
\\
|
||||||
|
boolop ::= & and ~|~ or & \mbox{\emph{Boolean binary operators}} \\
|
||||||
\end{array}
|
\end{array}
|
||||||
\]
|
\]
|
||||||
\end{figure}
|
\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''}
|
% \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{array}
|
||||||
\]
|
\]
|
||||||
\end{figure}
|
\end{figure}
|
||||||
|
|||||||
Reference in New Issue
Block a user