Presentation is loading. Please wait.

Presentation is loading. Please wait.

H γλώσσα CPN ML. 1. Δηλώσεις 3 Colour Sets Unit colset name = unit [with new_unit]; ex: colset U = unit;>>> 1`() colset E = unit with e;>>> 1`e.

Similar presentations


Presentation on theme: "H γλώσσα CPN ML. 1. Δηλώσεις 3 Colour Sets Unit colset name = unit [with new_unit]; ex: colset U = unit;>>> 1`() colset E = unit with e;>>> 1`e."— Presentation transcript:

1 H γλώσσα CPN ML

2 1. Δηλώσεις

3 3 Colour Sets Unit colset name = unit [with new_unit]; ex: colset U = unit;>>> 1`() colset E = unit with e;>>> 1`e

4 4 Colour Sets Boolean colset name = bool [with (new_false, new_true)]; ex: colset B = bool;>>> 1`true colset B2 = bool with (no, yes);>>> 1`yes Operations not, andalso, orelse

5 5 Colour Sets Integer colset 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 6 Colour Sets Strings 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 Operations s1^s2, String.size s, substring(s, i, len), explode s, implode l (length)

7 7 Colour Sets Enumerated colset name = with id0 | id1 | … | idn; ex: colset dwarfs = Dopey | Doc | Sleepy | Bashful | Happy | Grumpy | Sneezy;

8 8 Colour Sets Index colset name = index id with int1..int2; ex: colset STUDENT = index student with 1..11; >>> 1`student(1).. 1`student(11)

9 9 Compound Colour Sets Product colset name = product name1 * name2 *... * namen; ex: colset COUPLES = product MEN * WOMEN; >>> 1`(Bob, Mary) Operations #iExtract element i of tuple _Omit element - ex. (Bob,_) - Not allowed in CPN

10 10 Compound Colour Sets Record 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 recExtract element idi of record rec (ex: #s rec) …Omit element (not allowed in CPN)

11 11 Compound Colour Sets List colset name = list name0 [with int1..int2]; ex: colset MyList = list INT with 1..3; >>> 1`[3, 8, 54] Operations Many; see: http://wiki.daimi.au.dk/cpntools-help/list_colour_sets.wiki

12 12 Compound Colour Sets Union 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 41`NUM

13 13 Compound Colour Sets Subset 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];

14 14 Compound Colour Sets Alias colset name = name0; ex: colset Naturals = POSINT;

15 15 Variables & Constants var id1[, id2, …, idn]: name; val id = exp; ex: var x: int; val maxtries = 5;

16 16 Reference Variables globref id = exp; ex: globref i = 10; Operations: !acontents of the r.v. a a:=bassign value b to r.v. a ref breference constructor inc a/dec a in-/decrement value of int r.v. a

17 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 18 Local Declarations let val pat1=exp1 val pat2=exp2 … val patn=expn in exp end; let factor=5; in mult(num, factor); end;

19 19 Control Structures if boolexp then exp1 else exp2 case exp of pat1 => exp1 pat2 => exp2 … patn => expn;

20 2. Multisets

21 21 Constructor It is the ` character. NOT ‘! Syntax: i`c ex: 3`true

22 22 Operations emptyconstant; empty multiset ==equality <><>inequality >>greater than (>>=..or equal to) <<lesser than (<<=..or equal to) ++addition --subtraction **scalar multiplication

23 23 Operations size mssize random msreturn random colour cf(c, ms)appearances of c in ms filter p msfilter ms by predicate p ext_col f mstakes i1`c1++…++in`cn and returns i1`f(c1)++…++in`f(cn) ext_ms f mstakes i1`c1++…++in`cn and returns i1*f(c1)++…++in*f(cn) ms_to_col msreturns the element in ms (size ms=1)

24 3. Inscriptions

25 25 Place Inscriptions Name Colour set [Initial Marking[@+Delay]]

26 26 Place Inscriptions Start INT 1`0 ++ 1`1 ++ 1`2 1`0++ 1`1++ 1`2 3

27 27 Place Inscriptions Start INT (1`0 ++ 1`1 ++ 1`2)@+3 1`0@3++ 1`1@3++ 1`2@3 3

28 28 Transition Inscriptions Name [Guard][Delay] [Code]

29 29 Transition Inscriptions Even m>0@+2 input(m) output(n,b) let val even = (m mod 2)=0 in (m+1,even) end; Number Result m n b INT BOOL 3

30 30 Arc Inscriptions Even Number Result mb INT BOOL 3 1`3 1 m is bound to 3

31 31 Arc Inscriptions Even Number Result mb INT BOOL 1`3++1`5 1`3++ 1`5 2 m is free (3 or 5)

32 32 Arc Inscriptions Even Number Result mb@+2 INT BOOL 1`3++1`5 1`3++ 1`5 2 Arc delay: Output arc has a delay of 2

33 33 Arc Inscriptions Even Number Result m@+2b INT 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 34 Arc Inscriptions Even Number Result m if even m then 1`true else 1`false INT BOOL 1`3++1`5 1`3++ 1`5 2

35 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!

36 36 CPN ML Manual http://wiki.daimi.au.dk/cpntools-help/ cpn_ml.wiki?cmd=get&anchor=CPN+ML or http://wiki.daimi.au.dk/cpntools-help and follow “CPN ML”


Download ppt "H γλώσσα CPN ML. 1. Δηλώσεις 3 Colour Sets Unit colset name = unit [with new_unit]; ex: colset U = unit;>>> 1`() colset E = unit with e;>>> 1`e."

Similar presentations


Ads by Google