Languages with both Logical and Arithmetic Expressions

HNU CE 프로그래밍언어론 (2021년 1학기)

산술식 언어의 동작 과정 의미론

Syntax

e ::= n \mid x \mid e + e

Semantics

~\sigma,e \Downarrow v~
\sigma \in \texttt{Env} ~ = ~ \texttt{Name} \xrightarrow{_\mathrm{fin}} \texttt{Value}
\sigma ::= \{ x_1\mapsto v_1, \ldots, x_k\mapsto v_k\}
v \in \texttt{Value} ~ = ~ \texttt{Int}
\frac{}{\sigma,\,n \;\Downarrow\; n}
\frac{}{\sigma,\, x \;\Downarrow\; \sigma(x)}
\frac{\sigma,\,e_1\Downarrow\,v_1 \quad \sigma,\,e_2\Downarrow\,v_2}{\sigma,\,e_1+\,e_2 \;\Downarrow\; v_1\texttt{+}\,v_2}
e \in \texttt{Expr}
n \in \texttt{Int}

논리식 언어의 동작 과정 의미론

Syntax

e ::= b \mid x \mid e \land e \mid \ldots

Semantics

~\sigma,e \Downarrow v~
\sigma \in \texttt{Env} ~ = ~ \texttt{Name} \xrightarrow{_\mathrm{fin}} \texttt{Value}
\sigma ::= \{ x_1\mapsto v_1, \ldots, x_k\mapsto v_k\}
v \in \texttt{Value} ~ = ~ \texttt{Bool}
\frac{}{\sigma,\,b \;\Downarrow\; b}
\frac{}{\sigma,\, x \;\Downarrow\; \sigma(x)}
\frac{\sigma,\,e_1\Downarrow\,v_1 \quad \sigma,\,e_2\Downarrow\,v_2}{\sigma,\,e_1\land\,e_2 \;\Downarrow\; v_1 \texttt{\&\&}\, v_2}
e \in \texttt{Expr}
b \in \texttt{Bool}

산술식 논리식 모두 포함된 언어

Syntax

\begin{array}{l} e \in \texttt{Expr} \quad n\in\texttt{Int} \quad b\in\texttt{Bool} \\ e ::= x \mid \texttt{if}\;e\;\texttt{then}\;e\;\texttt{else}\;e\; \\ \qquad\mid n \mid e + e \mid \ldots \\ \qquad\mid b \mid e \land e \mid \neg e \mid \ldots \\ \qquad\mid e = e \mid e \lt e \mid \ldots\\ \end{array}

Semantics

~\sigma,e \Downarrow v~
\sigma \in \texttt{Env} ~ = ~ \texttt{Name} \xrightarrow{_\mathrm{fin}} \texttt{Value}
\sigma ::= \{ x_1\mapsto v_1, \ldots, x_k\mapsto v_k\}
v \in \texttt{Value} ~ = ~~ {\color{red}???}

산술식 논리식 모두 포함된 언어

Syntax

\begin{array}{l} e \in \texttt{Expr} \quad n\in\texttt{Int} \quad b\in\texttt{Bool} \\ e ::= x \mid \texttt{if}\;e\;\texttt{then}\;e\;\texttt{else}\;e\; \\ \qquad\mid n \mid e + e \mid \ldots \\ \qquad\mid b \mid e \land e \mid \neg e \mid \ldots \\ \qquad\mid e = e \mid e \lt e \mid \ldots\\ \end{array}

Semantics

~\sigma,e \Downarrow v~
\sigma \in \texttt{Env} ~ = ~ \texttt{Name} \xrightarrow{_\mathrm{fin}} \texttt{Value}
\sigma ::= \{ x_1\mapsto v_1, \ldots, x_k\mapsto v_k\}
v \in \texttt{Value} ~ = \texttt{Int}
\texttt{Bool} = \{0,1\} \subset \texttt{Int}

산술식 논리식 모두 포함된 언어

Syntax

