From c402948797c884cfcfc14db996545d09eba1a0da Mon Sep 17 00:00:00 2001 From: Marjolein Zwerver Date: Tue, 27 May 2014 16:52:27 +0200 Subject: [PATCH] update wiskundige functies --- semantics.tex | 33 ++++++++++++++++++++++++++------- syntax.tex | 4 +++- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/semantics.tex b/semantics.tex index 578901d..5ab8dc4 100644 --- a/semantics.tex +++ b/semantics.tex @@ -88,8 +88,9 @@ Om de gebruiken we de volgende functie:\\ $$\mathcal{NOT} : Stack \rightarrow Stack$$ $$\mathcal{NOT} [\:] = [\:]$$ -$$\mathcal{NOT} [a:rest] = [0:rest] \: \text{if} \: a \neq 0$$ -$$\mathcal{NOT} [a:rest] = [1:rest] \: \text{if} \: a = 0$$\\ +$$\mathcal{NOT} [0:rest] = [1:rest]$$ +$$\mathcal{NOT} [\_:rest] = [0:rest] $$\\ + Deze functie neemt het bovenste element van de stack en stopt 0 bovenaan de stack als deze waarde niet gelijk is aan 0 en 1 als deze waarde gelijk is aan 0.\\ @@ -98,8 +99,26 @@ volgende functie:\\ $$\mathcal{GRE} : Stack \rightarrow Stack$$ $$\mathcal{GRE} [\:] = [\:]$$ $$\mathcal{GRE} [a] = [a] $$ -$$\mathcal{GRE} [a:b:rest] = [0:rest] \: \text{if} \: a \geq b$$ -$$\mathcal{GRE} [a:b:rest] = [1:rest] \: \text{if} \: a < b$$\\ +$$\mathcal{GRE} [a:b:rest]$$ +$$\qquad \qquad | \: a \geq b = [0:rest]$$ +$$\qquad \qquad | \: a < b = [1:rest]$$\\ + +$$\mathcal{ROLL} : Stack \rightarrow Stack$$ +$$\mathcal{ROLL} [\:] = [\:]$$ +$$\mathcal{ROLL} [a] = [a] $$ +$$\mathcal{ROLL} [a:b:rest]$$ +$$\qquad \qquad | modulo \: a \: b == 0 = rest$$ +$$\qquad \qquad | b <= 0 = rest$$ +$$\qquad \qquad | b > length rest = rest$$ +$$\qquad \qquad | a == 1 = roll1 [b:rest]$$ +$$\qquad \qquad | a > 0 = roll([a-1] ++ [b] ++ roll1 [b:rest]$$ +$$\qquad \qquad | a < 0 = roll(modulo \: a \: b] ++ [b:rest])$$ + +$$\mathcal{ROLL}1 : Stack \rightarrow Stack$$ +$$\mathcal{ROLL}1 [1:rest] = [rest]$$ +$$\mathcal{ROLL}1 [b:c:d:rest] = [d] ++ \mathcal{ROLL}1 [b-1:c:rest]$$ + + Deze functie haalt de bovenste twee elementen van de stack en stopt 1 bovenop de stack als het tweede bovenste element een hogere waarde heeft als dat van het bovenste element. Anders word 1 bovenop de stack gestopt.\\ @@ -135,11 +154,11 @@ $ \langle greater, s_i, s_o, s\rangle \Rightarrow \langle s_i, s_o, \mathcal{GRE}(s)\rangle\\ {[push_{sos}]} \qquad -\langle push, s_i, s_o, s\rangle \Rightarrow -\langle s_i, s_o, s\rangle\\ +\langle push \: n, s_i, s_o, s\rangle \Rightarrow +\langle s_i, s_o, \mathcal{E}(n,s)\rangle\\ {[roll_{sos}]} \qquad \langle roll, s_i, s_o, s\rangle \Rightarrow -\langle s_i, s_o, s\rangle\\ +\langle s_i, s_o, \mathcal{ROLL}(s)\rangle\\ {[inchar_{sos}]} \qquad \langle inchar, s_i, s_o, s\rangle \Rightarrow \langle s_i, s_o, s\rangle\\ diff --git a/syntax.tex b/syntax.tex index 080721a..9f1809e 100644 --- a/syntax.tex +++ b/syntax.tex @@ -36,7 +36,9 @@ die gedeeltelijk beschreven is in tabel \ref{tab:sy1}. Om de notatie leesbaar en overzichtelijk te houden beschrijven we de syntax niet in de oorspronkelijke kleuren notatie maar gebruiken we een woordelijke notatie. Dan ziet de grammatica er als volgt uit:\\ -$S ::= S_1 ; S_2\ |\ push\ |\ pop\ |\ add\ |\ subtract\ +$S ::= S_1 ; S_2\ |\ push \: n\ |\ pop\ |\ add\ |\ subtract\ |\ multiply\ |\ divide\ |\\mod\ |\ not\ |\ greater\ |\ pointer\ |\ switch\ |\ duplicate\ |\ roll\ |\\ inchar\ |\ innum\ |\ outchar\ |\ outnum$\\ + +Waarbij $n \in \mathbb{N}_1$. -- 2.20.1