H γλώσσα CPN ML. 1. Δηλώσεις 3 Colour Sets Unit colset name = unit [with new_unit];...
-
Upload
immanuel-latimore -
Category
Documents
-
view
219 -
download
0
Transcript of H γλώσσα CPN ML. 1. Δηλώσεις 3 Colour Sets Unit colset name = unit [with new_unit];...
3
Colour Sets
Unitcolset name = unit [with new_unit];
ex:colset U = unit; >>> 1`()
colset E = unit with e; >>> 1`e
4
Colour Sets
Booleancolset name = bool [with (new_false, new_true)];
ex:colset B = bool; >>> 1`true
colset B2 = bool with (no, yes); >>> 1`yes
Operationsnot, andalso, orelse
5
Colour Sets
Integercolset name = int [with int-exp1..int-exp2];
ex:colset I = int ; >>> 1`36 colset I2 = int with 0..9; >>> 1`7
Operations~(neg), +, -, *, div, mod, abs, Int.min(i1,i2), Int.max(i1,i2)
6
Colour SetsStrings
colset name = string [with string-exp1..string-exp2 [and int-exp1..int-exp2] ];
ex:colset lowerstring = string with “a” .. “z” and 1..3;“abc”, “xy” >>> OK “AbC”, “abcd” NOT OK
Operationss1^s2, String.size s, substring(s, i, len), explode s, implode l
(length)
7
Colour SetsEnumerated
colset name = with id0 | id1 | … | idn;
ex:colset dwarfs = Dopey | Doc | Sleepy | Bashful | Happy
| Grumpy | Sneezy;
8
Colour SetsIndex
colset name = index id with int1..int2;
ex:colset STUDENT = index student with 1..11;>>> 1`student(1) .. 1`student(11)
9
Compound Colour SetsProduct
colset name = product name1 * name2 * ... * namen;
ex:colset COUPLES = product MEN * WOMEN;>>> 1`(Bob, Mary)
Operations#i Extract element i of tuple_ Omit element - ex. (Bob,_) - Not allowed in
CPN
10
Compound Colour SetsRecord
colset name = record id1:name1 * id2:name2 * ... * idn:namen;
ex:colset ID = record n:NAME, s:SURNAME, a:AGE;>>> 1`{n=“Bob”, s=“Smith”, a=29}
Operations#idi rec Extract element idi of record rec (ex: #s rec)… Omit element (not allowed in CPN)
11
Compound Colour SetsList
colset name = list name0 [with int1..int2];
ex:colset MyList = list INT with 1..3;>>> 1`[3, 8, 54]
OperationsMany; see:http://wiki.daimi.au.dk/cpntools-help/list_colour_sets.wiki
12
Compound Colour SetsUnion
colset name = union id1[:name1] + id2[:name2] + ... + idn[:namen];
ex:colset Digit = int with 0..9;colset MyUnion = union NUM:Digit + NONE;>>> 1`NUM(4) NOT VALID: 1`NUM(13)
1`NONE 1`NONE(a)1`NUM 4 1`NUM
13
Compound Colour SetsSubset
colset name = subset name0 by subset-function;
colset name = subset name0 with subset-list;
ex:fun even i = ((i mod 2) = 0);colset evenInt = subset INT by even;
colset int2to4 = subset INT with [2,3,4];
15
Variables & Constants
var id1[, id2, …, idn]: name;
val id = exp;
ex:
var x: int;
val maxtries = 5;
16
Reference Variables
globref id = exp;
ex:
globref i = 10;
Operations:!a contents of the r.v. a
a:=b assign value b to r.v. a
ref b reference constructor
inc a/dec a in-/decrement value of int r.v. a
17
Functions
fun id pat1 = exp1
id pat2 = exp2
...
id patn = expn;
ex:fun isPos(x) = (x>0);fun diff(x,y) = (x<>y);fun Divide(x,y) = (x div y) Divide(_,0) = error;
18
Local Declarations
let
val pat1=exp1
val pat2=exp2
…
val patn=expn
in
exp
end;
letfactor=5;
inmult(num, factor);
end;
19
Control Structures
• if boolexp then exp1 else exp2
• case exp ofpat1 => exp1
pat2 => exp2
…
patn => expn;
22
Operations
empty constant; empty multiset== equality<><> inequality>> greater than (>>= ..or equal to)<< lesser than (<<= ..or equal to)++ addition-- subtraction** scalar multiplication
23
Operations
size ms sizerandom ms return random colourcf(c, ms) appearances of c in msfilter p ms filter ms by predicate pext_col f ms takes i1`c1++…++in`cn and returns
i1`f(c1)++…++in`f(cn)ext_ms f ms takes i1`c1++…++in`cn and returns
i1*f(c1)++…++in*f(cn)ms_to_col ms returns the element in ms (size
ms=1)
29
Transition Inscriptions
Even
m>0 @+2
input(m)output(n,b)let val even = (m mod 2)=0in (m+1,even)end;
Number Resultm
n
bINT BOOL
3
32
Arc Inscriptions
EvenNumber Resultm b@+2INT BOOL
1`3++1`5
1`3++1`5
2
Arc delay:Output arc has a delay of 2
33
Arc Inscriptions
EvenNumber Resultm@+2 bINT BOOL
(1`3++1`5)@+6
1`3@6++1`5@6
2
Preemtpying time stamps (on input arcs):“Even” can use tokens from “Number”
at time 4 (before their time stamp would allow)
34
Arc Inscriptions
EvenNumber Resultm if even mthen 1`trueelse 1`false
INT BOOL
1`3++1`5
1`3++1`5
2
35
Arc Inscriptions
Arc inscriptions can’t:
• contain I/O or use commands
• Update or use reference variables
• Use the random function
but CPN Tools does not check this!