| 1 | The CIVL-C code will not have an explicit "Root" procedure.
|
|---|
| 2 | Instead, a Root procedure will be implicitly wrapped around
|
|---|
| 3 | the enitre code. The global input variables will become
|
|---|
| 4 | the inputs to the Root procedure.
|
|---|
| 5 |
|
|---|
| 6 | Syntactic changes from C:
|
|---|
| 7 |
|
|---|
| 8 | a type _proc
|
|---|
| 9 |
|
|---|
| 10 | _input int n; // type modifier: global variable is input
|
|---|
| 11 | _output double y; // ditto
|
|---|
| 12 |
|
|---|
| 13 | function definitions in any scope
|
|---|
| 14 |
|
|---|
| 15 | _spawn f(...); /* this is an expression with side-effects */
|
|---|
| 16 |
|
|---|
| 17 | _wait expr; /* this is a statement */
|
|---|
| 18 |
|
|---|
| 19 | _assert expr; /* statement */
|
|---|
| 20 |
|
|---|
| 21 | _assume expr; /* statement */
|
|---|
| 22 |
|
|---|
| 23 | _when (expr) stmt; /* guarded command */
|
|---|
| 24 |
|
|---|
| 25 | /* nondeterministic choice: */
|
|---|
| 26 | _choose {
|
|---|
| 27 | stmt1;
|
|---|
| 28 | stmt2;
|
|---|
| 29 | ...
|
|---|
| 30 | default: stmt
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | the "default" clause is optional.
|
|---|
| 34 |
|
|---|
| 35 | example: this shows how to encode "low-level" CIVL:
|
|---|
| 36 |
|
|---|
| 37 | l1: _choose {
|
|---|
| 38 | _when (x>0) {x--; goto l2;}
|
|---|
| 39 | _when (x==0) {y=1; goto l3;}
|
|---|
| 40 | default: {z=1; goto l4;}
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | loop invariants: each loop construct has an optional invariant
|
|---|
| 44 | clause as follows:
|
|---|
| 45 |
|
|---|
| 46 | while (expr) _invariant (expr) stmt
|
|---|
| 47 |
|
|---|
| 48 | for (e1; e2; e3) _invariant (expr) stmt
|
|---|
| 49 |
|
|---|
| 50 | do stmt while (expr) _invariant (expr) ;
|
|---|
| 51 |
|
|---|
| 52 | optional elements preceding procedure decls:
|
|---|
| 53 |
|
|---|
| 54 | requires expr ;
|
|---|
| 55 | ensures expr ;
|
|---|
| 56 |
|
|---|
| 57 | expressions:
|
|---|
| 58 | expr@x : refer to variable in other process, e.g., procs[i]@x
|
|---|
| 59 | \collective(array-expression) e : collective assertion over
|
|---|
| 60 | set of processes in array
|
|---|
| 61 |
|
|---|
| 62 | example:
|
|---|
| 63 |
|
|---|
| 64 | _proc procs[N];
|
|---|
| 65 | ...
|
|---|
| 66 | assert \collective(procs) i==procs[pid+1]@i ;
|
|---|
| 67 |
|
|---|
| 68 | Elements not added to grammar:
|
|---|
| 69 |
|
|---|
| 70 | _self : constant of type _proc indicating "me"
|
|---|