The loose expression evaluation operations which are presented in this
section takes a syntactic expression and yields a ``loose value''. This
loose value is a setof pairs with a return value and its
corresponding model as explained in Section~\ref{semantic}.
The general strategy behind the loose evaluation of expressions is
that whenever an syntactic expression contains more than one
subexpression the loose valuesfrom these subexpressions are
combined such that only ``consistent'' models are considered. In addition
it should be noticed that {\it PatternMatch} operation
which performs matching of a syntactic pattern to a value yields the setofall possible
bindings of the pattern identifiers in case of looseness.
let val_lv = LooseEvalExpr(expr) in forall mk_(val_v,m) inset val_lv do let env_s = PatternMatch(pat,val_v) in if env_s <> {} thenforall env inset env_s do
(PushBlkEnv(env) ; let in_lv = LooseEvalExpr(in_e) in
( PopBlkEnv() ;
lval := lval union Consistent(in_lv,m)
)
) elseerror; return lval);
\end{vdm_al}
Here in {\it LooseEvalLetExpr} it can be seen how the right-hand-side expression,
{\it expr} is evaluated first. For each of the loose value pairs
(value and corresponding model) the value is matched against the
pattern and given that this succeeds ($env-s \Neq \Emptyset$) the
in-expression is evaluated in a context where each of the bindings from the
pattern matching is visible (by $PushBlkEnv$). The loose value pairs which are
consistent with the model for the loose value pair of the first
expression are added to the resulting loose value for the entire
let-expression.
forall mk_(env,m) inset EvalBind(lhs) do
(PushBlkEnv(env); let st_lv = LooseEvalExpr(st_e) in forall mk_(val,m2) inset Consistent(st_lv,m) do if val = mk_BOOL(true) then em_s := em_s union {mk_(env,m2 munion m)};
PopBlkEnv()); if em_s <> {} thenforall mk_(env,m3) inset em_s do
(PushBlkEnv(env) ; let in_lv = LooseEvalExpr(in_e) in
(PopBlkEnv();
lval := lval union Consistent(in_lv,m3)
)
) elseerror; return lval);
\end{vdm_al} For let-be-such-that expressions all possible environments arising from matching the left-hand-side (set) binding are taken into account
(with the corresponding models). If there is an additional
``such-that'' predicate it is evaluated where one of these
environments are in context. The consistent loose valuesfrom the
predicate must thenbe tested whether they yield true. Forall such
loose values the corresponding environment is put in context for
evaluation of the body expression, where the consistency again must be
ensured.
let test_lv = LooseEvalExpr(test) in forall mk_(test_v,m) inset test_lv do if is_BOOL(test_v) thenlet mk_BOOL(b) = test_v in if b then lval := lval union Consistent(LooseEvalExpr(cons),m) else lval := lval union Consistent(LooseEvalExpr(altn),m) elseerror; return lval);
\end{vdm_al}
Conditional expressions are relatively simple because it simply isall
loose valuesfrom the evaluation of the test expression which must be to calculate the consistent loose valuesfrom the consequence
expression or the alternative expression (depending upon the the value of the test expression in a particular model).
let sel_lv = LooseEvalExpr(sel) in forall mk_(sel_v,m) inset sel_lv do
(while alt_l <> [] and cont do
(let mk_CaseAltn(pat,body) = hd alt_l in let env_s = PatternMatch(pat,sel_v) in if env_s <> {} then (cont := false; forall env inset env_s do
(PushBlkEnv(env);
lval := lval union Consistent(LooseEvalExpr(body),m);
PopBlkEnv()));
alt_l := tl alt_l); ifnot cont then cont := true elseifOthers = nil thenerror else lval := lval union LooseEvalExpr(Others)); return lval);
\end{vdm_al} Forcases expressions all loose valuesfrom the evaluation of the
selector expression are used for further matching against the patterns in the different case alternatives. When a matching pattern is found all the matching environments are used as context for the body of the
case alternative. If none of the alternatives matches an others clause
must be present.
\subsection{Binary Expressions}
\begin{vdm_al}
LooseEvalBinaryExpr: BinaryExpr ==> LVAL
LooseEvalBinaryExpr (mk_BinaryExpr(left_e, opr, right_e)) == let left_lv = LooseEvalExpr(left_e),
right_lv = LooseEvalExpr(right_e) in if opr = <SETMINUS> then LooseEvalSetBinaryExpr(left_lv, right_lv) elseif opr = <EQ> then LooseEvalEqBinaryExpr(left_lv, right_lv) else LooseEvalNumBinaryExpr(left_lv, opr, right_lv);
\end{vdm_al}
Since all the binary operators we have selected in our subset are
strict (we have not included any of the logical connectives) we can
safely evaluate both the of the operands to the binary operator. The
actual work is done by seperate auxiliary functions (one forset
difference, one for equality and one for the remaining numerical
operators which are included).
for index = 2 tolen els do let elm_llv = LooseEvalExpr(els(index)) in
sm_s := {mk_(s union {e},m munion m2)
| mk_(s,m) inset sm_s, mk_(e,m2) inset elm_llv & forall id inset (dom m interdom m2) &
m(id) = m2(id)}; return {mk_(mk_SET(s),m) | mk_(s,m) inset sm_s}));
\end{vdm_al} Forset enumeration expressions it is first tested whether we are
dealing with an empty set. Otherwise a setof loose values are created with pairs of a singleton setwith the first element and its
corresponding model. This setof loose valuesisthen gradually
updated to include larger setvaluesand larger corresponding models
(with the usual consistency check).
let arg_lv = LooseEvalExpr(arg_e),
mk_(pat,body) = LookUpFn(fct_e) in
(PushEmptyEnv(); forall mk_(arg_v,m) inset arg_lv do let env_s = PatternMatch(pat,arg_v) in
(InstallCurFn(fct_e, arg_v, PatternIds(pat)); forall env inset env_s do
(PushBlkEnv(env); let ap_lv = LooseEvalExpr(body) in
(PopBlkEnv();
lval := lval union Consistent(ap_lv,m))));
LeaveCurFn());
PopEnvL(); return lval);
\end{vdm_al}
Here it is worth noting how function application is treated. Forall
possible matches of the argument value against the formal parameter
pattern, the global stateis updated (by $InstallCurFn$) with information about the current function
application (tobe used to create unique identifiers) and the
pattern identifiers from the formal parameter are installed as well,
such that bindings to these are not made a part of the resulting
model. The body isthen evaluated in a context where these bindings
are visible and the consistent models are added to the resulting loose
evaluator. Here it can also be seen how the stack of environments are
used by pushing and popping environments at the outermost levels
(using $PushEmptyEnv$ and $PopEnvL$). This isthen taken into account by the corresponding lookup operation which
will only search for a binding in the top-most function application
environment.
\end{vdm_al}
Literal expressions naturally contains no looseness anddonot rely on
any particular model. Therefore this is modeled as singleton sets with
emthy models.
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.