1 / 31

Programming Language Semantics Advanced Issues in Operational Semantics

Programming Language Semantics Advanced Issues in Operational Semantics. Chapter 14 Nondetermism and Parallelism. Hashlama Friday May 30 11:00-14:00. Schreiber 309. Motivation. Specifying the semantics of real programming languages is more difficult than IMP…. Language Features.

tboucher
Download Presentation

Programming Language Semantics Advanced Issues in Operational Semantics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming Language SemanticsAdvanced Issues in Operational Semantics Chapter 14 Nondetermism and Parallelism

  2. Hashlama Friday May 3011:00-14:00 Schreiber 309

  3. Motivation • Specifying the semantics of real programming languages is more difficult than IMP… Language Features • Higher order types • Dynamic memory allocation • Pointers • Procedures and recursion • Parameter passing • Concurrency

  4. Plan • Handling memory allocation (Ex 2) • A simple parallel construct • Guarded commands • Concurrency with communication

  5. Abstract Syntax for IMP++ • L • X | L.car | L.cdr • Aexp • a ::= n | L | cons(a, a) | nil | a0 + a1 | a0 – a1 | a0 a1 • Bexp • b ::= true | false | a0 = a1 | a0 a1 | b | b0 b1 | b0  b1 • Com • c ::= skip | L := a | c0 ; c1 | if b then c0else c1| while b do c

  6. Extending the semantic domain • States cannot be mapping from variables to values • Need a way to represent “sharing” • Two level stores •  = (env, store) • env : Loc  Val • store=(Cells, car, cdr) • car: Cells  Val, cdr: Cells Val • Val = Cells {nil}  N

  7. Extending the semantic relation • expressions • <a, > 1 <a’, > • What is the intermediate result of computing L-value? • (((X).cdr).car) • Allow location expressions a  cells • cons expressions modify the store

  8. Expression rules (1) <n,  > 1 <n,  > <nil,  > 1 <nil,  > <X, (e , s)>1 <e(X), (e, s)> <L, (e, s) > 1 <L’, (e, s)> <L.sel, (e, s) > 1 <L’.sel, (e, s)> , sel {car, cdr} s=(cells, car, cdr) and c  cells, sel {car, cdr} and sel(c)=c’ <c.sel, (e, s) > 1 <c’, (e, s)>

  9. Expression rules (2) <a0,  > 1 <a0’, ’> <cons(a0, a1),  > 1 <cons(a0’, a1), ’> <a1, (e, s) > 1 <a1’, (e, s’)> s=(cells, car, cdr), c0Val <cons(c0+a1), (e, s)> 1 <cons(c0, a1’), (e, s’)> s=(cells, car, cdr), ccells, c0, c1 Val <cons(c0, c1), (e, s) > 1 <c, (e, cells{c}, car[c0/c], cdr[c1/c])>

  10. Boolean expressions(1) <t,  > 1 <t,  >, t {true, false} <a0, > 1 <a0’, ’> <a0=a1,  > 1 <a0’, ’> <a1, (e, s)> 1 <a1’, (e, s’)>, s=(cells, car, cdr), c0Val <c0=a1, (e, s) > 1 <c0=a1’, (e, s’)> s=(cells, car, cdr),c0, c1 Val, c0=c1<c0=c1, (e, s) > 1 <true, (e, s)> s=(cells, car, cdr),c0, c1 Val, c0≠c1<c0=c1, (e, s) > 1 <false, (e, s)>

  11. Commands(1) <skip, > 1 <a, (e, s) > 1 <a’, (e, s’)> X  Loc <X:=a, (e, s)> 1 <X:=a’, (e, s’)> <X := c, (e, s) > 1 <(e[c/X], s)>, X  Loc, cVal <a0, (e, s) > 1 <a0’,(e, s)> <a0.car := a1, (e, s) >1 <a0’.car:=a1, (e, s)> <a1, (e, s)> 1 <a1’, (e, s’)> s=(cells, car, cdr), c  cells <c.car := a1, (e, s) >1 <(c.car :=a1’, (e, s’)> s=(cells, car, cdr), c0  cells, c1  Val <c0.car := c1, (e, s) >1 <(e, (cells, car[c1/c0], cdr)

  12. Commands (2) <c0, > 1<c’0, ’> <c’0; c1, > 1<c’0;c1, ’> <c0, > 1’, <c1, ’> 1’’ <c0; c1, > 1’’ <b, >1<true, ’>, <c0, ’> 1’’ <if b then c0 else c1, >1’’ <b, >1<false, ’>, <c1, ’> 1’’ <if b then c0 else c1, >1’’ <while b do c1, >1 <if b then (c1; while b do c) else skip, >

  13. A Simple Parallel Construct • c0 || c1 • Execute co and c1 in parallel • (X := 1 || (X:=2 ; X := X + 1)) • Natural Operational Semantics • Small step rules • <c, > 1 <c’, >

  14. Parallelism Introduces (Demonic) Nondeterminism (X := 0 || X := 1); if X = 0 then c0 else c1

  15. Guarded Commands • Com • c ::= skip | abort | X := a | c0 ; c1 | if gc fi | do gc od • GC • gc ::= b  c | gc0  gc1 if X Y  MAX := X  Y X  MAX := Y fi do X >Y  X := X - Y  Y >X  Y := Y - X od

  16. Rules for commands <skip, > 1 <a,  >  n <X:=a,  > 1 [n/X] <c0,  > 1’ <c0,  > 1 <c’0, ’> <c0;c1,  >1 <c1, ’> <c0;c1,  >1 <c’0; c1, ’> <gc, > 1 <c, ’> <if gc fi,  >1 <c, ’> <gc,  > 1fail<gc,  > 1 <c, ’> <do gc od,  >1 <do gc od,  >1 <c’; do gc od, ’>

  17. Rules for guarded commands <b,  > true <bc,  > 1 <c, > <gc0,  > 1 <c, ’> <gc1,  > 1 <c, ’> <gc0gc1,  >1 <c, ’> <gc0gc1,  >1 <c, ’> <b,  > 1 false<gc0,  > 1 fail <gc1,  > 1 fail <bc,  >1fail <gc0 gc1,  >1 fail

  18. Example do X >Y  X := X - Y  Y >X  Y := Y - X od

  19. Communicating processes • Languages for modeling distributed systems • CSP, Occam, Ada? • Hoare, Milner • Support • Parallelism • Non-determinism • Synchronization via communication •  ? X   ! a

  20. Communication Processes • Channel names , ,   Chan • Input expression ? X where X  Loc • Output expressions ! A where a  Aexp • Commands • c::= skip | abort | X := a |  ? X |  ! A | c0 ; c1 |if gc fi | do gc od | c0 || c1 | c   • Guarded commands • gc ::= b c | b   ? X  c | b   ! a  c|gc0 gc1

  21. do (true   ? X   ! X) od || do (true   ? Y   ! Y) od ||  Examples do (true   ? X   ! X) od

  22. Examples if (true   ? X  c0) (true   ? Y  c1) fi if (true   ? X; c0) (true   ? Y ;c1) fi

  23. Formal semantics • Need a way to model communication events • <?X; c , > • Label transitions • {? n |  Chan & n  N} {! n |  Chan & n  N}

  24. Conventions in formal semantics • Empty command * • *; c  c; *  c || *  * || c  c • * ; *  (*  )  * •   1 •  •  =? n •  =! n •  =

  25. Rules for commands <skip, >  <a,  >  n <X:=a,  >  [n/X] < ? X ; c, >  ?n <c, [n/X]> <a, >  n < ! e ; c, >  !n <c, > <c0,  >  <c’0, ’> <c0;c1,  > <c’0; c1, ’>

  26. Rules for commands(2) <gc,  > fail<gc,  >  <c, ’> <do gc od,  > <do gc od,  ><c’; do gc od, ’> <c0,  > <c’0, ’><c1 , >  <c’1, ’> <c0 || c1,  ><c’0 || c1, ’> < c0 || c1,  ><c0 || c’1, ’> <c0,  > ?n<c’0, ’><c1 , > !n <c’1, > <c0 || c1,  ><c’0 || c’1, ’> <c0,  > ?n<c’0, ’><c1 , > !n <c’1, > <c0 || c1,  ><c’0 || c’1, ’>

  27. Rules for commands(3) provided that ?n and !n <c,  >  <c’, ’> <c ,  > <c , ’>

  28. Rules for guarded commands(1) <b,  > true <b,  >  false <bc,  >  <c, > <bc,  >fail <b,  >  false <b,  >  false <b ?X c,  >  fail <b !e c, >  fail <gc0,  >  fail <gc1,  >  fail <gc0 gc1,  >fail

  29. Rules for guarded commands(2) <b,  > true < b ?Xc, ?n <c, [n/X]> <b,  >  true, <a, >n <b !a  c, >  !n <c, > <gc0,  >  <c, ’> <gc1,  >  <c, ’> <gc0gc1,  ><c, ’> <gc0gc1,  > <c, ’>

  30. Uncovered • Calculus for Communicating Systems (CCS) • A specification language • The modal -calculus • Local model checking

  31. Summary • Writing a small step semantics for a real programming language is non-trivial • Small step semantics can model • Nondeterminism • Concurrency • Failures • Guarded command is a powerful language construct

More Related