How can i define such a macro in spin?

496 Views Asked by At

I wrote the following model:

#define inc(sn)if :: sn < 255 -> sn = sn + 1; ::else -> sn = 1; fi;
#define inc_twice(sn) if :: sn+2 >255 -> sn= sn-253; ::else -> sn=sn+2; fi;

active proctype monitor()
{
    byte sn = 255;
    assert (inc(sn) ==1);
}

But the compiler fails as follows:

spin: test2.pml:9, Error: syntax error  saw 'keyword: if' near 'if'
spin: test2.pml:9, Error: syntax error  saw 'token: ::'
spin: test2.pml:9, Error: syntax error  saw 'keyword: fi' near 'fi'
spin: test2.pml:11, Error: aborting (ana_stmnt)
child process exited abnormally.

How can i solve it?

1

There are 1 best solutions below

0
On

I have met the same problem . And you can solve it by change your code into this :

#define inc(sn)if \\

:: sn < 255 -> sn = sn + 1 \\

::else -> sn = 1 \\

fi;

#define inc_twice(sn) if \\

:: sn+2 >255 -> sn= sn-253 \\

::else -> sn=sn+2 \\

 fi;

I don't know what causes this issue, but I solve it by the above method.