\begin{array}{l} e \in \texttt{Expr} \quad n\in\texttt{Int} \quad b\in\texttt{Bool} \\ e ::= x \mid \texttt{if}\;e\;\texttt{then}\;e\;\texttt{else}\;e\; \\ \qquad\mid n \mid e + e \mid \ldots \\ \qquad\mid b \mid e \land e \mid \neg e \mid \ldots \\ \qquad\mid e = e \mid e \lt e \mid \ldots\\ \end{array}

Semantics

~\sigma,e \Downarrow v~
\sigma \in \texttt{Env} ~ = ~ \texttt{Name} \xrightarrow{_\mathrm{fin}} \texttt{Value}
\sigma ::= \{ x_1\mapsto v_1, \ldots, x_k\mapsto v_k\}
v \in \texttt{Value} ~ = \texttt{Int} \uplus \texttt{Bool}
\texttt{Bool} \cap \texttt{Int} = \emptyset

비교식 의미규칙

Syntax

\begin{array}{l} e ::= x \mid n \mid b \mid e + e \mid e \mid \neg e \mid e \land e \\~\quad~~ \mid e = e \mid e \lt e \mid \texttt{if}\;e\;\texttt{then}\;e\;\texttt{else}\;e\; \end{array}

Semantics

~\sigma,e \Downarrow v~
v \in \texttt{Value} \;=\; \texttt{Int} \uplus \texttt{Bool}
e \in \texttt{Expr} \quad n\in\texttt{Int} \quad b\in\texttt{Bool}
\frac{\sigma,\,e_1\,\Downarrow\,n_1 \quad \sigma,\,e_2\,\Downarrow\,n_2}{ \sigma,\,e_1 =\, e_2 \;\Downarrow\; n_1 \texttt{==}\, n_2}
\frac{\sigma,\,e_1\,\Downarrow\,b_1 \quad \sigma,\,e_2\,\Downarrow\,b_2}{ \sigma,\,e_1 =\, e_2 \;\Downarrow\; b_1 \texttt{==}\, b_2}
\frac{\sigma,\,e_1\,\Downarrow\,n_1 \quad \sigma,\,e_2\,\Downarrow\,n_2}{ \sigma,\,e_1 <\, e_2 \;\Downarrow\; n_1 \texttt{<}\, n_2}
\frac{\sigma,\,e_1\,\Downarrow\,b_1 \quad \sigma,\,e_2\,\Downarrow\,b_2}{ \sigma,\,e_1 <\, e_2 \;\Downarrow\; b_1 \texttt{<}\, b_2}

조건식 의미규칙

Syntax

\begin{array}{l} e ::= x \mid n \mid b \mid e + e \mid e \mid \neg e \mid e \land e \\~\quad~~ \mid e = e \mid e \lt e \mid \texttt{if}\;e\;\texttt{then}\;e\;\texttt{else}\;e\; \end{array}

Semantics

~\sigma,e \Downarrow v~
v \in \texttt{Value} \;=\; \texttt{Int} \uplus \texttt{Bool}
e \in \texttt{Expr} \quad n\in\texttt{Int} \quad b\in\texttt{Bool}
\frac{\sigma,\,e\,\Downarrow\,\texttt{False} \quad \sigma,\,e_0\,\Downarrow\,v_0}{ \sigma,\,\texttt{if}\;e\;\texttt{then}\;e_1\;\texttt{else}\;e_0\;\Downarrow\; v_0}
\frac{\sigma,\,e\,\Downarrow\,\texttt{True} \quad \sigma,\,e_1\,\Downarrow\,v_1}{ \sigma,\,\texttt{if}\;e\;\texttt{then}\;e_1\;\texttt{else}\;e_0\;\Downarrow\; v_1}

의미규칙

\begin{array}{l} e ::= x \mid n \mid b \mid e + e \mid \neg e \mid e \land e \\~\quad~~ \mid e = e \mid e \lt e \mid \texttt{if}\;e\;\texttt{then}\;e\;\texttt{else}\;e\; \end{array}

Semantics

