H γλώσσα CPN ML. 1....

Click here to load reader

  • date post

    14-Dec-2015
  • Category

    Documents

  • view

    216
  • download

    0

Embed Size (px)

Transcript of H γλώσσα CPN ML. 1....

  • Slide 1

H CPN ML Slide 2 1. Slide 3 3 Colour Sets Unit colset name = unit [with new_unit]; ex: colset U = unit;>>> 1`() colset E = unit with e;>>> 1`e Slide 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 Slide 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) Slide 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 >>> OKAbC, abcd NOT OK Operations s1^s2, String.size s, substring(s, i, len), explode s, implode l (length) Slide 7 7 Colour Sets Enumerated colset name = with id0 | id1 | | idn; ex: colset dwarfs = Dopey | Doc | Sleepy | Bashful | Happy | Grumpy | Sneezy; Slide 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) Slide 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 Slide 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) >> 1`[3, 8, 54] Operations Many; see"> 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 Slide 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 Slide 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]; Slide 14 14 Compound Colour Sets Alias colset name = name0; ex: colset Naturals = POSINT; Slide 15 15 Variables & Constants var id1[, id2, , idn]: name; val id = exp; ex: var x: int; val maxtries = 5; Slide 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 Slide 17 17 Functions fun id pat1 = exp1 id pat2 = exp2... id patn = expn; ex: fun isPos(x) = (x>0); fun diff(x,y) = (xy); fun Divide(x,y) = (x div y) Divide(_,0) = error; Slide 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; Slide 19 19 Control Structures if boolexp then exp1 else exp2 case exp of pat1 => exp1 pat2 => exp2 patn => expn; Slide 20 2. Multisets Slide 21 21 Constructor It is the ` character. NOT ! Syntax: i`c ex: 3`true Slide 22 22 Operations emptyconstant; empty multiset ==equality inequality >>greater than (>>=..or equal to) 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 Slide 30 30 Arc Inscriptions Even Number Result mb INT BOOL 3 1`3 1 m is bound to 3 Slide 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) Slide 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 Slide 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) Slide 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 Slide 35 35 Arc Inscriptions Arc inscriptions cant: contain I/O or use commands Update or use reference variables Use the random function but CPN Tools does not check this! Slide 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