I don't know how to declare global constants in NuSMV, in a way that is similar to
#define n 5
in C
.
How can I do that in NuSMV?
I don't know how to declare global constants in NuSMV, in a way that is similar to
#define n 5
in C
.
How can I do that in NuSMV?
According to paragraph 2.3.2 (page 27) of NuSMV 2.6 Manual:
In order to make descriptions more concise, a symbol can be associated with a common expression, and a DEFINE declaration introduces such a symbol. The syntax for this kind of declaration is:
define_declaration :: DEFINE define_body define_body :: identifier := simple_expr ; | define_body identifier := simple_expr ;
DEFINE associates an
identifier
on the left hand side of the:=
with an expression on the right side. A define statement can be considered as a macro. Whenever a defineidentifier
occurs in an expression, theidentifier
is syntactically replaced by the expression it is associated with. The associated expression is always evaluated in the context of the statement where theidentifier
is declared (see Section 2.3.16 [Context], page 36 for an explanation of contexts). Forward references to defined symbols are allowed but circular definitions are not, and result in an error. The difference between defined symbols and variables is that while variables are statically typed, definitions are not.
Therefore, this should work:
DEFINE n := 5 ;
You can only put this definition within one module, because it must belong to some context.
However, you can "simulate" a global scope by having one special module acting as a container for all global definitions. e.g.:
MODULE global
DEFINE
n := 5;
MODULE pippo(global)
VAR
pluto : {0, 1, 2, 3, 4, 5};
ASSIGN
init(pluto) := global.n;
MODULE main()
VAR
global : global();
pippo : pippo(global);
You can test the example like this:
~$ NuSMV -int
NuSMV > reset; read_model -i example.smv; go; pick_state -i -v
*************** AVAILABLE STATES *************
================= State =================
0) -------------------------
global.n = 5
pippo.pluto = 5