~\sigma,e \Downarrow v~
v \in \texttt{Value} \;=\; \texttt{Int} \uplus \texttt{Bool}
e \in \texttt{Expr} \quad n\in\texttt{Int} \quad b\in\texttt{Bool}
\frac{\sigma,\,e\,\Downarrow\,\texttt{False} \quad \sigma,\,e_0\,\Downarrow\,v_0}{ \sigma,\,\texttt{if}\;e\;\texttt{then}\;e_1\;\texttt{else}\;e_0\;\Downarrow\; v_0}
\frac{\sigma,\,e\,\Downarrow\,\texttt{True} \quad \sigma,\,e_1\,\Downarrow\,v_1}{ \sigma,\,\texttt{if}\;e\;\texttt{then}\;e_1\;\texttt{else}\;e_1\;\Downarrow\; v_1}

Syntax

\frac{\sigma,\,e_1\,\Downarrow\,n_1 \quad \sigma,\,e_2\,\Downarrow\,n_2}{ \sigma,\,e_1 =\, e_2 \;\Downarrow\; n_1 \texttt{==}\, n_2}
\frac{\sigma,\,e_1\,\Downarrow\,b_1 \quad \sigma,\,e_2\,\Downarrow\,b_2}{ \sigma,\,e_1 =\, e_2 \;\Downarrow\; b_1 \texttt{==}\, b_2}
\frac{\sigma,\,e_1\,\Downarrow\,n_1 \quad \sigma,\,e_2\,\Downarrow\,n_2}{ \sigma,\,e_1 <\, e_2 \;\Downarrow\; n_1 \texttt{<}\, n_2}
\frac{\sigma,\,e_1\,\Downarrow\,b_1 \quad \sigma,\,e_2\,\Downarrow\,b_2}{ \sigma,\,e_1 <\, e_2 \;\Downarrow\; b_1 \texttt{<}\, b_2}

의미규칙

\begin{array}{l} e ::= x \mid n \mid b \mid e + e \mid \neg e \mid e \land e \\~\quad~~ \mid e = e \mid e \lt e \mid \texttt{if}\;e\;\texttt{then}\;e\;\texttt{else}\;e\; \end{array}

Semantics

~\sigma,e \Downarrow v~
v \in \texttt{Value} \;=\; \texttt{Int} \uplus \texttt{Bool}
e \in \texttt{Expr} \quad n\in\texttt{Int} \quad b\in\texttt{Bool}

Syntax

\frac{\sigma,\,e_1\Downarrow\,n_1 \quad \sigma,\,e_2\Downarrow\,n_2}{\sigma,\,e_1+\,e_2 \;\Downarrow\; n_1\texttt{+}\,n_2}
\frac{\sigma,\,e_1\Downarrow\,b_1 \quad \sigma,\,e_2\Downarrow\,b_2}{\sigma,\,e_1\land\,e_2 \;\Downarrow\; b_1\texttt{\&\&}\,b_2}
\frac{\sigma,\,e\,\Downarrow\,b }{\sigma,\,\neg e \;\Downarrow\; \texttt{not}\,b}

하스켈에서 Value 정의하기

\begin{array}{l} e ::= x \mid n \mid b \mid e + e \mid e \mid \neg e \mid e \land e \\~\quad~~ \mid e = e \mid e \lt e \mid \texttt{if}\;e\;\texttt{then}\;e\;\texttt{else}\;e\; \end{array}

Semantics

~\sigma,e \Downarrow v~
\texttt{Value} ~~ = \qquad \texttt{Int}~ \uplus \quad \qquad \texttt{Bool}
e \in \texttt{Expr} \quad n\in\texttt{Int} \quad b\in\texttt{Bool}

Syntax

data Value = Vint Int | Vbool Bool
v \in \texttt{Value} \;=\; \texttt{Int} \uplus \texttt{Bool}

논리식 산술식 모두 포함된 언어

By 안기영 (Ahn, Ki Yung)

논리식 산술식 모두 포함된 언어

HNU CE 프로그래밍언어론 (2021년 1학기)

  • 658