hw2: add boolean operators to semantics

This commit is contained in:
2026-03-06 00:13:04 -08:00
parent d7f35fef5b
commit 5e9759a8e5
2 changed files with 17 additions and 0 deletions

Binary file not shown.

View File

@@ -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}