0

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?

Patrick Trentin
  • 7,126
  • 3
  • 23
  • 40
Hongjian Jiang
  • 307
  • 1
  • 6
  • should i change it into a inline module? – Hongjian Jiang Oct 16 '20 at 01:35
  • Is there any way to define a function to get return value? – Hongjian Jiang Oct 16 '20 at 02:01
  • The issue most likely isn't that Promela doesn't support macros (see: [macros](http://spinroot.com/spin/Man/macros.html)), but that you are embedding commands inside an assert that requires an expression. Have you tried incrementing `sn` and only after checking that the value of `sn` is equal `1`? – Patrick Trentin Oct 24 '20 at 08:56

1 Answers1

0

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.

ChristianYami
  • 586
  • 1
  • 9
  • 17
rookie
  • 1